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
14 from org
.libreoffice
.unotest
import UnoInProcess
16 class Fdo84315(unittest
.TestCase
):
20 cls
._uno
= UnoInProcess()
22 workdir
= os
.environ
[ "WORKDIR_FOR_BUILD" ]
23 cls
._xDoc
= cls
._uno
.openDocFromAbsolutePath(workdir
+ "/CppunitTest/fdo84315.odb")
26 def tearDownClass(cls
):
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
)
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()
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
)
75 if __name__
== '__main__':