unoxml: move checkRDF from Java to CppUnittest
Change-Id: If4e3120643c40f52b99bb71782c4c34a34871031 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173567 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
parent
b8d5b98b06
commit
b42b218bd7
4 changed files with 290 additions and 536 deletions
|
@ -1,38 +0,0 @@
|
|||
# -*- 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/.
|
||||
#
|
||||
# This file incorporates work covered by the following license notice:
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed
|
||||
# with this work for additional information regarding copyright
|
||||
# ownership. The ASF licenses this file to you under the Apache
|
||||
# License, Version 2.0 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
#
|
||||
|
||||
$(eval $(call gb_JunitTest_JunitTest,unordf_complex))
|
||||
|
||||
$(eval $(call gb_JunitTest_set_defs,unordf_complex,\
|
||||
$$(DEFS) \
|
||||
-Dorg.openoffice.test.arg.tdoc=$(SRCDIR)/unoxml/qa/complex/unoxml/testdocuments \
|
||||
))
|
||||
|
||||
$(eval $(call gb_JunitTest_use_unoapi_jars,unordf_complex))
|
||||
|
||||
$(eval $(call gb_JunitTest_add_sourcefiles,unordf_complex,\
|
||||
unoxml/qa/complex/unoxml/RDFRepositoryTest \
|
||||
unoxml/qa/complex/unoxml/TestDocument \
|
||||
))
|
||||
|
||||
$(eval $(call gb_JunitTest_add_classes,unordf_complex,\
|
||||
complex.unoxml.RDFRepositoryTest \
|
||||
))
|
||||
|
||||
# vim: set noet sw=4 ts=4:
|
|
@ -36,7 +36,6 @@ $(eval $(call gb_Module_add_slowcheck_targets,unoxml,\
|
|||
|
||||
$(eval $(call gb_Module_add_subsequentcheck_targets,unoxml,\
|
||||
JunitTest_unoxml_complex \
|
||||
JunitTest_unordf_complex \
|
||||
))
|
||||
|
||||
# vim: set noet sw=4 ts=4:
|
||||
|
|
|
@ -1,497 +0,0 @@
|
|||
/*
|
||||
* 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/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
package complex.unoxml;
|
||||
|
||||
import helper.StreamSimulator;
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.beans.Pair;
|
||||
import com.sun.star.beans.StringPair;
|
||||
import com.sun.star.container.XEnumeration;
|
||||
import com.sun.star.container.ElementExistException;
|
||||
import com.sun.star.container.NoSuchElementException;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.text.XTextRange;
|
||||
import com.sun.star.text.XText;
|
||||
import com.sun.star.rdf.*;
|
||||
import lib.TestParameters;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.openoffice.test.OfficeConnection;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test case for service com.sun.star.rdf.Repository
|
||||
* Currently, this service is implemented in
|
||||
* unoxml/source/rdf/librdf_repository.cxx
|
||||
*
|
||||
*/
|
||||
public class RDFRepositoryTest
|
||||
{
|
||||
XComponentContext xContext;
|
||||
String tempDir;
|
||||
|
||||
XDocumentRepository xRep;
|
||||
XURI foo;
|
||||
XURI bar;
|
||||
XURI baz;
|
||||
XURI uint;
|
||||
XURI rdfslabel;
|
||||
XURI base;
|
||||
XBlankNode blank;
|
||||
XLiteral lit;
|
||||
XLiteral litlang;
|
||||
XLiteral littype;
|
||||
String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
|
||||
|
||||
/**
|
||||
* The test parameters
|
||||
*/
|
||||
private TestParameters param = null;
|
||||
|
||||
@Before public void before()
|
||||
{
|
||||
try {
|
||||
XMultiServiceFactory xMSF = getMSF();
|
||||
param = new TestParameters();
|
||||
param.put("ServiceFactory", xMSF);
|
||||
|
||||
assertNotNull("could not create MultiServiceFactory.", xMSF);
|
||||
XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
|
||||
Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext");
|
||||
xContext = UnoRuntime.queryInterface(XComponentContext.class, defaultCtx);
|
||||
assertNotNull("could not get component context.", xContext);
|
||||
|
||||
tempDir = util.utils.getOfficeTemp/*Dir*/(xMSF);
|
||||
System.out.println("tempdir: " + tempDir);
|
||||
|
||||
foo = URI.create(xContext, "uri:foo");
|
||||
assertNotNull("foo", foo);
|
||||
bar = URI.create(xContext, "uri:bar");
|
||||
assertNotNull("bar", bar);
|
||||
baz = URI.create(xContext, "uri:baz");
|
||||
assertNotNull("baz", baz);
|
||||
uint = URI.create(xContext, "uri:int");
|
||||
assertNotNull("uint", uint);
|
||||
blank = BlankNode.create(xContext, "_:uno");
|
||||
assertNotNull("blank", blank);
|
||||
lit = Literal.create(xContext, "I am the literal");
|
||||
assertNotNull("lit", lit);
|
||||
litlang = Literal.createWithLanguage(xContext,
|
||||
"I am the literal", "en");
|
||||
assertNotNull("litlang", litlang);
|
||||
littype = Literal.createWithType(xContext, "42", uint);
|
||||
assertNotNull("littype", littype);
|
||||
|
||||
rdfslabel = URI.create(xContext, rdfs + "label");
|
||||
assertNotNull("rdfslabel", rdfslabel);
|
||||
base = URI.create(xContext, "base-uri:"); //FIXME
|
||||
assertNotNull("base", base);
|
||||
} catch (Exception e) {
|
||||
report(e);
|
||||
}
|
||||
//FIXME: ?
|
||||
// xRep = Repository.create(xContext);
|
||||
System.out.println("Creating service Repository...");
|
||||
xRep = UnoRuntime.queryInterface(XDocumentRepository.class, Repository.create(xContext));
|
||||
assertNotNull("null", xRep);
|
||||
System.out.println("...done");
|
||||
}
|
||||
|
||||
@After public void after()
|
||||
{
|
||||
xRep = null;
|
||||
}
|
||||
|
||||
@Test public void check()
|
||||
{
|
||||
try {
|
||||
System.out.println("Checking that new repository is really empty...");
|
||||
assertTrue("empty: graphs", 0 == xRep.getGraphNames().length);
|
||||
|
||||
XEnumeration stmts;
|
||||
stmts = xRep.getStatements(null, null, null);
|
||||
assertTrue("empty: stmts", !stmts.hasMoreElements());
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
System.out.println("Checking graph creation...");
|
||||
|
||||
XNamedGraph xFooGraph = xRep.createGraph(foo);
|
||||
assertNotNull("foo graph", xFooGraph);
|
||||
|
||||
try {
|
||||
xRep.createGraph(foo);
|
||||
fail("creating duplicate graph was allowed");
|
||||
} catch (ElementExistException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
xRep.createGraph(null);
|
||||
fail("invalid graph name was allowed");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
XURI[] names = xRep.getGraphNames();
|
||||
assertTrue("no foo graph in getGraphNames",
|
||||
1 == names.length && eq(names[0], foo));
|
||||
assertNotNull("no foo graph", xRep.getGraph(foo));
|
||||
|
||||
stmts = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("stmts in foo graph", !stmts.hasMoreElements());
|
||||
|
||||
XOutputStream xFooOut =
|
||||
new StreamSimulator(tempDir + "empty.rdf", false, param);
|
||||
xRep.exportGraph(FileFormat.RDF_XML, xFooOut, foo, base);
|
||||
xFooOut.closeOutput();
|
||||
|
||||
XInputStream xFooIn =
|
||||
new StreamSimulator(tempDir + "empty.rdf", true, param);
|
||||
xRep.importGraph(FileFormat.RDF_XML, xFooIn, bar, base);
|
||||
assertNotNull("no bar graph", xRep.getGraph(bar));
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
System.out.println("Checking graph manipulation...");
|
||||
|
||||
XEnumeration xFooEnum;
|
||||
|
||||
Statement xFoo_FooBarBaz = new Statement(foo, bar, baz, foo);
|
||||
xFooGraph.addStatement(foo, bar, baz);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,baz)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz }));
|
||||
|
||||
Statement xFoo_FooBarBlank = new Statement(foo, bar, blank, foo);
|
||||
xFooGraph.addStatement(foo, bar, blank);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,blank)",
|
||||
eq(xFooEnum,
|
||||
new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank }));
|
||||
xFooEnum = xRep.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,blank) (global)",
|
||||
eq(xFooEnum,
|
||||
new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank }));
|
||||
|
||||
Statement xFoo_BazBarLit = new Statement(baz, bar, lit, foo);
|
||||
xFooGraph.addStatement(baz, bar, lit);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(baz,bar,lit)",
|
||||
eq(xFooEnum, new Statement[] {
|
||||
xFoo_FooBarBaz, xFoo_FooBarBlank, xFoo_BazBarLit }));
|
||||
xFooEnum = xFooGraph.getStatements(baz, bar, null);
|
||||
assertTrue("addStatement(baz,bar,lit) (baz,bar)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_BazBarLit }));
|
||||
|
||||
Statement xFoo_BazBarLitlang =
|
||||
new Statement(baz, bar, litlang, foo);
|
||||
xFooGraph.addStatement(baz, bar, litlang);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(baz,bar,litlang)",
|
||||
eq(xFooEnum, new Statement[] {
|
||||
xFoo_FooBarBaz, xFoo_FooBarBlank, xFoo_BazBarLit,
|
||||
xFoo_BazBarLitlang }));
|
||||
xFooEnum = xFooGraph.getStatements(null, null, baz);
|
||||
assertTrue("addStatement(baz,bar,litlang) (baz)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz }));
|
||||
|
||||
Statement xFoo_BazBarLittype =
|
||||
new Statement(baz, bar, littype, foo);
|
||||
xFooGraph.addStatement(baz, bar, littype);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(baz,bar,littype)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank,
|
||||
xFoo_BazBarLit, xFoo_BazBarLitlang, xFoo_BazBarLittype }));
|
||||
|
||||
xFooGraph.removeStatements(baz, bar, litlang);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("removeStatement(baz,bar,litlang)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank,
|
||||
xFoo_BazBarLit, xFoo_BazBarLittype }));
|
||||
|
||||
xFooGraph.removeStatements(foo, bar, null);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("removeStatement(foo,bar,null)",
|
||||
eq(xFooEnum, new Statement[] {
|
||||
xFoo_BazBarLit, xFoo_BazBarLittype }));
|
||||
|
||||
xFooGraph.addStatement(foo, bar, baz);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,baz) (re-add)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz,
|
||||
xFoo_BazBarLit, xFoo_BazBarLittype }));
|
||||
|
||||
xFooGraph.addStatement(foo, bar, baz);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,baz) (duplicate)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz,
|
||||
xFoo_BazBarLit, xFoo_BazBarLittype }));
|
||||
|
||||
xFooGraph.addStatement(xFooGraph, bar, baz);
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("addStatement(foo,bar,baz) (triplicate, as graph)",
|
||||
eq(xFooEnum, new Statement[] { xFoo_FooBarBaz,
|
||||
xFoo_BazBarLit, xFoo_BazBarLittype }));
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
System.out.println("Checking graph import/export...");
|
||||
|
||||
xFooOut = new StreamSimulator(tempDir + "foo.rdf", false, param);
|
||||
xRep.exportGraph(FileFormat.RDF_XML, xFooOut, foo, base);
|
||||
xFooOut.closeOutput();
|
||||
|
||||
xFooIn = new StreamSimulator(tempDir + "foo.rdf", true, param);
|
||||
try {
|
||||
xRep.importGraph(FileFormat.RDF_XML, xFooIn, bar, base);
|
||||
fail("importing existing graph did not fail");
|
||||
} catch (ElementExistException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
xFooIn = new StreamSimulator(tempDir + "foo.rdf", true, param);
|
||||
xRep.importGraph(FileFormat.RDF_XML, xFooIn, baz, base);
|
||||
XNamedGraph xBazGraph = xRep.getGraph(baz);
|
||||
assertNotNull("no baz graph", xBazGraph);
|
||||
|
||||
Statement xBaz_FooBarBaz = new Statement(foo, bar, baz, baz);
|
||||
Statement xBaz_BazBarLit = new Statement(baz, bar, lit, baz);
|
||||
Statement xBaz_BazBarLittype =
|
||||
new Statement(baz, bar, littype, baz);
|
||||
XEnumeration xBazEnum = xBazGraph.getStatements(null, null, null);
|
||||
assertTrue("importing exported graph",
|
||||
eq(xBazEnum, new Statement[] {
|
||||
xBaz_FooBarBaz, xBaz_BazBarLit, xBaz_BazBarLittype }));
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
System.out.println("Checking graph deletion...");
|
||||
|
||||
xFooGraph.clear();
|
||||
xFooEnum = xFooGraph.getStatements(null, null, null);
|
||||
assertTrue("clear", eq(xFooEnum, new Statement[] { }));
|
||||
|
||||
xRep.destroyGraph(baz);
|
||||
assertNull("baz graph zombie", xRep.getGraph(baz));
|
||||
|
||||
try {
|
||||
xBazGraph.clear();
|
||||
fail("deleted graph not invalid (clear)");
|
||||
} catch (NoSuchElementException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
xBazGraph.addStatement(foo, foo, foo);
|
||||
fail("deleted graph not invalid (add)");
|
||||
} catch (NoSuchElementException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
xBazGraph.removeStatements(null, null, null);
|
||||
fail("deleted graph not invalid (remove)");
|
||||
} catch (NoSuchElementException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
xBazGraph.getStatements(null, null, null);
|
||||
fail("deleted graph not invalid (get)");
|
||||
} catch (NoSuchElementException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
} catch (Exception e) {
|
||||
report(e);
|
||||
}
|
||||
}
|
||||
|
||||
// utilities -------------------------------------------------------------
|
||||
|
||||
public void report(Exception e) {
|
||||
System.out.println("Exception occurred:");
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
public static String toS(XNode n) {
|
||||
if (null == n)
|
||||
{
|
||||
return "< null >";
|
||||
}
|
||||
return n.getStringValue();
|
||||
}
|
||||
|
||||
static boolean isBlank(XNode i_node)
|
||||
{
|
||||
XBlankNode blank = UnoRuntime.queryInterface(XBlankNode.class, i_node);
|
||||
return blank != null;
|
||||
}
|
||||
|
||||
static Statement[] toSeq(XEnumeration i_Enum) throws Exception
|
||||
{
|
||||
java.util.Collection<Statement> c = new java.util.ArrayList<Statement>();
|
||||
while (i_Enum.hasMoreElements()) {
|
||||
Statement s = (Statement) i_Enum.nextElement();
|
||||
c.add(s);
|
||||
}
|
||||
return c.toArray(new Statement[c.size()]);
|
||||
}
|
||||
|
||||
private static class StmtComp implements java.util.Comparator<Statement>
|
||||
{
|
||||
public int compare(Statement left, Statement right)
|
||||
{
|
||||
int eq;
|
||||
if ((eq = cmp(left.Graph, right.Graph )) != 0)
|
||||
{
|
||||
return eq;
|
||||
}
|
||||
if ((eq = cmp(left.Subject, right.Subject )) != 0)
|
||||
{
|
||||
return eq;
|
||||
}
|
||||
if ((eq = cmp(left.Predicate, right.Predicate)) != 0)
|
||||
{
|
||||
return eq;
|
||||
}
|
||||
if ((eq = cmp(left.Object, right.Object )) != 0)
|
||||
{
|
||||
return eq;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int cmp(XNode i_Left, XNode i_Right)
|
||||
{
|
||||
if (isBlank(i_Left)) {
|
||||
return isBlank(i_Right) ? 0 : 1;
|
||||
} else {
|
||||
if (isBlank(i_Right)) {
|
||||
return -1;
|
||||
} else {
|
||||
return toS(i_Left).compareTo(toS(i_Right));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean eq(Statement i_Left, Statement i_Right)
|
||||
{
|
||||
XURI lG = i_Left.Graph;
|
||||
XURI rG = i_Right.Graph;
|
||||
if (!eq(lG, rG)) {
|
||||
System.out.println("Graphs differ: " + toS(lG) + " != " + toS(rG));
|
||||
return false;
|
||||
}
|
||||
if (!eq(i_Left.Subject, i_Right.Subject)) {
|
||||
System.out.println("Subjects differ: " +
|
||||
i_Left.Subject.getStringValue() + " != " +
|
||||
i_Right.Subject.getStringValue());
|
||||
return false;
|
||||
}
|
||||
if (!eq(i_Left.Predicate, i_Right.Predicate)) {
|
||||
System.out.println("Predicates differ: " +
|
||||
i_Left.Predicate.getStringValue() + " != " +
|
||||
i_Right.Predicate.getStringValue());
|
||||
return false;
|
||||
}
|
||||
if (!eq(i_Left.Object, i_Right.Object)) {
|
||||
System.out.println("Objects differ: " +
|
||||
i_Left.Object.getStringValue() + " != " +
|
||||
i_Right.Object.getStringValue());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean eq(Statement[] i_Result, Statement[] i_Expected)
|
||||
{
|
||||
if (i_Result.length != i_Expected.length) {
|
||||
System.out.println("eq: different lengths: " + i_Result.length + " " +
|
||||
i_Expected.length);
|
||||
return false;
|
||||
}
|
||||
Statement[] expected = i_Expected.clone(); // make a copy
|
||||
java.util.Arrays.sort(i_Result, new StmtComp());
|
||||
java.util.Arrays.sort(expected, new StmtComp());
|
||||
for (int i = 0; i < expected.length; ++i) {
|
||||
if (!eq(i_Result[i], expected[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean eq(XEnumeration i_Enum, Statement[] i_Expected)
|
||||
throws Exception
|
||||
{
|
||||
Statement[] current = toSeq(i_Enum);
|
||||
return eq(current, i_Expected);
|
||||
}
|
||||
|
||||
static boolean eq(XNode i_Left, XNode i_Right)
|
||||
{
|
||||
if (i_Left == null) {
|
||||
return (i_Right == null);
|
||||
} else {
|
||||
return (i_Right != null) &&
|
||||
(i_Left.getStringValue().equals(i_Right.getStringValue())
|
||||
// FIXME: hack: blank nodes considered equal
|
||||
|| (isBlank(i_Left) && isBlank(i_Right)));
|
||||
}
|
||||
}
|
||||
|
||||
private XMultiServiceFactory getMSF()
|
||||
{
|
||||
return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
|
||||
}
|
||||
|
||||
// setup and close connections
|
||||
@BeforeClass public static void setUpConnection() throws Exception {
|
||||
System.out.println("setUpConnection()");
|
||||
connection.setUp();
|
||||
}
|
||||
|
||||
@AfterClass public static void tearDownConnection()
|
||||
throws InterruptedException, com.sun.star.uno.Exception
|
||||
{
|
||||
System.out.println("tearDownConnection()");
|
||||
connection.tearDown();
|
||||
}
|
||||
|
||||
private static final OfficeConnection connection = new OfficeConnection();
|
||||
}
|
||||
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
#include <comphelper/processfactory.hxx>
|
||||
|
||||
#include <com/sun/star/container/ElementExistException.hpp>
|
||||
#include <com/sun/star/rdf/Statement.hpp>
|
||||
#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
|
||||
#include <com/sun/star/rdf/XDocumentRepository.hpp>
|
||||
#include <com/sun/star/rdf/XRepository.hpp>
|
||||
#include <com/sun/star/rdf/BlankNode.hpp>
|
||||
#include <com/sun/star/rdf/FileFormat.hpp>
|
||||
#include <com/sun/star/rdf/Literal.hpp>
|
||||
#include <com/sun/star/rdf/Repository.hpp>
|
||||
|
@ -329,6 +331,294 @@ CPPUNIT_TEST_FIXTURE(RDFStreamTest, testSPARQL)
|
|||
sQuery = "ASK { ?pkg rdf:type pkg:Package . }";
|
||||
CPPUNIT_ASSERT(xDocRepo->queryAsk(sNss + sQuery));
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(RDFStreamTest, testRDF)
|
||||
{
|
||||
const uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext(),
|
||||
css::uno::UNO_SET_THROW);
|
||||
uno::Reference<rdf::XRepository> xRepo = rdf::Repository::create(xContext);
|
||||
uno::Reference<rdf::XDocumentRepository> xDocRepo(xRepo, uno::UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xDocRepo);
|
||||
uno::Reference<css::rdf::XURI> xFoo = rdf::URI::create(xContext, "uri:foo");
|
||||
uno::Reference<css::rdf::XURI> xBase = rdf::URI::create(xContext, "base-uri:");
|
||||
uno::Reference<css::rdf::XURI> xBar = rdf::URI::create(xContext, "uri:bar");
|
||||
uno::Reference<css::rdf::XURI> xBaz = rdf::URI::create(xContext, "uri:baz");
|
||||
uno::Reference<css::rdf::XLiteral> xLit = rdf::Literal::create(xContext, "I am the literal");
|
||||
uno::Reference<css::rdf::XURI> xInt = rdf::URI::create(xContext, "uri:int");
|
||||
uno::Reference<css::rdf::XLiteral> xLitType
|
||||
= rdf::Literal::createWithType(xContext, "42", xInt);
|
||||
uno::Reference<css::rdf::XBlankNode> xBlank = rdf::BlankNode::create(xContext, "_:uno");
|
||||
|
||||
// 1. empty: graphs
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), xDocRepo->getGraphNames().size());
|
||||
|
||||
uno::Reference<container::XEnumeration> xEnum
|
||||
= xDocRepo->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 2. empty: stmts
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
uno::Reference<rdf::XNamedGraph> xGraph = xDocRepo->createGraph(xFoo);
|
||||
|
||||
// 3. foo graph
|
||||
CPPUNIT_ASSERT(xGraph);
|
||||
|
||||
// 4. creating duplicate graph is not allowed
|
||||
try
|
||||
{
|
||||
xDocRepo->createGraph(xFoo);
|
||||
CPPUNIT_FAIL("expected ElementExistException");
|
||||
}
|
||||
catch (com::sun::star::container::ElementExistException&)
|
||||
{
|
||||
}
|
||||
|
||||
// 5. invalid graph name is not allowed
|
||||
try
|
||||
{
|
||||
xDocRepo->createGraph(nullptr);
|
||||
CPPUNIT_FAIL("expected IllegalArgumentException");
|
||||
}
|
||||
catch (css::lang::IllegalArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
// 6. foo graph in getGraphNames
|
||||
css::uno::Sequence<css::uno::Reference<css::rdf::XURI>> xURI = xDocRepo->getGraphNames();
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), xURI.size());
|
||||
CPPUNIT_ASSERT_EQUAL(xFoo->getStringValue(), xURI[0]->getStringValue());
|
||||
|
||||
// 7. foo graph
|
||||
uno::Reference<rdf::XNamedGraph> xFooGraph = xDocRepo->getGraph(xFoo);
|
||||
CPPUNIT_ASSERT(xFooGraph);
|
||||
|
||||
xEnum = xDocRepo->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 8. empty: stmts
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
const uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess(
|
||||
xContext->getServiceManager()->createInstanceWithContext(
|
||||
u"com.sun.star.ucb.SimpleFileAccess"_ustr, xContext),
|
||||
uno::UNO_QUERY_THROW);
|
||||
uno::Reference<io::XOutputStream> xOutputStream(
|
||||
xFileAccess->openFileWrite(maTempFile.GetURL()));
|
||||
xDocRepo->exportGraph(rdf::FileFormat::RDF_XML, xOutputStream, xFoo, xBase);
|
||||
xOutputStream->closeOutput();
|
||||
|
||||
uno::Reference<io::XInputStream> xInputStream(xFileAccess->openFileRead(maTempFile.GetURL()),
|
||||
uno::UNO_SET_THROW);
|
||||
xDocRepo->importGraph(rdf::FileFormat::RDF_XML, xInputStream, xBar, xBase);
|
||||
|
||||
// 7. bar graph
|
||||
CPPUNIT_ASSERT(xDocRepo->getGraph(xBar));
|
||||
|
||||
xFooGraph->addStatement(xFoo, xBar, xBaz);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 8. addStatement(foo,bar,baz)
|
||||
rdf::Statement aFoo_FooBarBaz(xFoo, xBar, xBaz, xFoo);
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xFoo, xBar, xBlank);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 9. addStatement(foo,bar,blank)
|
||||
rdf::Statement aFoo_FooBarBlank(xFoo, xBar, xBlank, xFoo);
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBlank, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xBaz, xBar, xLit);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 10. addStatement(baz,bar,lit)
|
||||
rdf::Statement aFoo_BazBarLit(xBaz, xBar, xLit, xFoo);
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBlank, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xEnum = xFooGraph->getStatements(xBaz, xBar, nullptr);
|
||||
|
||||
// 11. addStatement(baz,bar,lit) (baz,bar)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
uno::Reference<css::rdf::XLiteral> xLitLang
|
||||
= rdf::Literal::createWithLanguage(xContext, "I am the literal", "en");
|
||||
xFooGraph->addStatement(xBaz, xBar, xLitLang);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 12. addStatement(baz,bar,litlang)
|
||||
rdf::Statement aFoo_BazBarLitlang(xBaz, xBar, xLitLang, xFoo);
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitlang, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBlank, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, xBaz);
|
||||
|
||||
// 13. addStatement(baz,bar,litlang) (baz)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xBaz, xBar, xLitType);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 14. addStatement(baz,bar,littype)
|
||||
rdf::Statement aFoo_BazBarLitType(xBaz, xBar, xLitType, xFoo);
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitlang, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBlank, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->removeStatements(xBaz, xBar, xLitLang);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 15. removeStatement(baz,bar,litlang)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBlank, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->removeStatements(xFoo, xBar, nullptr);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 16. removeStatement(foo,bar,null)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xFoo, xBar, xBaz);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 17. addStatement(foo,bar,baz) (re-add)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xFoo, xBar, xBaz);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 18. addStatement(foo,bar,baz) (duplicate)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xFooGraph->addStatement(xFooGraph, xBar, xBaz);
|
||||
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 19. addStatement(foo,bar,baz) (triplicate, as graph)
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aFoo_BazBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
xOutputStream.set(xFileAccess->openFileWrite(maTempFile.GetURL()));
|
||||
xDocRepo->exportGraph(rdf::FileFormat::RDF_XML, xOutputStream, xFoo, xBase);
|
||||
xOutputStream->closeOutput();
|
||||
|
||||
xInputStream.set(xFileAccess->openFileRead(maTempFile.GetURL()), uno::UNO_SET_THROW);
|
||||
try
|
||||
{
|
||||
xDocRepo->importGraph(rdf::FileFormat::RDF_XML, xInputStream, xBar, xBase);
|
||||
CPPUNIT_FAIL("importing existing graph did not fail");
|
||||
}
|
||||
catch (com::sun::star::container::ElementExistException&)
|
||||
{
|
||||
}
|
||||
|
||||
xInputStream.set(xFileAccess->openFileRead(maTempFile.GetURL()), uno::UNO_SET_THROW);
|
||||
xDocRepo->importGraph(rdf::FileFormat::RDF_XML, xInputStream, xBaz, xBase);
|
||||
uno::Reference<rdf::XNamedGraph> xBazGraph = xDocRepo->getGraph(xBaz);
|
||||
CPPUNIT_ASSERT(xBazGraph);
|
||||
|
||||
rdf::Statement aBaz_FooBarBaz(xFoo, xBar, xBaz, xBaz);
|
||||
rdf::Statement aBaz_FooBarLit(xBaz, xBar, xLit, xBaz);
|
||||
rdf::Statement aBaz_FooBarLitType(xBaz, xBar, xLitType, xBaz);
|
||||
|
||||
xEnum = xBazGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
|
||||
// 20. importing exported graph
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aBaz_FooBarBaz, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aBaz_FooBarLitType, xEnum->nextElement().get<rdf::Statement>());
|
||||
CPPUNIT_ASSERT_STATEMENT_EQUAL(aBaz_FooBarLit, xEnum->nextElement().get<rdf::Statement>());
|
||||
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
// 21. Checking graph deletion
|
||||
xFooGraph->clear();
|
||||
xEnum = xFooGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
CPPUNIT_ASSERT(!xEnum->hasMoreElements());
|
||||
|
||||
// 22. baz graph zombie
|
||||
xDocRepo->destroyGraph(xBaz);
|
||||
CPPUNIT_ASSERT(!xDocRepo->getGraph(xBaz));
|
||||
|
||||
try
|
||||
{
|
||||
xBazGraph->clear();
|
||||
CPPUNIT_FAIL("deleted graph not invalid (clear)");
|
||||
}
|
||||
catch (com::sun::star::container::NoSuchElementException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
xBazGraph->addStatement(xFoo, xFoo, xFoo);
|
||||
CPPUNIT_FAIL("deleted graph not invalid (add)");
|
||||
}
|
||||
catch (com::sun::star::container::NoSuchElementException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
xBazGraph->removeStatements(nullptr, nullptr, nullptr);
|
||||
CPPUNIT_FAIL("deleted graph not invalid (remove)");
|
||||
}
|
||||
catch (com::sun::star::container::NoSuchElementException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
xBazGraph->getStatements(nullptr, nullptr, nullptr);
|
||||
CPPUNIT_FAIL("deleted graph not invalid (remove)");
|
||||
}
|
||||
catch (com::sun::star::container::NoSuchElementException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
|
Loading…
Reference in a new issue