diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sot/qa/complex | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream/4%7.4.7.tar.xz libreoffice-upstream/4%7.4.7.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sot/qa/complex')
4 files changed, 270 insertions, 0 deletions
diff --git a/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java b/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java new file mode 100644 index 000000000..f01a14178 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java @@ -0,0 +1,5 @@ +package complex.olesimplestorage; + +interface OLESimpleStorageTest { + boolean test(); +} diff --git a/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java b/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java new file mode 100644 index 000000000..4c96ce1f6 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java @@ -0,0 +1,84 @@ +/* + * 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.olesimplestorage; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; + + +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.*; + +/* Document. + */ + +public class OLESimpleStorageUnitTest +{ + private XMultiServiceFactory m_xMSF = null; + + @Before public void before () { + System.out.println("before()"); + try { + m_xMSF = getMSF(); + } catch ( Exception e ){ + fail( "Cannot create service factory!" ); + } + if ( m_xMSF == null ) { + fail( "Cannot create service factory!" ); + } + } + + @After public void after () { + System.out.println("after()"); + m_xMSF = null; + } + + @Test public void ExecuteTest01() { + System.out.println("ExecuteTest01()"); + OLESimpleStorageTest aTest = new Test01( m_xMSF ); + assertTrue( "Test01 failed!", aTest.test() ); + } + + + + 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(); + +}
\ No newline at end of file diff --git a/sot/qa/complex/olesimplestorage/Test01.java b/sot/qa/complex/olesimplestorage/Test01.java new file mode 100644 index 000000000..18d220e05 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/Test01.java @@ -0,0 +1,140 @@ +/* + * 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.olesimplestorage; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.io.XTempFile; +import com.sun.star.embed.XOLESimpleStorage; +import com.sun.star.uno.UnoRuntime; + +import java.util.Random; + + +public class Test01 implements OLESimpleStorageTest +{ + private XMultiServiceFactory m_xMSF = null; + private TestHelper m_aTestHelper = null; + private static final int pStreamCnt = 5; + private static final int pBytesCnt = 10; + + public Test01 ( XMultiServiceFactory xMSF ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper ("Test01: "); + } + + public boolean test () + { + try + { + //create a new temporary stream + Object oTempFile = m_xMSF.createInstance ( "com.sun.star.io.TempFile" ); + XTempFile xTempFile = UnoRuntime.queryInterface(XTempFile.class, oTempFile); + m_aTestHelper.Message ( "A new temporary stream created." ); + + //create OLESimpleStorage based on it + Object pArgs[] = new Object[2]; + pArgs[0] = xTempFile; + pArgs[1] = Boolean.TRUE; + Object oOLESimpleStorage = m_xMSF.createInstanceWithArguments ( "com.sun.star.embed.OLESimpleStorage", pArgs ); + XOLESimpleStorage xOLESimpleStorage = UnoRuntime.queryInterface(XOLESimpleStorage.class, oOLESimpleStorage); + m_aTestHelper.Message ( "OLESimpleStorage based on XStream created." ); + + //fill it with some streams + Object oStream[] = new Object[pStreamCnt]; + byte pBytesIn[][][] = new byte [pStreamCnt][1][pBytesCnt]; + byte pBytesOut[][] = new byte [pStreamCnt][pBytesCnt]; + XTempFile xTempStream[] = new XTempFile[pStreamCnt]; + Random oRandom = new Random (); + final String sSubStreamPrefix = "SubStream"; + for ( int i = 0; i < pStreamCnt; i++ ) + { + oRandom.nextBytes (pBytesOut[i]); + oStream[i] = m_xMSF.createInstance ( "com.sun.star.io.TempFile" ); + xTempStream[i] = UnoRuntime.queryInterface(XTempFile.class, oStream[i]); + xTempStream[i].getOutputStream ().writeBytes (pBytesOut[i]); + xTempStream[i].seek (0); + m_aTestHelper.Message ( "Substream " + i + " initialized." ); + if (xOLESimpleStorage.hasByName (sSubStreamPrefix + i)) + { + xOLESimpleStorage.replaceByName ( sSubStreamPrefix + i, xTempStream[i] ); + } + else + { + xOLESimpleStorage.insertByName ( sSubStreamPrefix + i, xTempStream[i] ); + m_aTestHelper.Message ( "Substream " + i + " inserted." ); + } + } + + //commit the storage and close it + xOLESimpleStorage.commit (); + m_aTestHelper.Message ( "Storage committed." ); + xOLESimpleStorage.dispose (); + for ( int i = 0; i < pStreamCnt; ++i ) + { + xTempStream[i].setRemoveFile ( true ); + xTempStream[i].getInputStream ().closeInput (); + xTempStream[i].getOutputStream ().closeOutput (); + } + m_aTestHelper.Message ( "Storage closed." ); + + //open the same stream with the constructor for inputstream + pArgs[0] = xTempFile.getInputStream (); + oOLESimpleStorage = m_xMSF.createInstanceWithArguments ( "com.sun.star.embed.OLESimpleStorage", pArgs ); + xOLESimpleStorage = UnoRuntime.queryInterface(XOLESimpleStorage.class, oOLESimpleStorage); + m_aTestHelper.Message ( "Storage reopened, based on XInputStream." ); + + //check that all the streams contain correct information + m_aTestHelper.Message ( "Checking data contained in all the substreams..." ); + for ( int i = 0; i < pStreamCnt; ++i ) + { + if ( xOLESimpleStorage.hasByName (sSubStreamPrefix + i) ) + { + xTempStream[i] = UnoRuntime.queryInterface(XTempFile.class, xOLESimpleStorage.getByName(sSubStreamPrefix + i)); + xTempStream[i].seek (0); + xTempStream[i].getInputStream ().readBytes (pBytesIn[i], pBytesIn[i][0].length + 1 ); + for ( int j = 0; j < pBytesCnt; ++j ) + { + if ( pBytesIn[i][0][j] != pBytesOut[i][j] ) + { + m_aTestHelper.Error ( "Stream " + i + " byte " + j + ": INCORRECT DATA!"); + return false; + } + else + { + m_aTestHelper.Message ( "Stream " + i + " byte " + j + ": CORRECT." ); + } + } + } + else + { + m_aTestHelper.Error( "Stream " + i + " is lost!"); + return false; + } + } + m_aTestHelper.Message ( "All substreams contain correct data. SUCCESS." ); + } + catch ( Exception e ) + { + m_aTestHelper.Error ( "Exception: " + e ); + return false; + } + return true; + } +} diff --git a/sot/qa/complex/olesimplestorage/TestHelper.java b/sot/qa/complex/olesimplestorage/TestHelper.java new file mode 100644 index 000000000..651ee9218 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/TestHelper.java @@ -0,0 +1,41 @@ +/* + * 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.olesimplestorage; + +public class TestHelper +{ + + private String m_sTestPrefix; + + public TestHelper ( String sTestPrefix ) + { + + m_sTestPrefix = sTestPrefix; + } + + public void Error ( String sError ) + { + System.out.println ( m_sTestPrefix + "Error: " + sError ); + } + + public void Message ( String sMessage ) + { + System.out.println ( m_sTestPrefix + sMessage ); + } +} |