summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-03-13 12:48:07 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-08-13 11:07:10 +0200
commit6b2def18093055290cc896023078b639d85694f6 (patch)
treedfbbebb126d81f4dbbb63eef8dba7889e3f55b25
parentde6355afa4bf89199c7281ddb43a141e192d43d6 (diff)
tdf#123293 Add test
Test for commit 0a5ca5768f56db481dd3b947b3dddaab7ed96450 Change-Id: I53b72c385d9ef4d51cefa687f07a75c9520d3e71 Reviewed-on: https://gerrit.libreoffice.org/69165 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> (cherry picked from commit e9ce7acaf5cc87a4fb40f12ea0aac8cb9df3562f) Reviewed-on: https://gerrit.libreoffice.org/69182 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> (cherry picked from commit ed85a358d4aed976ec19578fbfbe00d31c6430fe) Reviewed-on: https://gerrit.libreoffice.org/76215 Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r--qadevOOo/runner/util/DesktopTools.java48
-rw-r--r--sfx2/qa/complex/sfx2/DocumentMetadataAccess.java15
-rw-r--r--sfx2/qa/complex/sfx2/tools/TestDocument.java3
3 files changed, 66 insertions, 0 deletions
diff --git a/qadevOOo/runner/util/DesktopTools.java b/qadevOOo/runner/util/DesktopTools.java
index 1650a04fdb71..5b82a2dc3726 100644
--- a/qadevOOo/runner/util/DesktopTools.java
+++ b/qadevOOo/runner/util/DesktopTools.java
@@ -19,6 +19,10 @@ package util;
import helper.ConfigHelper;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.ArrayList;
import lib.StatusException;
@@ -35,9 +39,11 @@ import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XModel;
+import com.sun.star.io.XInputStream;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XCloseable;
@@ -253,6 +259,48 @@ public class DesktopTools
}
/**
+ * 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));
+ 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);
+ inputFile.close();
+ inputStream = new ByteArrayToXInputStreamAdapter(
+ bytes.toByteArray());
+ } 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
* @param DocumentToClose the document to close
*/
diff --git a/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java b/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java
index 9a0e7b8170a7..5697bba07e20 100644
--- a/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java
+++ b/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java
@@ -615,6 +615,21 @@ 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);
+ }
+ }
+
private void storeRDFa(XComponent xComp, String file) throws com.sun.star.io.IOException
{
System.out.println("Storing test document...");
diff --git a/sfx2/qa/complex/sfx2/tools/TestDocument.java b/sfx2/qa/complex/sfx2/tools/TestDocument.java
index d10a4b0cb5d6..462c97fb99b7 100644
--- a/sfx2/qa/complex/sfx2/tools/TestDocument.java
+++ b/sfx2/qa/complex/sfx2/tools/TestDocument.java
@@ -26,6 +26,9 @@ public final class TestDocument {
public static String getUrl(String name) {
return OfficeFileUrl.getAbsolute(new File(Argument.get("tdoc"), name));
}
+ public static String getPath(String name) {
+ return new File(Argument.get("tdoc"), name).toString();
+ }
private TestDocument() {}
}