LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / dbaccess / qa / python / fdo84315.py
blobf58b16f513096a972500bc78fac84d8c707776e4
1 #! /usr/bin/env python
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import os
11 import unittest
12 from collections import deque
13 import unohelper
14 from org.libreoffice.unotest import UnoInProcess
16 class Fdo84315(unittest.TestCase):
18 @classmethod
19 def setUpClass(cls):
20 cls._uno = UnoInProcess()
21 cls._uno.setUp()
22 workdir = os.environ[ "WORKDIR_FOR_BUILD" ]
23 cls._xDoc = cls._uno.openDocFromAbsolutePath(workdir + "/CppunitTest/fdo84315.odb")
25 @classmethod
26 def tearDownClass(cls):
27 cls._uno.tearDown()
29 def __test_Query(self, column_name, expected_type, xResultset):
30 self.assertTrue(xResultset)
31 xMeta = xResultset.MetaData
32 self.assertEqual(xMeta.ColumnCount, 1)
33 self.assertEqual(xResultset.findColumn(column_name), 1)
34 self.assertEqual(xMeta.getColumnName(1), column_name)
35 self.assertEqual(xMeta.getColumnType(1), expected_type)
36 return xMeta
38 def __test_ResultSetInteger(self, xResultset, expected_values):
39 while xResultset.next():
40 self.assertEqual(xResultset.getInt(1), expected_values.popleft())
41 self.assertEqual(len(expected_values), 0)
43 def __test_ResultSetString(self, xResultset, expected_values):
44 while xResultset.next():
45 self.assertEqual(xResultset.getString(1), expected_values.popleft())
46 self.assertEqual(len(expected_values), 0)
48 def test_fdo84315(self):
49 xDoc = self.__class__._xDoc
50 xDataSource = xDoc.DataSource
51 xCon = xDataSource.getConnection('','')
52 xStatement = xCon.createStatement()
54 NUMERIC = 2
55 VAR_CHAR = 12
56 INTEGER = 4
58 xResultset = xStatement.executeQuery('SELECT "count" FROM "test_table"')
59 expected_values = deque([42, 4711])
60 xMeta = self.__test_Query('count', NUMERIC, xResultset)
61 self.__test_ResultSetInteger(xResultset, expected_values)
63 xResultset = xStatement.executeQuery('SELECT "name" FROM "test_table"')
64 expected_values = deque(['foo', 'bar'])
65 xMeta = self.__test_Query('name', VAR_CHAR, xResultset)
66 self.__test_ResultSetString(xResultset, expected_values)
68 xResultset = xStatement.executeQuery('SELECT "id" FROM "test_table"')
69 expected_values = deque([0, 1])
70 xMeta = self.__test_Query('id', INTEGER, xResultset)
71 self.__test_ResultSetInteger(xResultset, expected_values)
73 xCon.dispose()
75 if __name__ == '__main__':
76 unittest.main()