unoxml: move checkRDFa from Java to CppUnittest
Change-Id: Ife5cd7398bdbacbd8189c8451dab6351590052e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173484 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
parent
1ce7c35402
commit
c600065569
3 changed files with 135 additions and 128 deletions
|
@ -27,8 +27,11 @@ $(eval $(call gb_CppunitTest_use_libraries,unoxml_rdftest, \
|
|||
cppuhelper \
|
||||
sal \
|
||||
sax \
|
||||
subsequenttest \
|
||||
test \
|
||||
tl \
|
||||
unotest \
|
||||
utl \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_configuration,unoxml_rdftest))
|
||||
|
|
|
@ -436,101 +436,6 @@ public class RDFRepositoryTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test public void checkRDFa()
|
||||
{
|
||||
try {
|
||||
System.out.println("Checking RDFa gunk...");
|
||||
|
||||
String content = "behold, for I am the content.";
|
||||
XTextRange xTR = new TestRange(content);
|
||||
XMetadatable xM = (XMetadatable) xTR;
|
||||
|
||||
Pair<Statement[], Boolean> result =
|
||||
xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: not empty (initial)",
|
||||
0 == result.First.length);
|
||||
|
||||
try {
|
||||
xRep.setStatementRDFa(foo, new XURI[] {}, xM, "", null);
|
||||
fail("RDFa: set: no predicate");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
xRep.setStatementRDFa(foo, new XURI[] {bar}, null, "", null);
|
||||
fail("RDFa: set: null");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
XLiteral trlit = Literal.create(xContext, content);
|
||||
Statement x_FooBarTRLit = new Statement(foo, bar, trlit, null);
|
||||
xRep.setStatementRDFa(foo, new XURI[] { bar }, xM, "", null);
|
||||
|
||||
result = xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: without content",
|
||||
!result.Second && (1 == result.First.length)
|
||||
&& eq(result.First[0], x_FooBarTRLit));
|
||||
|
||||
//FIXME: do this?
|
||||
xTR.setString(lit.getStringValue());
|
||||
/*
|
||||
Statement xFooBarLit = new Statement(foo, bar, lit, null);
|
||||
result = xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: change",
|
||||
eq((Statement)result.First, xFooBarLit) && null == result.Second);
|
||||
*/
|
||||
|
||||
Statement x_FooBarLittype = new Statement(foo, bar, littype, null);
|
||||
xRep.setStatementRDFa(foo, new XURI[] { bar }, xM, "42", uint);
|
||||
|
||||
result = xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: with content",
|
||||
result.Second &&
|
||||
(1 == result.First.length) &&
|
||||
eq(result.First[0], x_FooBarLittype));
|
||||
|
||||
//FIXME: do this?
|
||||
xTR.setString(content);
|
||||
/*
|
||||
Statement xFooLabelTRLit = new Statement(foo, rdfslabel, trlit, null);
|
||||
result = xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: change (label)",
|
||||
eq((Statement)result.First, xFooBarLittype) &&
|
||||
eq((Statement)result.Second, xFooLabelTRLit));
|
||||
*/
|
||||
|
||||
xRep.removeStatementRDFa((XMetadatable)xTR);
|
||||
|
||||
result = xRep.getStatementRDFa((XMetadatable)xTR);
|
||||
assertTrue("RDFa: get: not empty (removed)",
|
||||
0 == result.First.length);
|
||||
|
||||
xRep.setStatementRDFa(foo, new XURI[] { foo, bar, baz }, xM,
|
||||
"", null);
|
||||
|
||||
Statement x_FooFooTRLit = new Statement(foo, foo, trlit, null);
|
||||
Statement x_FooBazTRLit = new Statement(foo, baz, trlit, null);
|
||||
result = xRep.getStatementRDFa((XMetadatable) xTR);
|
||||
assertTrue("RDFa: get: without content (multiple predicates, reinsert)",
|
||||
!result.Second &&
|
||||
eq(result.First, new Statement[] {
|
||||
x_FooFooTRLit, x_FooBarTRLit, x_FooBazTRLit }));
|
||||
|
||||
xRep.removeStatementRDFa((XMetadatable)xTR);
|
||||
|
||||
result = xRep.getStatementRDFa((XMetadatable) xTR);
|
||||
assertTrue("RDFa: get: not empty (re-removed)",
|
||||
0 == result.First.length);
|
||||
|
||||
System.out.println("...done");
|
||||
|
||||
} catch (Exception e) {
|
||||
report(e);
|
||||
}
|
||||
}
|
||||
|
||||
// utilities -------------------------------------------------------------
|
||||
|
||||
public void report(Exception e) {
|
||||
|
@ -776,37 +681,6 @@ public class RDFRepositoryTest
|
|||
}
|
||||
}
|
||||
|
||||
private class TestRange implements XTextRange, XMetadatable, XServiceInfo
|
||||
{
|
||||
private String m_Stream;
|
||||
String m_XmlId;
|
||||
String m_Text;
|
||||
TestRange(String i_Str) { m_Text = i_Str; }
|
||||
|
||||
public String getStringValue() { return ""; }
|
||||
public String getNamespace() { return ""; }
|
||||
public String getLocalName() { return ""; }
|
||||
|
||||
public StringPair getMetadataReference()
|
||||
{ return new StringPair(m_Stream, m_XmlId); }
|
||||
public void setMetadataReference(StringPair i_Ref)
|
||||
throws IllegalArgumentException
|
||||
{ m_Stream = i_Ref.First; m_XmlId = i_Ref.Second; }
|
||||
public void ensureMetadataReference()
|
||||
{ m_Stream = "content.xml"; m_XmlId = "42"; }
|
||||
|
||||
public String getImplementationName() { return null; }
|
||||
public String[] getSupportedServiceNames() { return null; }
|
||||
public boolean supportsService(String i_Svc)
|
||||
{ return i_Svc.equals("com.sun.star.text.Paragraph"); }
|
||||
|
||||
public XText getText() { return null; }
|
||||
public XTextRange getStart() { return null; }
|
||||
public XTextRange getEnd() { return null; }
|
||||
public String getString() { return m_Text; }
|
||||
public void setString(String i_Str) { m_Text = i_Str; }
|
||||
}
|
||||
|
||||
private XMultiServiceFactory getMSF()
|
||||
{
|
||||
return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <test/bootstrapfixture.hxx>
|
||||
#include <test/unoapi_test.hxx>
|
||||
|
||||
#include <comphelper/processfactory.hxx>
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
|||
#include <com/sun/star/rdf/XDocumentRepository.hpp>
|
||||
#include <com/sun/star/rdf/XRepository.hpp>
|
||||
#include <com/sun/star/rdf/FileFormat.hpp>
|
||||
#include <com/sun/star/rdf/Literal.hpp>
|
||||
#include <com/sun/star/rdf/Repository.hpp>
|
||||
#include <com/sun/star/rdf/URI.hpp>
|
||||
#include <com/sun/star/text/XTextDocument.hpp>
|
||||
|
@ -25,8 +26,13 @@ using namespace com::sun::star;
|
|||
|
||||
namespace
|
||||
{
|
||||
class RDFStreamTest : public test::BootstrapFixture
|
||||
class RDFStreamTest : public UnoApiTest
|
||||
{
|
||||
public:
|
||||
RDFStreamTest()
|
||||
: UnoApiTest(u"/unoxml/qa/unit/data/"_ustr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(RDFStreamTest, testCVE_2012_0037)
|
||||
|
@ -60,6 +66,130 @@ CPPUNIT_TEST_FIXTURE(RDFStreamTest, testCVE_2012_0037)
|
|||
CPPUNIT_ASSERT_EQUAL(OUString("uri:bar"), aStatement.Predicate->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("EVIL"), aStatement.Object->getStringValue());
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(RDFStreamTest, testRDFa)
|
||||
{
|
||||
mxComponent = loadFromDesktop(u"private:factory/swriter"_ustr);
|
||||
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
|
||||
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
|
||||
uno::UNO_QUERY);
|
||||
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
|
||||
uno::Reference<text::XTextRange> xTextRange(xParaEnum->nextElement(), uno::UNO_QUERY);
|
||||
|
||||
xTextRange->setString(u"behold, for I am the content."_ustr);
|
||||
|
||||
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(mxComponent,
|
||||
uno::UNO_QUERY);
|
||||
uno::Reference<rdf::XRepository> xRepo = xDocumentMetadataAccess->getRDFRepository();
|
||||
uno::Reference<rdf::XDocumentRepository> xDocRepo(xRepo, uno::UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xDocRepo);
|
||||
|
||||
uno::Reference<rdf::XMetadatable> xMeta(xTextRange, uno::UNO_QUERY);
|
||||
|
||||
// 1. RDFa: get: not empty (initial)
|
||||
::beans::Pair<uno::Sequence<rdf::Statement>, sal_Bool> xResult
|
||||
= xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), xResult.First.size());
|
||||
CPPUNIT_ASSERT(!xResult.Second);
|
||||
|
||||
uno::Reference<uno::XComponentContext> xContext = getComponentContext();
|
||||
uno::Reference<css::rdf::XURI> xFoo = rdf::URI::create(xContext, "uri:foo");
|
||||
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::XURI> xInt = rdf::URI::create(xContext, "uri:int");
|
||||
css::uno::Sequence<uno::Reference<rdf::XURI>> xURI{};
|
||||
|
||||
// 2. RDFa: set: no predicate
|
||||
try
|
||||
{
|
||||
xDocRepo->setStatementRDFa(xFoo, xURI, xMeta, OUString(), nullptr);
|
||||
CPPUNIT_FAIL("expected IllegalArgumentException");
|
||||
}
|
||||
catch (css::lang::IllegalArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
css::uno::Sequence<uno::Reference<rdf::XURI>> xURI2{ xBar };
|
||||
|
||||
// 3. RDFa: set: null
|
||||
try
|
||||
{
|
||||
xDocRepo->setStatementRDFa(xFoo, xURI2, nullptr, OUString(), nullptr);
|
||||
CPPUNIT_FAIL("expected IllegalArgumentException");
|
||||
}
|
||||
catch (css::lang::IllegalArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
xDocRepo->setStatementRDFa(xFoo, xURI2, xMeta, OUString(), nullptr);
|
||||
|
||||
// 4. RDFa: get: without content
|
||||
xResult = xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), xResult.First.size());
|
||||
CPPUNIT_ASSERT(!xResult.Second);
|
||||
|
||||
rdf::Statement aStatement = xResult.First[0];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Subject->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:bar"), aStatement.Predicate->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("behold, for I am the content."),
|
||||
aStatement.Object->getStringValue());
|
||||
|
||||
xDocRepo->setStatementRDFa(xFoo, xURI2, xMeta, u"42"_ustr, xInt);
|
||||
|
||||
// 5. RDFa: get: with content
|
||||
xResult = xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), xResult.First.size());
|
||||
CPPUNIT_ASSERT(xResult.Second);
|
||||
|
||||
aStatement = xResult.First[0];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Subject->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:bar"), aStatement.Predicate->getStringValue());
|
||||
|
||||
uno::Reference<css::rdf::XLiteral> xLitType
|
||||
= rdf::Literal::createWithType(xContext, "42", xInt);
|
||||
CPPUNIT_ASSERT_EQUAL(xLitType->getStringValue(), aStatement.Object->getStringValue());
|
||||
|
||||
xDocRepo->removeStatementRDFa(xMeta);
|
||||
|
||||
// 6. RDFa: get: not empty (removed)
|
||||
xResult = xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), xResult.First.size());
|
||||
CPPUNIT_ASSERT(xResult.Second);
|
||||
|
||||
css::uno::Sequence<uno::Reference<rdf::XURI>> xURI3{ xFoo, xBar, xBaz };
|
||||
|
||||
xDocRepo->setStatementRDFa(xFoo, xURI3, xMeta, OUString(), nullptr);
|
||||
|
||||
// 7. RDFa: get: without content (multiple predicates, reinsert)
|
||||
xResult = xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(3), xResult.First.size());
|
||||
CPPUNIT_ASSERT(!xResult.Second);
|
||||
|
||||
aStatement = xResult.First[0];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Subject->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:baz"), aStatement.Predicate->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("behold, for I am the content."),
|
||||
aStatement.Object->getStringValue());
|
||||
|
||||
aStatement = xResult.First[1];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Subject->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:bar"), aStatement.Predicate->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("behold, for I am the content."),
|
||||
aStatement.Object->getStringValue());
|
||||
|
||||
aStatement = xResult.First[2];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Subject->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("uri:foo"), aStatement.Predicate->getStringValue());
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("behold, for I am the content."),
|
||||
aStatement.Object->getStringValue());
|
||||
|
||||
xDocRepo->removeStatementRDFa(xMeta);
|
||||
|
||||
// 8. RDFa: get: not empty (re-removed)
|
||||
xResult = xDocRepo->getStatementRDFa(xMeta);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), xResult.First.size());
|
||||
CPPUNIT_ASSERT(!xResult.Second);
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
|
Loading…
Reference in a new issue