[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Sep 25 15:18:14 UTC 2018
sw/PythonTest_sw_python.mk | 1
sw/qa/python/check_xnamedgraph.py | 168 +++++++++++++++++++++++++++++
sw/qa/python/testdocuments/XNamedGraph.ott |binary
3 files changed, 169 insertions(+)
New commits:
commit 6d3a04546542156d50151cf9b4507661bde39df0
Author: Serge Krot <Serge.Krot at cib.de>
AuthorDate: Thu Sep 20 14:39:20 2018 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Sep 25 17:17:50 2018 +0200
sw: new unit test for XNamedGraph
Change-Id: I222179c92cda3e0b2503544b7f120f35957265ac
Reviewed-on: https://gerrit.libreoffice.org/60815
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 2e2ef509add2..13bf75122742 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_styles \
check_xtexttable \
check_table \
+ check_xnamedgraph \
get_expression \
set_expression \
text_portion_enumeration_test \
diff --git a/sw/qa/python/check_xnamedgraph.py b/sw/qa/python/check_xnamedgraph.py
new file mode 100644
index 000000000000..75d030fd3e3b
--- /dev/null
+++ b/sw/qa/python/check_xnamedgraph.py
@@ -0,0 +1,168 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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 org.libreoffice.unotest import UnoInProcess
+
+
+class XNamedGraph(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls._uno = UnoInProcess()
+ cls._uno.setUp()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._uno.tearDown()
+
+ def test_getStatements(self):
+ xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+ xRepo = xDMA.getRDFRepository()
+ xGraphs = xRepo.getGraphNames()
+
+ all = self.getStatementsCount(xGraphs, xDMA, None, None)
+ self.assertTrue(all > 0)
+
+ # check that we have some node from the second RDF graph
+ # (but not any from the list of LO standard nodes)
+ DATE_URI_STR = "http://www.wollmux.org/WollMuxMetadata#WollMuxVersion"
+ xUri = self.nameToUri(DATE_URI_STR)
+
+ onlyWollMux = self.getStatementsCount(xGraphs, xDMA, xUri, None)
+ self.assertTrue(onlyWollMux > 0)
+ self.assertTrue(onlyWollMux < all)
+
+ xDMA.close(True)
+
+ def test_Statements_AddRemove(self):
+ # take any first graph
+ xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+ xGraph = self.getAnyGraph(xDMA)
+
+ DATE_URI_STR = "http://www.example.com/Metadata#Version"
+ OBJECT_STR = "foo"
+
+ # not exist => add => remove
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+ self.addStatement(xDMA, xGraph, DATE_URI_STR, OBJECT_STR)
+ self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+ self.removeStatement(xDMA, xGraph, DATE_URI_STR, None)
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+
+ xDMA.close(True)
+
+ def test_Statements_RemoveByObject(self):
+ # take any first graph
+ xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+ xGraph = self.getAnyGraph(xDMA)
+
+ DATE_URI_STR = "http://www.example.com/Metadata#Version"
+ OBJECT_STR = "foo"
+
+ # remove by object
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+ self.addStatement(xDMA, xGraph, DATE_URI_STR, OBJECT_STR)
+ self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+ self.removeStatement(xDMA, xGraph, None, OBJECT_STR)
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+
+ xDMA.close(True)
+
+ def test_Statements_RemoveByObject(self):
+ # take any first graph
+ xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+ xGraph = self.getAnyGraph(xDMA)
+
+ DATE_URI_STR_1 = "http://www.example.com/Metadata#Version"
+ DATE_URI_STR_2 = "http://www.example.com/Metadata#Second"
+ OBJECT_STR = "foo"
+
+ # remove several with one call
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_1))
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_2))
+ self.addStatement(xDMA, xGraph, DATE_URI_STR_1, OBJECT_STR)
+ self.addStatement(xDMA, xGraph, DATE_URI_STR_2, OBJECT_STR)
+ self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR_1))
+ self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR_2))
+ self.removeStatement(xDMA, xGraph, None, OBJECT_STR)
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_1))
+ self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_2))
+
+ xDMA.close(True)
+
+ def getAnyGraph(self, xDMA):
+ xRepo = xDMA.getRDFRepository()
+ xGraphs = xRepo.getGraphNames()
+ self.assertTrue(len(xGraphs) > 0)
+ xGraph = xRepo.getGraph(xGraphs[0])
+ self.assertIsNotNone(xGraph)
+ return xGraph
+
+ def getStatementsCount(self, xGraphs, xDMA, xPredicate, xObject):
+ count = 0
+ xRepo = xDMA.getRDFRepository()
+
+ for xGraphUri in xGraphs:
+ xGraph = xRepo.getGraph(xGraphUri)
+
+ xStatements = xGraph.getStatements(xDMA, xPredicate, xObject)
+ self.assertIsNotNone(xStatements)
+
+ if xPredicate is None:
+ self.assertTrue(xStatements.hasMoreElements())
+
+ for xStatement in xStatements:
+ count += 1
+
+ return count
+
+ def hasStatement(self, xDMA, xGraph, xPredicateName):
+ xPredicate = self.nameToUri(xPredicateName)
+ self.assertIsNotNone(xPredicate)
+
+ xStatements = xGraph.getStatements(xDMA, xPredicate, None)
+ self.assertIsNotNone(xStatements)
+ return xStatements.hasMoreElements()
+
+ def nameToUri(self, xPredicateName):
+ xServiceManager = self.__class__._uno.xContext.ServiceManager
+ xUri = xServiceManager.createInstance("com.sun.star.rdf.URI")
+ xUri.initialize((xPredicateName,))
+ return xUri
+
+ def stringToLiteral(self, xString):
+ xServiceManager = self.__class__._uno.xContext.ServiceManager
+ xLiteral = xServiceManager.createInstance("com.sun.star.rdf.Literal")
+ xLiteral.initialize((xString,))
+ return xLiteral
+
+ def addStatement(self, xDMA, xGraph, xPredicateName, xObjectStr):
+ xPredicate = self.nameToUri(xPredicateName)
+ self.assertIsNotNone(xPredicate)
+
+ xObject = self.stringToLiteral(xObjectStr)
+ self.assertIsNotNone(xObject)
+
+ xGraph.addStatement(xDMA, xPredicate, xObject)
+
+ def removeStatement(self, xDMA, xGraph, xPredicateName, xObjectStr):
+ xPredicate = None
+ if xPredicateName is not None:
+ xPredicate = self.nameToUri(xPredicateName)
+
+ xObject = None
+ if xObjectStr is not None:
+ xObject = self.stringToLiteral(xObjectStr)
+
+ xGraph.removeStatements(xDMA, xPredicate, xObject)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sw/qa/python/testdocuments/XNamedGraph.ott b/sw/qa/python/testdocuments/XNamedGraph.ott
new file mode 100644
index 000000000000..9c097024b7ed
Binary files /dev/null and b/sw/qa/python/testdocuments/XNamedGraph.ott differ
More information about the Libreoffice-commits
mailing list