From 6dbb6275ebd1a4299099c3b6bc82ec4ee0e1fb86 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Tue, 30 Sep 2014 15:25:42 +0200 Subject: fdo84315: add integration test for basic LibreOffice Base functionality Thanks to Stephan for helping with the test environment setup: sbergman@redhat.com: Do the same "set UserInstallation to user profile dir in test/user-template" in UnoInProcess's setUp as is done in test::BootstrapFixtureBase::setUp (unotest/source/cpp/bootstrapfixturebase.cxx) for CppunitTests. That way, these tests all use the workdir/unittest/ UserInstallation concurrently, but they at least do not run into the gotcha in SubstitutePathVariables::SetPredefinedPathVariables (framework/source/services/substitutepathvars.cxx) to only set the PREDEFVAR_USERPATH if PATH_EXISTS. Change-Id: Iad058098a4c69cb567e2d3222af3c7d4ba993271 --- dbaccess/Module_dbaccess.mk | 6 ++ dbaccess/PythonTest_dbaccess_python.mk | 20 +++++++ dbaccess/qa/extras/testdocuments/fdo84315.odb | Bin 0 -> 3592 bytes dbaccess/qa/python/fdo84315.py | 71 +++++++++++++++++++++++ unotest/source/python/org/libreoffice/unotest.py | 25 ++++++++ 5 files changed, 122 insertions(+) create mode 100644 dbaccess/PythonTest_dbaccess_python.mk create mode 100644 dbaccess/qa/extras/testdocuments/fdo84315.odb create mode 100644 dbaccess/qa/python/fdo84315.py diff --git a/dbaccess/Module_dbaccess.mk b/dbaccess/Module_dbaccess.mk index bbe300904e2c..2dccdf8cde59 100644 --- a/dbaccess/Module_dbaccess.mk +++ b/dbaccess/Module_dbaccess.mk @@ -68,6 +68,12 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,dbaccess,\ JunitTest_dbaccess_unoapi \ )) +ifneq ($(DISABLE_PYTHON),TRUE) +$(eval $(call gb_Module_add_subsequentcheck_targets,dbaccess,\ + PythonTest_dbaccess_python \ +)) +endif + endif # vim: set noet sw=4 ts=4: diff --git a/dbaccess/PythonTest_dbaccess_python.mk b/dbaccess/PythonTest_dbaccess_python.mk new file mode 100644 index 000000000000..7954cbc3e911 --- /dev/null +++ b/dbaccess/PythonTest_dbaccess_python.mk @@ -0,0 +1,20 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_PythonTest_PythonTest,dbaccess_python)) + +$(eval $(call gb_PythonTest_set_defs,dbaccess_python,\ + TDOC="$(SRCDIR)/dbaccess/qa/extras/testdocuments" \ +)) + +$(eval $(call gb_PythonTest_add_modules,dbaccess_python,$(SRCDIR)/dbaccess/qa/python,\ + fdo84315 \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/dbaccess/qa/extras/testdocuments/fdo84315.odb b/dbaccess/qa/extras/testdocuments/fdo84315.odb new file mode 100644 index 000000000000..0513ff5874a7 Binary files /dev/null and b/dbaccess/qa/extras/testdocuments/fdo84315.odb differ diff --git a/dbaccess/qa/python/fdo84315.py b/dbaccess/qa/python/fdo84315.py new file mode 100644 index 000000000000..0670f66ab3a6 --- /dev/null +++ b/dbaccess/qa/python/fdo84315.py @@ -0,0 +1,71 @@ +#! /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 unittest +from collections import deque +from org.libreoffice.unotest import UnoInProcess + +class Fdo84315(unittest.TestCase): + _uno = None + _xDoc = None + + @classmethod + def setUpClass(cls): + cls._uno = UnoInProcess() + cls._uno.setUp() + cls._xDoc = cls._uno.openBaseDoc('fdo84315.odb') + + @classmethod + def tearDownClass(cls): + cls._uno.tearDown() + + def test_fdo84315(self): + xDoc = self.__class__._xDoc + xDataSource = xDoc.DataSource + xCon = xDataSource.getConnection('','') + xStatement = xCon.createStatement() + + xResultset = xStatement.executeQuery('SELECT "count" FROM "test_table"') + expected_values = deque([42, 4711]) + self.assertTrue(xResultset) + xMeta = xResultset.MetaData + self.assertEqual(xMeta.ColumnCount, 1) + self.assertEqual(xResultset.findColumn("count"), 1) + self.assertEqual(xMeta.getColumnName(1), "count"); + self.assertEqual(xMeta.getColumnType(1), 2); # numeric + while xResultset.next(): + self.assertEqual(xResultset.getInt(1), expected_values.popleft()) + self.assertEqual(len(expected_values), 0) + + xResultset = xStatement.executeQuery('SELECT "name" FROM "test_table"') + expected_values = deque(['foo', 'bar']) + self.assertTrue(xResultset) + xMeta = xResultset.MetaData + self.assertEqual(xMeta.ColumnCount, 1) + self.assertEqual(xResultset.findColumn("name"), 1) + self.assertEqual(xMeta.getColumnName(1), "name"); + self.assertEqual(xMeta.getColumnType(1), 12); # varchar + while xResultset.next(): + self.assertEqual(xResultset.getString(1), expected_values.popleft()) + self.assertEqual(len(expected_values), 0) + + xResultset = xStatement.executeQuery('SELECT "id" FROM "test_table"') + expected_values = deque([0, 1]) + self.assertTrue(xResultset) + xMeta = xResultset.MetaData + self.assertEqual(xMeta.ColumnCount, 1) + self.assertEqual(xResultset.findColumn("id"), 1) + self.assertEqual(xMeta.getColumnName(1), "id"); + self.assertEqual(xMeta.getColumnType(1), 4); # integer + while xResultset.next(): + self.assertEqual(xResultset.getInt(1), expected_values.popleft()) + self.assertEqual(len(expected_values), 0) + +if __name__ == '__main__': + unittest.main() diff --git a/unotest/source/python/org/libreoffice/unotest.py b/unotest/source/python/org/libreoffice/unotest.py index 6a7f8143cdd2..1991b79d29da 100644 --- a/unotest/source/python/org/libreoffice/unotest.py +++ b/unotest/source/python/org/libreoffice/unotest.py @@ -174,6 +174,15 @@ class UnoInProcess: def getDoc(self): return self.xDoc def setUp(self): + # set UserInstallation to user profile dir in test/user-template: + path = os.getenv("WORKDIR") + if os.name == "nt": + # do not quote drive letter - it must be "X:" + url = "file:///" + path + else: + url = "file://" + quote(path) + os.putenv("UserInstallation", url + "/unittest") + self.xContext = pyuno.getComponentContext() pyuno.private_initTestEnvironment() def openEmptyWriterDoc(self): @@ -202,6 +211,22 @@ class UnoInProcess: assert(self.xDoc) return self.xDoc + def openBaseDoc(self, file): + assert(self.xContext) + smgr = self.getContext().ServiceManager + desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext()) + props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", False)] + loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props]) + path = os.getenv("TDOC") + if os.name == "nt": + #do not quote drive letter - it must be "X:" + url = "file:///" + path + "/" + quote(file) + else: + url = "file://" + quote(path) + "/" + quote(file) + self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps) + assert(self.xDoc) + return self.xDoc + def checkProperties(self, obj, dict, test): for k,v in dict.items(): obj.setPropertyValue(k, v) -- cgit