summaryrefslogtreecommitdiffstats
path: root/dbaccess/qa/python/fdo84315.py
blob: f58b16f513096a972500bc78fac84d8c707776e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env python
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import os
import unittest
from collections import deque
import unohelper
from org.libreoffice.unotest import UnoInProcess

class Fdo84315(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls._uno = UnoInProcess()
        cls._uno.setUp()
        workdir = os.environ[ "WORKDIR_FOR_BUILD" ]
        cls._xDoc = cls._uno.openDocFromAbsolutePath(workdir + "/CppunitTest/fdo84315.odb")

    @classmethod
    def tearDownClass(cls):
        cls._uno.tearDown()

    def __test_Query(self, column_name, expected_type, xResultset):
        self.assertTrue(xResultset)
        xMeta = xResultset.MetaData
        self.assertEqual(xMeta.ColumnCount, 1)
        self.assertEqual(xResultset.findColumn(column_name), 1)
        self.assertEqual(xMeta.getColumnName(1), column_name)
        self.assertEqual(xMeta.getColumnType(1), expected_type)
        return xMeta

    def __test_ResultSetInteger(self, xResultset, expected_values):
        while xResultset.next():
            self.assertEqual(xResultset.getInt(1), expected_values.popleft())
        self.assertEqual(len(expected_values), 0)

    def __test_ResultSetString(self, xResultset, expected_values):
        while xResultset.next():
            self.assertEqual(xResultset.getString(1), expected_values.popleft())
        self.assertEqual(len(expected_values), 0)

    def test_fdo84315(self):
        xDoc = self.__class__._xDoc
        xDataSource = xDoc.DataSource
        xCon = xDataSource.getConnection('','')
        xStatement = xCon.createStatement()

        NUMERIC = 2
        VAR_CHAR = 12
        INTEGER = 4

        xResultset = xStatement.executeQuery('SELECT "count" FROM "test_table"')
        expected_values = deque([42, 4711])
        xMeta = self.__test_Query('count', NUMERIC, xResultset)
        self.__test_ResultSetInteger(xResultset, expected_values)

        xResultset = xStatement.executeQuery('SELECT "name" FROM "test_table"')
        expected_values = deque(['foo', 'bar'])
        xMeta = self.__test_Query('name', VAR_CHAR, xResultset)
        self.__test_ResultSetString(xResultset, expected_values)

        xResultset = xStatement.executeQuery('SELECT "id" FROM "test_table"')
        expected_values = deque([0, 1])
        xMeta = self.__test_Query('id', INTEGER, xResultset)
        self.__test_ResultSetInteger(xResultset, expected_values)

        xCon.dispose()

if __name__ == '__main__':
    unittest.main()