Kaydet (Commit) 6dbb6275 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

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
üst 45b87655
......@@ -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:
# -*- 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:
#! /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()
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment