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/.
12 from collections
import deque
13 from org
.libreoffice
.unotest
import UnoInProcess
15 class Fdo84315(unittest
.TestCase
):
19 cls
._uno
= UnoInProcess()
21 workdir
= os
.environ
[ "WORKDIR_FOR_BUILD" ]
22 cls
._xDoc
= cls
._uno
.openDocFromAbsolutePath(workdir
+ "/CppunitTest/fdo84315.odb")
25 def tearDownClass(cls
):
28 def __test_Query(self
, column_name
, expected_type
, xResultset
):
29 self
.assertTrue(xResultset
)
30 xMeta
= xResultset
.MetaData
31 self
.assertEqual(xMeta
.ColumnCount
, 1)
32 self
.assertEqual(xResultset
.findColumn(column_name
), 1)
33 self
.assertEqual(xMeta
.getColumnName(1), column_name
)
34 self
.assertEqual(xMeta
.getColumnType(1), expected_type
)
37 def __test_ResultSetInteger(self
, xResultset
, expected_values
):
38 while xResultset
.next():
39 self
.assertEqual(xResultset
.getInt(1), expected_values
.popleft())
40 self
.assertEqual(len(expected_values
), 0)
42 def __test_ResultSetString(self
, xResultset
, expected_values
):
43 while xResultset
.next():
44 self
.assertEqual(xResultset
.getString(1), expected_values
.popleft())
45 self
.assertEqual(len(expected_values
), 0)
47 def test_fdo84315(self
):
48 xDoc
= self
.__class
__._xDoc
49 xDataSource
= xDoc
.DataSource
50 xCon
= xDataSource
.getConnection('','')
51 xStatement
= xCon
.createStatement()
57 xResultset
= xStatement
.executeQuery('SELECT "count" FROM "test_table"')
58 expected_values
= deque([42, 4711])
59 self
.__test
_Query
('count', NUMERIC
, xResultset
)
60 self
.__test
_ResultSetInteger
(xResultset
, expected_values
)
62 xResultset
= xStatement
.executeQuery('SELECT "name" FROM "test_table"')
63 expected_values
= deque(['foo', 'bar'])
64 self
.__test
_Query
('name', VAR_CHAR
, xResultset
)
65 self
.__test
_ResultSetString
(xResultset
, expected_values
)
67 xResultset
= xStatement
.executeQuery('SELECT "id" FROM "test_table"')
68 expected_values
= deque([0, 1])
69 self
.__test
_Query
('id', INTEGER
, xResultset
)
70 self
.__test
_ResultSetInteger
(xResultset
, expected_values
)
74 if __name__
== '__main__':