tdf#123293: port test from Java to CppUnitTest
Change-Id: I5297a041970871ab0fba6a71d59639b07072b64b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169889 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Tested-by: Jenkins
This commit is contained in:
parent
433c4180ac
commit
e42be49887
4 changed files with 23 additions and 68 deletions
|
@ -258,51 +258,6 @@ public class DesktopTools
|
||||||
return oDoc;
|
return oDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* loads a document of from a given path using an input stream
|
|
||||||
*
|
|
||||||
* @param xMSF the MultiServiceFactory
|
|
||||||
* @param filePath the path of the document to load.
|
|
||||||
* @return the XComponent Interface of the document
|
|
||||||
*/
|
|
||||||
public static XComponent loadDocUsingStream(XMultiServiceFactory xMSF, String filePath)
|
|
||||||
{
|
|
||||||
XInputStream inputStream = null;
|
|
||||||
try {
|
|
||||||
final InputStream inputFile = new BufferedInputStream(
|
|
||||||
new FileInputStream(filePath));
|
|
||||||
try {
|
|
||||||
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
||||||
final byte[] byteBuffer = new byte[4096];
|
|
||||||
int byteBufferLength = 0;
|
|
||||||
while ((byteBufferLength = inputFile.read(byteBuffer)) > 0)
|
|
||||||
bytes.write(byteBuffer, 0, byteBufferLength);
|
|
||||||
inputStream = new ByteArrayToXInputStreamAdapter(
|
|
||||||
bytes.toByteArray());
|
|
||||||
} finally {
|
|
||||||
inputFile.close();
|
|
||||||
}
|
|
||||||
} catch (java.io.IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyValue[] loadProps = new PropertyValue[1];
|
|
||||||
loadProps[0] = new PropertyValue();
|
|
||||||
loadProps[0].Name = "InputStream";
|
|
||||||
loadProps[0].Value = inputStream;
|
|
||||||
|
|
||||||
XComponent oDoc = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
oDoc = getCLoader(xMSF).loadComponentFromURL("private:stream", "_blank", 0, loadProps);
|
|
||||||
}
|
|
||||||
catch (com.sun.star.uno.Exception e)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Document could not be loaded", e);
|
|
||||||
}
|
|
||||||
return oDoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* closes a given document
|
* closes a given document
|
||||||
* @param DocumentToClose the document to close
|
* @param DocumentToClose the document to close
|
||||||
|
|
|
@ -578,21 +578,6 @@ public class DocumentMetadataAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void checkTdf123293() throws Exception
|
|
||||||
{
|
|
||||||
XComponent xComp = null;
|
|
||||||
try {
|
|
||||||
xComp = util.DesktopTools.loadDocUsingStream(xMSF, TestDocument.getPath("TESTRDFA.odt"));
|
|
||||||
|
|
||||||
// Metadata was discarded when loading from stream, make sure it's there now
|
|
||||||
XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
|
|
||||||
assertNotNull("No metadata loaded", xRepoSupplier);
|
|
||||||
} finally {
|
|
||||||
close(xComp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// utilities -------------------------------------------------------------
|
// utilities -------------------------------------------------------------
|
||||||
|
|
||||||
static void close(XComponent i_comp)
|
static void close(XComponent i_comp)
|
||||||
|
|
Binary file not shown.
|
@ -15,10 +15,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <cppunit/TestAssert.h>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
#include <cppunit/plugin/TestPlugIn.h>
|
|
||||||
|
|
||||||
#include <com/sun/star/beans/Pair.hpp>
|
#include <com/sun/star/beans/Pair.hpp>
|
||||||
#include <com/sun/star/beans/PropertyState.hpp>
|
#include <com/sun/star/beans/PropertyState.hpp>
|
||||||
#include <com/sun/star/beans/PropertyValue.hpp>
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
||||||
|
@ -31,20 +27,20 @@
|
||||||
#include <com/sun/star/rdf/XDocumentRepository.hpp>
|
#include <com/sun/star/rdf/XDocumentRepository.hpp>
|
||||||
#include <com/sun/star/rdf/XRepository.hpp>
|
#include <com/sun/star/rdf/XRepository.hpp>
|
||||||
#include <com/sun/star/text/XTextDocument.hpp>
|
#include <com/sun/star/text/XTextDocument.hpp>
|
||||||
#include <comphelper/sequence.hxx>
|
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
|
||||||
|
|
||||||
#include <test/unoapixml_test.hxx>
|
#include <test/unoapixml_test.hxx>
|
||||||
|
|
||||||
#include <unotools/ucbstreamhelper.hxx>
|
#include <unotools/ucbstreamhelper.hxx>
|
||||||
|
#include <comphelper/sequence.hxx>
|
||||||
#include <comphelper/propertysequence.hxx>
|
#include <comphelper/propertysequence.hxx>
|
||||||
|
#include <comphelper/propertyvalue.hxx>
|
||||||
#include <comphelper/processfactory.hxx>
|
#include <comphelper/processfactory.hxx>
|
||||||
#include <sfx2/app.hxx>
|
#include <sfx2/app.hxx>
|
||||||
#include <osl/file.hxx>
|
#include <osl/file.hxx>
|
||||||
|
|
||||||
|
|
||||||
using namespace ::com::sun::star;
|
using namespace ::com::sun::star;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MiscTest
|
class MiscTest
|
||||||
|
@ -56,7 +52,6 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override
|
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override
|
||||||
{
|
{
|
||||||
// ODF
|
// ODF
|
||||||
|
@ -451,6 +446,26 @@ CPPUNIT_TEST_FIXTURE(MiscTest, testRDFa)
|
||||||
saveAndReload(u"writer8"_ustr);
|
saveAndReload(u"writer8"_ustr);
|
||||||
verify(/*bIsExport*/ true);
|
verify(/*bIsExport*/ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPPUNIT_TEST_FIXTURE(MiscTest, testTdf123293)
|
||||||
|
{
|
||||||
|
const uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext(),
|
||||||
|
css::uno::UNO_SET_THROW);
|
||||||
|
const uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess(
|
||||||
|
xContext->getServiceManager()->createInstanceWithContext(
|
||||||
|
u"com.sun.star.ucb.SimpleFileAccess"_ustr, xContext),
|
||||||
|
uno::UNO_QUERY_THROW);
|
||||||
|
const uno::Reference<io::XInputStream> xInputStream(xFileAccess->openFileRead(createFileURL(u"TESTRDFA.odt") ),
|
||||||
|
uno::UNO_SET_THROW);
|
||||||
|
uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(
|
||||||
|
"InputStream", xInputStream) };
|
||||||
|
mxComponent = mxDesktop->loadComponentFromURL(u"private:stream"_ustr, u"_blank"_ustr, 0, aLoadArgs);
|
||||||
|
CPPUNIT_ASSERT(mxComponent.is());
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
|
Loading…
Reference in a new issue