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:
Xisco Fauli
2024-07-03 16:48:54 +02:00
parent 433c4180ac
commit e42be49887
4 changed files with 23 additions and 68 deletions
-45
View File
@@ -258,51 +258,6 @@ public class DesktopTools
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
* @param DocumentToClose the document to close