diff options
Diffstat (limited to 'package/qa/ofopxmlstorages')
-rw-r--r-- | package/qa/ofopxmlstorages/StorageTest.java | 7 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/StorageUnitTest.java | 149 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test01.java | 218 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test02.java | 182 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test03.java | 251 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test04.java | 326 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test05.java | 332 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test06.java | 295 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test07.java | 276 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test08.java | 279 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/TestHelper.java | 1111 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/makefile.mk | 82 |
12 files changed, 3508 insertions, 0 deletions
diff --git a/package/qa/ofopxmlstorages/StorageTest.java b/package/qa/ofopxmlstorages/StorageTest.java new file mode 100644 index 000000000..5f3b2ff2a --- /dev/null +++ b/package/qa/ofopxmlstorages/StorageTest.java @@ -0,0 +1,7 @@ +package complex.ofopxmlstorages; + +public interface StorageTest +{ + boolean test(); +} + diff --git a/package/qa/ofopxmlstorages/StorageUnitTest.java b/package/qa/ofopxmlstorages/StorageUnitTest.java new file mode 100644 index 000000000..e8ee7696a --- /dev/null +++ b/package/qa/ofopxmlstorages/StorageUnitTest.java @@ -0,0 +1,149 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.connection.XConnector; +import com.sun.star.connection.XConnection; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.XNamingService; +import com.sun.star.uno.XComponentContext; + +import com.sun.star.container.*; +import com.sun.star.beans.*; +import com.sun.star.lang.*; + +import complexlib.ComplexTestCase; + +import complex.ofopxmlstorages.*; + +import util.utils; +import java.util.*; +import java.io.*; + +/* This unit test for storage objects is designed to + * test most important statements from storage service + * specification. + * + * Regression tests are added to extend the tested + * functionalities. + */ +public class StorageUnitTest extends ComplexTestCase +{ + private XMultiServiceFactory m_xMSF = null; + private XSingleServiceFactory m_xStorageFactory = null; + + public String[] getTestMethodNames() + { + return new String[] { + "ExecuteTest01", + "ExecuteTest02", + "ExecuteTest03", + "ExecuteTest04", + "ExecuteTest05", + "ExecuteTest06", + "ExecuteTest07", + "ExecuteTest08" + }; + } + + public String getTestObjectName() + { + return "StorageUnitTest"; + } + + public void before() + { + m_xMSF = (XMultiServiceFactory)param.getMSF(); + if ( m_xMSF == null ) + { + failed( "Can't create service factory!" ); + return; + } + + try { + Object oStorageFactory = m_xMSF.createInstance( "com.sun.star.embed.StorageFactory" ); + m_xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, + oStorageFactory ); + } + catch( Exception e ) + { + failed( "Can't create storage factory!" ); + return; + } + + if ( m_xStorageFactory == null ) + { + failed( "Can't create service factory!" ); + return; + } + } + + public void ExecuteTest01() + { + StorageTest aTest = new Test01( m_xMSF, m_xStorageFactory, log ); + assure( "Test01 failed!", aTest.test() ); + } + + public void ExecuteTest02() + { + StorageTest aTest = new Test02( m_xMSF, m_xStorageFactory, log ); + assure( "Test02 failed!", aTest.test() ); + } + + public void ExecuteTest03() + { + StorageTest aTest = new Test03( m_xMSF, m_xStorageFactory, log ); + assure( "Test03 failed!", aTest.test() ); + } + + public void ExecuteTest04() + { + StorageTest aTest = new Test04( m_xMSF, m_xStorageFactory, log ); + assure( "Test04 failed!", aTest.test() ); + } + + public void ExecuteTest05() + { + StorageTest aTest = new Test05( m_xMSF, m_xStorageFactory, log ); + assure( "Test05 failed!", aTest.test() ); + } + + public void ExecuteTest06() + { + StorageTest aTest = new Test06( m_xMSF, m_xStorageFactory, log ); + assure( "Test06 failed!", aTest.test() ); + } + + public void ExecuteTest07() + { + StorageTest aTest = new Test07( m_xMSF, m_xStorageFactory, log ); + assure( "Test07 failed!", aTest.test() ); + } + + public void ExecuteTest08() + { + StorageTest aTest = new Test08( m_xMSF, m_xStorageFactory, log ); + assure( "Test08 failed!", aTest.test() ); + } +} + diff --git a/package/qa/ofopxmlstorages/Test01.java b/package/qa/ofopxmlstorages/Test01.java new file mode 100644 index 000000000..dd8665bc5 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test01.java @@ -0,0 +1,218 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test01 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test01( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test01: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + StringPair[][] aRelations2 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + try + { + String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); + if ( sTempFileURL == null || sTempFileURL == "" ) + { + m_aTestHelper.Error( "No valid temporary file was created!" ); + return false; + } + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // create temporary storage based on a previously created temporary file + XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xTempFileStorage == null ) + { + m_aTestHelper.Error( "Can't create storage based on temporary file!" ); + return false; + } + + // copy xTempStorage to xTempFileStorage + // xTempFileStorage will be automatically committed + if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) ) + return false; + + + // now check all the written and copied information + + + // the temporary file must not be locked any more after storage disposing + XStorage xResultStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // open existing substorage + XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResultSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, + "SubStream1", + "MediaType1", + pBytes1, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, + "SubStream2", + "MediaType2", + pBytes2, + aRelations2 ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test02.java b/package/qa/ofopxmlstorages/Test02.java new file mode 100644 index 000000000..a39e78ca4 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test02.java @@ -0,0 +1,182 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.io.XStream; +import com.sun.star.io.XInputStream; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test02 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test02: " ); + } + + public boolean test() + { + try + { + StringPair[][] aRelations = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + + XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); + if ( xTempFileStream == null ) + return false; + + // create storage based on the temporary stream + XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory, + xTempFileStream, + ElementModes.WRITE ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations ) ) + return false; + + // commit substorage first + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + // commit the root storage so the contents must be stored now + if ( !m_aTestHelper.commitStorage( xTempStorage ) ) + return false; + + // dispose used storage to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) + return false; + + + + // now check all the written information + + + // close the output part of the temporary stream + // the output part must present since we already wrote to the stream + if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) + return false; + + XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); + if ( xTempInStream == null ) + return false; + + + // open input stream + XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, xTempInStream ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't open storage based on input stream!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, true, ElementModes.READ, aRelations ) ) + return false; + + // open existing substorage + XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResultSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, aRelations ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test03.java b/package/qa/ofopxmlstorages/Test03.java new file mode 100644 index 000000000..d2f7bfa5b --- /dev/null +++ b/package/qa/ofopxmlstorages/Test03.java @@ -0,0 +1,251 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.embed.*; +import com.sun.star.container.XNameAccess; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test03 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test03( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test03: " ); + } + + public boolean test() + { + try + { + StringPair[][] aRelations = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations ) ) + return false; + + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) + return false; + + + // check storage hierarchy tree + + + // check that isStorageElement() and isStreamElement reacts to nonexistent object correctly + try { + xTempStorage.isStorageElement( "does not exist" ); + m_aTestHelper.Error( "Nonexistent element doesn't detected by isStorageElement() call!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by isStorageElement() call: " + e ); + return false; + } + + try { + xTempStorage.isStreamElement( "does not exist" ); + m_aTestHelper.Error( "Nonexistent element doesn't detected by isStreamElement() call!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by isStreamElement() call: " + e ); + return false; + } + + XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage ); + if ( xRootNameAccess == null ) + { + m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" ); + return false; + } + + try { + if ( !xTempStorage.isStorageElement( "SubStorage1" ) || xTempStorage.isStreamElement( "SubStorage1" ) ) + { + m_aTestHelper.Error( "Child 'SubStorage1' can not be detected as storage!" ); + return false; + } + + if ( xTempStorage.isStorageElement( "SubStream1" ) || !xTempStorage.isStreamElement( "SubStream1" ) ) + { + m_aTestHelper.Error( "Child 'SubStream1' can not be detected as stream!" ); + return false; + } + } + catch( Exception e ) + { + m_aTestHelper.Error( "Child's type can not be detected, exception: " + e ); + return false; + } + + + // check that root storage contents are represented correctly + String sRootCont[] = xRootNameAccess.getElementNames(); + + if ( sRootCont.length != 2 ) + { + m_aTestHelper.Error( "Root storage contains wrong amount of children!" ); + return false; + } + + if ( !( sRootCont[0].equals( "SubStorage1" ) && sRootCont[1].equals( "SubStream1" ) + || sRootCont[0].equals( "SubStream1" ) && sRootCont[1].equals( "SubStorage1" ) ) + || !( xRootNameAccess.hasByName( "SubStream1" ) && xRootNameAccess.hasByName( "SubStorage1" ) ) ) + { + m_aTestHelper.Error( "Root storage contains wrong list of children!" ); + return false; + } + + // get storage through XNameAccess + XStorage xResultSubStorage = getStorageFromNameAccess( xRootNameAccess, "SubStorage1" ); + if ( xResultSubStorage == null ) + return false; + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations ) ) + return false; + + XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage ); + if ( xChildAccess == null ) + { + m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" ); + return false; + } + + if ( !xChildAccess.hasByName( "SubStream2" ) + || !xResultSubStorage.isStreamElement( "SubStream2" ) + || xResultSubStorage.isStorageElement( "SubStream2" ) ) + { + m_aTestHelper.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" ); + return false; + } + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + + public XStorage getStorageFromNameAccess( XNameAccess xAccess, String sName ) + { + try + { + Object oStorage = xAccess.getByName( sName ); + XStorage xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStorage ); + + if ( xResult != null ) + return xResult; + else + m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess!" ); + } + catch( Exception e ) + { + m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess, exception: " + e ); + } + + return null; + } + +} + diff --git a/package/qa/ofopxmlstorages/Test04.java b/package/qa/ofopxmlstorages/Test04.java new file mode 100644 index 000000000..7bc793a60 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test04.java @@ -0,0 +1,326 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.DisposedException; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.container.XNameAccess; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test04 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test04( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test04: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + StringPair[][] aRelations2 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + try + { + String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); + if ( sTempFileURL == null || sTempFileURL == "" ) + { + m_aTestHelper.Error( "No valid temporary file was created!" ); + return false; + } + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open substorages and create streams there + + // first substorage of the root storage + XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage1 == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + // second substorage of the root storage + XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage2", + ElementModes.WRITE ); + if ( xTempSubStorage2 == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage2, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1, + false, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage2, + false, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + // create temporary storage based on a previously created temporary file + XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xTempFileStorage == null ) + { + m_aTestHelper.Error( "Can't create storage based on temporary file!" ); + return false; + } + + if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempFileStorage ) ) + return false; + + // if storage is not committed before disposing all the changes will be lost + if ( !m_aTestHelper.commitStorage( xTempSubStorage2 ) ) + return false; + + // a storage must be disposed before moving/removing otherwise the access will be denied + if ( !m_aTestHelper.disposeStorage( xTempSubStorage2 ) ) + return false; + + if ( !m_aTestHelper.moveElementTo( xTempStorage, "SubStorage2", xTempFileStorage ) ) + return false; + + // SubStorage2 must be removed and disposed now + try + { + xTempSubStorage2.isStreamElement( "SubStream2" ); + m_aTestHelper.Error( "SubStorage2 must be disposed already!" ); + return false; + } + catch( com.sun.star.lang.DisposedException de ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e ); + return false; + } + + if ( !m_aTestHelper.copyElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) ) + return false; + + if ( !m_aTestHelper.renameElement( xTempFileStorage, "SubStream1", "SubStream1_copy" ) ) + return false; + + if ( !m_aTestHelper.moveElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) ) + return false; + + if ( !m_aTestHelper.commitStorage( xTempFileStorage ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) ) + return false; + + + // now check all the written and copied information + + + // the temporary file must not be locked any more after storage disposing + XStorage xResStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + + if ( xResStorage == null ) + { + m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); + return false; + } + + // open and check SubStorage1 + XStorage xResSubStorage1 = m_aTestHelper.openSubStorage( xResStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResSubStorage1 == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResSubStorage1, + false, + ElementModes.READ, + aRelations2 ) ) + return false; + + + // open and check SubStorage2 + XStorage xResSubStorage2 = m_aTestHelper.openSubStorage( xResStorage, + "SubStorage2", + ElementModes.READ ); + if ( xResSubStorage2 == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResSubStorage2, + false, + ElementModes.READ, + aRelations2 ) ) + return false; + + + // check all the result streams + + if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1", "MediaType1", pBytes1, aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1_copy", "MediaType1", pBytes1, aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResSubStorage1, "SubStream1", "MediaType1", pBytes1, aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResSubStorage2, "SubStream2", "MediaType2", pBytes2, aRelations2 ) ) + return false; + + // the storage must be disposed before removing + if ( !m_aTestHelper.disposeStorage( xResSubStorage2 ) ) + return false; + + // remove element and check that it was removed completely + if ( !m_aTestHelper.removeElement( xResStorage, "SubStorage2" ) ) + return false; + + try + { + XNameAccess xResAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResStorage ); + if ( xResAccess.hasByName( "SubStorage2" ) ) + m_aTestHelper.Error( "SubStorage2 must be removed already!" ); + } + catch( Exception e ) + { + m_aTestHelper.Error( "Can't get access to root storage, exception: " + e ); + return false; + } + + try + { + xResSubStorage2.isStreamElement( "SubStream2" ); + + m_aTestHelper.Error( "SubStorage2 must be disposed already!" ); + return false; + } + catch( com.sun.star.lang.DisposedException de ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e ); + return false; + } + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xResStorage ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test05.java b/package/qa/ofopxmlstorages/Test05.java new file mode 100644 index 000000000..1ed0ba402 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test05.java @@ -0,0 +1,332 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.io.XStream; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test05 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test05( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test05: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + StringPair[][] aRelations2 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + try + { + String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); + if ( sTempFileURL == null || sTempFileURL == "" ) + { + m_aTestHelper.Error( "No valid temporary file was created!" ); + return false; + } + + // create temporary storage based on a previously created temporary file + XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xTempFileStorage == null ) + { + m_aTestHelper.Error( "Can't create storage based on temporary file!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempFileStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + // open a new substorage + XStorage xSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, + "SubSubStorage1", + ElementModes.WRITE ); + if ( xSubSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage, + true, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xSubSubStorage, + false, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + + // commit all the storages + if ( !m_aTestHelper.commitStorage( xSubSubStorage ) ) + return false; + + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + if ( !m_aTestHelper.commitStorage( xTempFileStorage ) ) + return false; + + // try to open an opened substorage, open call must fail + if ( !m_aTestHelper.cantOpenStorage( xTempFileStorage, "SubStorage1" ) ) + return false; + + + // reopen created streams + XStream xSubStream1 = m_aTestHelper.OpenStream( xSubSubStorage, + "SubStream1", + ElementModes.WRITE | ElementModes.NOCREATE ); + XStream xSubStream2 = m_aTestHelper.OpenStream( xSubSubStorage, + "SubStream2", + ElementModes.READ | ElementModes.NOCREATE ); + if ( xSubStream1 == null || xSubStream2 == null ) + return false; + + // it should be possible to have more than one copy of stream for reading + XStream xSubStream2clone = m_aTestHelper.OpenStream( xSubSubStorage, + "SubStream2", + ElementModes.READ | ElementModes.NOCREATE ); + if ( xSubStream2 == null ) + return false; + + + // so now the first stream can not be open neither for reading nor for writing + if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.WRITE ) + || !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.READ ) ) + return false; + + // the second stream can not be open for writing + if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream2", ElementModes.WRITE ) ) + return false; + + + // dispose xTestSubStorage, all the subtree must be disposed + if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) + return false; + + // check that subtree was disposed correctly + try + { + xSubSubStorage.isStreamElement( "SubStream1" ); + m_aTestHelper.Error( "Substorage was not disposed!" ); + return false; + } + catch ( com.sun.star.lang.DisposedException de ) + {} + catch ( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by disposed storage: " + e ); + return false; + } + + try + { + xSubStream1.getInputStream(); + m_aTestHelper.Error( "Writeable substream was not disposed!" ); + return false; + } + catch ( com.sun.star.lang.DisposedException de ) + {} + catch ( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e ); + return false; + } + + try + { + xSubStream2.getInputStream(); + m_aTestHelper.Error( "Readonly substream was not disposed!" ); + return false; + } + catch ( com.sun.star.lang.DisposedException de ) + {} + catch ( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e ); + return false; + } + + + // dispose root storage + if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) ) + return false; + + + + // now check all the written and copied information + + + XStorage xResultStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.READ ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, + true, + ElementModes.READ, + aRelations2 ) ) + return false; + + // open existing substorage + XStorage xResSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResSubStorage, + false, + ElementModes.READ, + aRelations2 ) ) + return false; + + // open existing substorage + XStorage xResSubSubStorage = m_aTestHelper.openSubStorage( xResSubStorage, + "SubSubStorage1", + ElementModes.READ ); + if ( xResSubSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResSubSubStorage, + false, + ElementModes.READ, + aRelations2 ) ) + return false; + + // check substreams + if ( !m_aTestHelper.checkStream( xResSubSubStorage, + "SubStream1", + "MediaType1", + pBytes1, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResSubSubStorage, + "SubStream2", + "MediaType2", + pBytes2, + aRelations2 ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test06.java b/package/qa/ofopxmlstorages/Test06.java new file mode 100644 index 000000000..b0b6b7bcc --- /dev/null +++ b/package/qa/ofopxmlstorages/Test06.java @@ -0,0 +1,295 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.ElementExistException; + +import com.sun.star.embed.*; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test06 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test06: " ); + } + + public boolean test() + { + try + { + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + try + { + xTempStorage.copyToStorage( null ); + m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" ); + return false; + } + catch( com.sun.star.lang.IllegalArgumentException iae ) + {} + catch( com.sun.star.uno.Exception ue ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception because of illegal parameter : " + e ); + return false; + } + + // open new substorages + XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage2", + ElementModes.WRITE ); + if ( xTempSubStorage1 == null || xTempSubStorage2 == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + // in case stream is open for reading it must exist + try + { + xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ ); + m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" ); + return false; + } + catch( com.sun.star.uno.Exception ue ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e ); + return false; + } + + // in case a storage is open for reading it must exist + try + { + xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ ); + m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" ); + return false; + } + catch( com.sun.star.uno.Exception ue ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e ); + return false; + } + + // in case of removing nonexistent element an exception must be thrown + try + { + xTempSubStorage1.removeElement( "NonExistingElement" ); + m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of try to remove nonexistent element : " + e ); + return false; + } + + // in case of renaming of nonexistent element an exception must be thrown + try + { + xTempSubStorage1.renameElement( "NonExistingElement", "NewName" ); + m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of try to rename nonexistent element : " + e ); + return false; + } + + // in case of renaming to a name of existent element an exception must be thrown + try + { + xTempStorage.renameElement( "SubStorage1", "SubStorage2" ); + m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" ); + return false; + } + catch( com.sun.star.container.ElementExistException ee ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of try to rename to the name of existent element : " + e ); + return false; + } + + // in case of copying target storage must be provided + try + { + xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" ); + m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" ); + return false; + } + catch( com.sun.star.lang.IllegalArgumentException iae ) + {} + catch( com.sun.star.uno.Exception ue ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for copying : " + e ); + return false; + } + + // in case of moving target storage must be provided + try + { + xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" ); + m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" ); + return false; + } + catch( com.sun.star.lang.IllegalArgumentException iae ) + {} + catch( com.sun.star.uno.Exception ue ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for moving : " + e ); + return false; + } + + + // prepare target for further testings + + // create new temporary storage based on arbitrary medium + XStorage xTargetStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTargetStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTargetSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + // in case of copying of nonexistent element an exception must be thrown + try + { + xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" ); + m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexistent element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of copying of nonexistent element: " + e ); + return false; + } + + // in case of moving of nonexistent element an exception must be thrown + try + { + xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" ); + m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexistent element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case of moving of nonexistent element: " + e ); + return false; + } + + // in case target for copying already exists an exception must be thrown + try + { + xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); + m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" ); + return false; + } + catch( com.sun.star.container.ElementExistException ee ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case target for copying already exists: " + e ); + return false; + } + + // in case target for moving already exists an exception must be thrown + try + { + xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); + m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" ); + return false; + } + catch( com.sun.star.container.ElementExistException ee ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected exception in case target for moving already exists: " + e ); + return false; + } + + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test07.java b/package/qa/ofopxmlstorages/Test07.java new file mode 100644 index 000000000..54f9a80b2 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test07.java @@ -0,0 +1,276 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.container.XNameAccess; +import com.sun.star.io.XStream; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test07 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test07( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test07: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + StringPair[][] aRelations2 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + try + { + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream2", + "MediaType2", + true, + pBytes2, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + + // check cloning at current state + + + // the new storage still was not committed so the clone must be empty + XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" ); + + if ( xClonedSubStorage == null ) + { + m_aTestHelper.Error( "The result of clone is empty!" ); + return false; + } + + XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage ); + if ( xClonedNameAccess == null ) + { + m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, + true, + ElementModes.WRITE, + new StringPair[0][0] ) ) + return false; + + if ( xClonedNameAccess.hasElements() ) + { + m_aTestHelper.Error( "The new substorage still was not committed so it must be empty!" ); + return false; + } + + if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) ) + return false; + + xClonedSubStorage = null; + xClonedNameAccess = null; + + // the new stream was opened, written and closed, that means flashed + // so the clone must contain all the information + XStream xClonedSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "SubStream1" ); + if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream, + "SubStream1", + "MediaType1", + pBytes1, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) ) + return false; + + + // commit substorage and check cloning + + + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" ); + if ( xClonedSubStorage == null ) + { + m_aTestHelper.Error( "The result of clone is empty!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, + true, + ElementModes.WRITE, + aRelations2 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xClonedSubStorage, + "SubStream2", + "MediaType2", + pBytes2, + aRelations2 ) ) + return false; + + XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage ); + if ( xCloneOfRoot == null ) + { + m_aTestHelper.Error( "The result of root clone is empty!" ); + return false; + } + + XNameAccess xCloneOfRootNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xCloneOfRoot ); + if ( xCloneOfRootNA == null ) + { + m_aTestHelper.Error( "XNameAccess is not implemented by the root clone!" ); + return false; + } + + if ( xCloneOfRootNA.hasElements() ) + { + m_aTestHelper.Error( "The root storage still was not committed so it's clone must be empty!" ); + return false; + } + + if ( !m_aTestHelper.disposeStorage( xCloneOfRoot ) ) + return false; + + xCloneOfRoot = null; + + + // commit root storage and check cloning + + + if ( !m_aTestHelper.commitStorage( xTempStorage ) ) + return false; + + xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage ); + if ( xCloneOfRoot == null ) + { + m_aTestHelper.Error( "The result of root clone is empty!" ); + return false; + } + + XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ ); + if ( xSubStorageOfClone == null ) + { + m_aTestHelper.Error( "The result of root clone is wrong!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone, + false, + ElementModes.READ, + aRelations2 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xSubStorageOfClone, + "SubStream2", + "MediaType2", + pBytes2, + aRelations2 ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } +} + diff --git a/package/qa/ofopxmlstorages/Test08.java b/package/qa/ofopxmlstorages/Test08.java new file mode 100644 index 000000000..a2607141f --- /dev/null +++ b/package/qa/ofopxmlstorages/Test08.java @@ -0,0 +1,279 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.io.XStream; +import com.sun.star.io.XInputStream; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test08 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test08( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test08: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + try + { + XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); + if ( xTempFileStream == null ) + return false; + + // create storage based on the temporary stream + XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory, + xTempFileStream, + ElementModes.WRITE ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // commit substorage first + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + // commit the root storage so the contents must be stored now + if ( !m_aTestHelper.commitStorage( xTempStorage ) ) + return false; + + // dispose substorage + if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) + return false; + + + // check substorage + + + if ( !checkSubStorages( xTempStorage, pBytes1, aRelations1 ) ) + return false; + + // dispose used storage to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) + return false; + + + // now check all the written information with readwrite access + + + XStorage xResWriteStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory, + xTempFileStream, + ElementModes.WRITE ); + if ( xResWriteStorage == null ) + { + m_aTestHelper.Error( "Can't open storage based on input stream!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResWriteStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + if( !checkSubStorages( xResWriteStorage, pBytes1, aRelations1 ) ) + return false; + + // try to open for writing after opening for reading + XStorage xResWSubStorage = m_aTestHelper.openSubStorage( xResWriteStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xResWSubStorage == null ) + { + m_aTestHelper.Error( "Can't open substorage for writing after it was opened for reading!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResWSubStorage, + false, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResWSubStorage, + "SubStream1", + "MediaType1", + pBytes1, + aRelations1 ) ) + return false; + + // dispose used storage to free resources + if ( !m_aTestHelper.disposeStorage( xResWriteStorage ) ) + return false; + + + + // now check all the written information with readonly access + + + // close the output part of the temporary stream + // the output part must present since we already wrote to the stream + if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) + return false; + + XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); + if ( xTempInStream == null ) + return false; + + // open input stream + // since no mode is provided the result storage must be opened readonly + XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, + xTempInStream ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't open storage based on input stream!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, + true, + ElementModes.READ, + aRelations1 ) ) + return false; + + if( !checkSubStorages( xResultStorage, pBytes1, aRelations1 ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + + private boolean checkSubStorages( XStorage xStorage, byte[] pBytes1, StringPair[][] aRelations ) + { + XStorage xReadSubStorage1 = m_aTestHelper.openSubStorage( xStorage, + "SubStorage1", + ElementModes.READ ); + + XStorage xReadSubStorage2 = m_aTestHelper.openSubStorage( xStorage, + "SubStorage1", + ElementModes.READ ); + + if ( xReadSubStorage1 == null || xReadSubStorage2 == null ) + { + m_aTestHelper.Error( "Can't open substorage for reading!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage1, + false, + ElementModes.READ, + aRelations ) ) + return false; + + if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage2, + false, + ElementModes.READ, + aRelations ) ) + return false; + + if ( !m_aTestHelper.checkStream( xReadSubStorage1, + "SubStream1", + "MediaType1", + pBytes1, + aRelations ) ) + return false; + + if ( !m_aTestHelper.checkStream( xReadSubStorage2, + "SubStream1", + "MediaType1", + pBytes1, + aRelations ) ) + return false; + + if ( !m_aTestHelper.disposeStorage( xReadSubStorage1 ) ) + return false; + + if ( !m_aTestHelper.disposeStorage( xReadSubStorage2 ) ) + return false; + + return true; + } +} + diff --git a/package/qa/ofopxmlstorages/TestHelper.java b/package/qa/ofopxmlstorages/TestHelper.java new file mode 100644 index 000000000..b7f42ea7f --- /dev/null +++ b/package/qa/ofopxmlstorages/TestHelper.java @@ -0,0 +1,1111 @@ +/* + * 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.ofopxmlstorages; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.AnyConverter; + +import com.sun.star.lang.*; +import com.sun.star.embed.*; +import com.sun.star.packages.*; +import com.sun.star.io.*; +import com.sun.star.beans.*; + +import share.LogWriter; + +public class TestHelper { + + LogWriter m_aLogWriter; + String m_sTestPrefix; + + public TestHelper( LogWriter aLogWriter, String sTestPrefix ) + { + m_aLogWriter = aLogWriter; + m_sTestPrefix = sTestPrefix; + } + + public boolean WriteBytesToStream( XStream xStream, + String sStreamName, + String sMediaType, + boolean bCompressed, + byte[] pBytes, + StringPair[][] aRelations ) + { + // get output stream of substream + XOutputStream xOutput = xStream.getOutputStream(); + if ( xOutput == null ) + { + Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" ); + return false; + } + + // get XTruncate implementation from output stream + XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); + if ( xTruncate == null ) + { + Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); + return false; + } + + // write requested byte sequence + try + { + xTruncate.truncate(); + xOutput.writeBytes( pBytes ); + } + catch( Exception e ) + { + Error( "Can't write to stream '" + sStreamName + "', exception: " + e ); + return false; + } + + // get access to the XPropertySet interface + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); + if ( xPropSet == null ) + { + Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); + return false; + } + + // set properties to the stream + try + { + xPropSet.setPropertyValue( "MediaType", sMediaType ); + xPropSet.setPropertyValue( "Compressed", Boolean.valueOf( bCompressed ) ); + } + catch( Exception e ) + { + Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e ); + return false; + } + + // check size property of the stream + try + { + long nSize = AnyConverter.toLong( xPropSet.getPropertyValue( "Size" ) ); + if ( nSize != pBytes.length ) + { + Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" ); + return false; + } + } + catch( Exception e ) + { + Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e ); + return false; + } + + // get access to the relationship information + XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream ); + if ( xRelAccess == null ) + { + Error( "Can't get XRelationshipAccess implementation from substream '" + sStreamName + "'!" ); + return false; + } + + // set the relationship information + try + { + xRelAccess.insertRelationships( aRelations, false ); + } + catch( Exception e ) + { + Error( "Can't set relationships to substream '" + sStreamName + "', exception: " + e ); + return false; + } + + // free the stream resources, garbage collector may remove the object too late + if ( !disposeStream( xStream, sStreamName ) ) + return false; + + return true; + } + + public boolean WriteBytesToSubstream( XStorage xStorage, + String sStreamName, + String sMediaType, + boolean bCompressed, + byte[] pBytes, + StringPair[][] aRelations ) + { + // open substream element + XStream xSubStream = null; + try + { + Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); + xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + if ( xSubStream == null ) + { + Error( "Can't create substream '" + sStreamName + "'!" ); + return false; + } + } + catch( Exception e ) + { + Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); + return false; + } + + return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes, aRelations ); + } + + public boolean setStorageTypeAndCheckProps( XStorage xStorage, + boolean bIsRoot, + int nMode, + StringPair[][] aRelations ) + { + boolean bOk = false; + + // get access to the XPropertySet interface + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + if ( xPropSet != null ) + { + try + { + // get "IsRoot" and "OpenMode" properties and control there values + boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); + int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); + + bOk = true; + if ( bPropIsRoot != bIsRoot ) + { + Error( "'IsRoot' property contains wrong value!" ); + bOk = false; + } + + if ( ( bIsRoot + && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) ) + || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) + { + Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" ); + bOk = false; + } + } + catch( Exception e ) + { + Error( "Can't control properties of substorage, exception: " + e ); + } + } + else + { + Error( "Can't get XPropertySet implementation from storage!" ); + } + + // get access to the relationship information + XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage ); + + if ( xRelAccess == null ) + { + Error( "Can't get XRelationshipAccess implementation from the storage!" ); + return false; + } + + // set the relationship information + try + { + xRelAccess.insertRelationships( aRelations, false ); + } + catch( Exception e ) + { + Error( "Can't set relationships to the storage, exception: " + e ); + return false; + } + + + return bOk; + } + + public boolean checkRelations( StringPair[][] aStorRels, StringPair[][] aTestRels ) + { + if ( aStorRels.length != aTestRels.length ) + { + Error( "The provided relations sequence has different size than the storage's one!" ); + return false; + } + + for ( int nStorInd = 0; nStorInd < aStorRels.length; nStorInd++ ) + { + int nStorIDInd = -1; + for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ ) + { + if ( aStorRels[nStorInd][nStorTagInd].First.equals( "Id" ) ) + { + nStorIDInd = nStorTagInd; + break; + } + } + + if ( nStorIDInd == -1 ) + { + Error( "One of the storage relations entries has no ID!" ); + return false; + } + + for ( int nInd = 0; nInd < aTestRels.length; nInd++ ) + { + int nIDInd = -1; + for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ ) + { + if ( aTestRels[nInd][nTagInd].First.equals( "Id" ) ) + { + nIDInd = nTagInd; + break; + } + } + + if ( nIDInd == -1 ) + { + Error( "One of the test hardcoded entries has no ID, num = " + nInd + ", length = " + aTestRels[nInd].length + ", global length = " + aTestRels.length + "!" ); + return false; + } + + if ( aStorRels[nStorInd][nStorIDInd].Second.equals( aTestRels[nInd][nIDInd].Second ) ) + { + boolean[] pRelCheckMark = new boolean[ aTestRels[nInd].length ]; + for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ ) + { + pRelCheckMark[nCheckInd] = false; + } + + for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ ) + { + boolean bFound = false; + for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ ) + { + if ( aTestRels[nInd][nTagInd].First.equals( aStorRels[nStorInd][nStorTagInd].First ) ) + { + if ( !aTestRels[nInd][nTagInd].Second.equals( aStorRels[nStorInd][nStorTagInd].Second ) ) + { + Error( "Test rel. num. " + nInd + " has different tag \"" + aTestRels[nInd][nTagInd].First + "\" value!" ); + return false; + } + + bFound = true; + pRelCheckMark[nTagInd] = true; + break; + } + } + + if ( !bFound ) + { + Error( "Stor rel. num. " + nStorInd + " has unexpected tag \"" + aStorRels[nStorInd][nStorTagInd].First + "\", ID = \"" + aStorRels[nStorInd][nStorIDInd].Second + "\"!" ); + return false; + } + } + + for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ ) + { + if ( !pRelCheckMark[nCheckInd] && !aTestRels[nInd][nCheckInd].Second.equals( "" ) ) + { + Error( "Test rel. num. " + nInd + " has unexpected tag \"" + aTestRels[nInd][nCheckInd].First + "\" with nonempty value!" ); + return false; + } + } + + break; + } + } + } + + return true; + } + + public boolean checkStorageProperties( XStorage xStorage, + boolean bIsRoot, + int nMode, + StringPair[][] aRelations ) + { + boolean bOk = false; + + // get access to the XPropertySet interface + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + if ( xPropSet != null ) + { + try + { + // get "IsRoot" and "OpenMode" properties and control there values + boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); + int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); + + bOk = true; + if ( bPropIsRoot != bIsRoot ) + { + Error( "'IsRoot' property contains wrong value!" ); + bOk = false; + } + + if ( ( bIsRoot + && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) ) + || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) + { + Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" ); + bOk = false; + } + } + catch( Exception e ) + { + Error( "Can't get properties of substorage, exception: " + e ); + } + } + else + { + Error( "Can't get XPropertySet implementation from storage!" ); + } + + // get access to the relationship information + XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage ); + + if ( xRelAccess == null ) + { + Error( "Can't get XRelationshipAccess implementation from the checked storage!" ); + return false; + } + + // get the relationship information + StringPair[][] aStorRels; + try + { + aStorRels = xRelAccess.getAllRelationships(); + } + catch( Exception e ) + { + Error( "Can't get relationships of the checked storage, exception: " + e ); + return false; + } + + if ( !checkRelations( aStorRels, aRelations ) ) + { + Error( "StorageRelationsChecking has failed!" ); + return false; + } + + return bOk; + } + + public boolean InternalCheckStream( XStream xStream, + String sName, + String sMediaType, + byte[] pBytes, + StringPair[][] aRelations ) + { + // get input stream of substream + XInputStream xInput = xStream.getInputStream(); + if ( xInput == null ) + { + Error( "Can't get XInputStream implementation from substream '" + sName + "'!" ); + return false; + } + + byte pContents[][] = new byte[1][]; // ??? + + // read contents + try + { + xInput.readBytes( pContents, pBytes.length + 1 ); + } + catch( Exception e ) + { + Error( "Can't read from stream '" + sName + "', exception: " + e ); + return false; + } + + // check size of stream data + if ( pContents.length == 0 ) + { + Error( "SubStream '" + sName + "' reading produced disaster!" ); + return false; + } + + if ( pBytes.length != pContents[0].length ) + { + Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" ); + return false; + } + + // check stream data + for ( int ind = 0; ind < pBytes.length; ind++ ) + { + if ( pBytes[ind] != pContents[0][ind] ) + { + Error( "SubStream '" + sName + "' contains wrong data! ( byte num. " + + ind + " should be" + pBytes[ind] + " but it is " + pContents[0][ind] + ")" ); + return false; + } + } + + // check properties + boolean bOk = false; + + // get access to the XPropertySet interface + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); + if ( xPropSet != null ) + { + try + { + // get "MediaType" and "Size" properties and control there values + String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); + long nPropSize = AnyConverter.toLong( xPropSet.getPropertyValue( "Size" ) ); + + bOk = true; + if ( !sPropMediaType.equals( sMediaType ) ) + { + Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '" + + sMediaType + "', set: '" + sPropMediaType + "'!" ); + bOk = false; + } + + if ( nPropSize != pBytes.length ) + { + Error( "'Size' property contains wrong value for stream'" + sName + "'!" ); + bOk = false; + } + } + catch( Exception e ) + { + Error( "Can't get properties of substream '" + sName + "', exception: " + e ); + } + } + else + { + Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" ); + } + + + // get access to the relationship information + XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream ); + + if ( xRelAccess == null ) + { + Error( "Can't get XRelationshipAccess implementation from the stream\"" + sName + "\"!" ); + return false; + } + + // get the relationship information + StringPair[][] aStorRels; + try + { + aStorRels = xRelAccess.getAllRelationships(); + } + catch( Exception e ) + { + Error( "Can't get relationships of the substream '" + sName + "', exception: " + e ); + return false; + } + + if ( !checkRelations( aStorRels, aRelations ) ) + { + Error( "Stream '" + sName + "' RelationsChecking has failed!" ); + return false; + } + + return bOk; + } + + public boolean checkStream( XStorage xParentStorage, + String sName, + String sMediaType, + byte[] pBytes, + StringPair[][] aRelations ) + { + // open substream element first + XStream xSubStream = null; + try + { + Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ ); + xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + if ( xSubStream == null ) + { + Error( "Can't open substream '" + sName + "'!" ); + return false; + } + } + catch( Exception e ) + { + Error( "Can't open substream '" + sName + "', exception : " + e + "!" ); + return false; + } + + boolean bResult = InternalCheckStream( xSubStream, sName, sMediaType, pBytes, aRelations ); + + // free the stream resources, garbage collector may remove the object too late + if ( !disposeStream( xSubStream, sName ) ) + return false; + + return bResult; + } + + public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage ) + { + // copy xSourceStorage to xDestStorage + try + { + xSourceStorage.copyToStorage( xDestStorage ); + } + catch( Exception e ) + { + Error( "Storage copying failed, exception: " + e ); + return false; + } + + return true; + } + + public boolean commitStorage( XStorage xStorage ) + { + // XTransactedObject must be supported by storages + XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); + if ( xTransact == null ) + { + Error( "Storage doesn't implement transacted access!" ); + return false; + } + + try + { + xTransact.commit(); + } + catch( Exception e ) + { + Error( "Storage commit failed, exception:" + e ); + return false; + } + + return true; + } + + public boolean disposeStream( XStream xStream, String sStreamName ) + { + XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream ); + if ( xComponent == null ) + { + Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); + return false; + } + + try + { + xComponent.dispose(); + } + catch( Exception e ) + { + Error( "Substream '" + sStreamName + "' disposing throws exception: " + e ); + return false; + } + + return true; + } + + public boolean disposeStorage( XStorage xStorage ) + { + // dispose the storage + XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage ); + if ( xComponent == null ) + { + Error( "Can't retrieve XComponent implementation from storage!" ); + return false; + } + + try + { + xComponent.dispose(); + } + catch( Exception e ) + { + Error( "Storage disposing failed!" ); + return false; + } + + return true; + } + + public XInputStream getInputStream( XStream xStream ) + { + XInputStream xInTemp = null; + try + { + xInTemp = xStream.getInputStream(); + if ( xInTemp == null ) + Error( "Can't get the input part of a stream!" ); + } + catch ( Exception e ) + { + Error( "Can't get the input part of a stream, exception :" + e ); + } + + return xInTemp; + } + + public boolean closeOutput( XStream xStream ) + { + XOutputStream xOutTemp = null; + try + { + xOutTemp = xStream.getOutputStream(); + if ( xOutTemp == null ) + { + Error( "Can't get the output part of a stream!" ); + return false; + } + } + catch ( Exception e ) + { + Error( "Can't get the output part of a stream, exception :" + e ); + return false; + } + + try + { + xOutTemp.closeOutput(); + } + catch ( Exception e ) + { + Error( "Can't close output part of a stream, exception :" + e ); + return false; + } + + return true; + } + + public XStorage openSubStorage( XStorage xStorage, String sName, int nMode ) + { + // open existing substorage + try + { + Object oSubStorage = xStorage.openStorageElement( sName, nMode ); + XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage ); + return xSubStorage; + } + catch( Exception e ) + { + Error( "Can't open substorage '" + sName + "', exception: " + e ); + } + + return null; + } + + public XStream CreateTempFileStream( XMultiServiceFactory xMSF ) + { + // try to get temporary file representation + XStream xTempFileStream = null; + try + { + Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); + xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile ); + } + catch( Exception e ) + {} + + if ( xTempFileStream == null ) + Error( "Can't create temporary file!" ); + + return xTempFileStream; + } + + public String CreateTempFile( XMultiServiceFactory xMSF ) + { + String sResult = null; + + // try to get temporary file representation + XPropertySet xTempFileProps = null; + try + { + Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); + xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); + } + catch( Exception e ) + {} + + if ( xTempFileProps != null ) + { + try + { + xTempFileProps.setPropertyValue( "RemoveFile", Boolean.FALSE ); + sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) ); + } + catch( Exception e ) + { + Error( "Can't control TempFile properties, exception: " + e ); + } + } + else + { + Error( "Can't create temporary file representation!" ); + } + + // close temporary file explicitly + try + { + XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps ); + if ( xStream != null ) + { + XOutputStream xOut = xStream.getOutputStream(); + if ( xOut != null ) + xOut.closeOutput(); + + XInputStream xIn = xStream.getInputStream(); + if ( xIn != null ) + xIn.closeInput(); + } + else + Error( "Can't close TempFile!" ); + } + catch( Exception e ) + { + Error( "Can't close TempFile, exception: " + e ); + } + + return sResult; + } + + public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest ) + { + // copy element with name sName from xSource to xDest + try + { + xSource.copyElementTo( sName, xDest, sName ); + } + catch( Exception e ) + { + Error( "Element copying failed, exception: " + e ); + return false; + } + + return true; + } + + public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest, String sTargetName ) + { + // copy element with name sName from xSource to xDest + try + { + xSource.copyElementTo( sName, xDest, sTargetName ); + } + catch( Exception e ) + { + Error( "Element copying failed, exception: " + e ); + return false; + } + + return true; + } + + public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest ) + { + // move element with name sName from xSource to xDest + try + { + xSource.moveElementTo( sName, xDest, sName ); + } + catch( Exception e ) + { + Error( "Element moving failed, exception: " + e ); + return false; + } + + return true; + } + + public boolean renameElement( XStorage xStorage, String sOldName, String sNewName ) + { + // rename element with name sOldName to sNewName + try + { + xStorage.renameElement( sOldName, sNewName ); + } + catch( Exception e ) + { + Error( "Element renaming failed, exception: " + e ); + return false; + } + + return true; + } + + public boolean removeElement( XStorage xStorage, String sName ) + { + // remove element with name sName + try + { + xStorage.removeElement( sName ); + } + catch( Exception e ) + { + Error( "Element removing failed, exception: " + e ); + return false; + } + + return true; + } + + public XStream OpenStream( XStorage xStorage, + String sStreamName, + int nMode ) + { + // open substream element + XStream xSubStream = null; + try + { + Object oSubStream = xStorage.openStreamElement( sStreamName, nMode ); + xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + if ( xSubStream == null ) + Error( "Can't create substream '" + sStreamName + "'!" ); + } + catch( Exception e ) + { + Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); + } + + return xSubStream; + } + + public boolean cantOpenStorage( XStorage xStorage, String sName ) + { + // try to open an opened substorage, open call must fail + try + { + Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.READ ); + Error( "The trying to reopen opened substorage '" + sName + "' must fail!" ); + } + catch( Exception e ) + { + return true; + } + + return false; + } + + public boolean cantOpenStream( XStorage xStorage, String sName, int nMode ) + { + // try to open the substream with specified mode must fail + try + { + Object oDummyStream = xStorage.openStreamElement( sName, nMode ); + Error( "The trying to open substream '" + sName + "' must fail!" ); + } + catch( Exception e ) + { + return true; + } + + return false; + } + + public XStorage createStorageFromURL( + XSingleServiceFactory xFactory, + String aURL, + int nMode ) + { + XStorage xResult = null; + + try + { + PropertyValue[] aAddArgs = new PropertyValue[1]; + aAddArgs[0] = new PropertyValue(); + aAddArgs[0].Name = "StorageFormat"; + aAddArgs[0].Value = "OFOPXMLFormat"; + + Object pArgs[] = new Object[3]; + pArgs[0] = (Object) aURL; + pArgs[1] = Integer.valueOf( nMode ); + pArgs[2] = (Object) aAddArgs; + + Object oTempStorage = xFactory.createInstanceWithArguments( pArgs ); + xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + } + catch( Exception e ) + { + Error( "Can't create storage from URL, exception: " + e ); + return null; + } + + if ( xResult == null ) + Error( "Can't create storage from URL!" ); + + return xResult; + } + + public XStorage createStorageFromStream( + XSingleServiceFactory xFactory, + XStream xStream, + int nMode ) + { + XStorage xResult = null; + + try + { + PropertyValue[] aAddArgs = new PropertyValue[1]; + aAddArgs[0] = new PropertyValue(); + aAddArgs[0].Name = "StorageFormat"; + aAddArgs[0].Value = "OFOPXMLFormat"; + + Object pArgs[] = new Object[3]; + pArgs[0] = (Object) xStream; + pArgs[1] = Integer.valueOf( nMode ); + pArgs[2] = (Object) aAddArgs; + + Object oTempStorage = xFactory.createInstanceWithArguments( pArgs ); + xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + } + catch( Exception e ) + { + Error( "Can't create storage from stream, exception: " + e ); + return null; + } + + if ( xResult == null ) + Error( "Can't create storage from stream!" ); + + return xResult; + } + + public XStorage createStorageFromInputStream( + XSingleServiceFactory xFactory, + XInputStream xInStream ) + { + XStorage xResult = null; + + try + { + PropertyValue[] aAddArgs = new PropertyValue[1]; + aAddArgs[0] = new PropertyValue(); + aAddArgs[0].Name = "StorageFormat"; + aAddArgs[0].Value = "OFOPXMLFormat"; + + Object pArgs[] = new Object[3]; + pArgs[0] = (Object) xInStream; + pArgs[1] = Integer.valueOf( ElementModes.READ ); + pArgs[2] = (Object) aAddArgs; + + Object oTempStorage = xFactory.createInstanceWithArguments( pArgs ); + xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + } + catch( Exception e ) + { + Error( "Can't create storage from input stream, exception: " + e ); + return null; + } + + if ( xResult == null ) + Error( "Can't create storage from input stream!" ); + + return xResult; + } + + public XStorage createTempStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory ) + { + // create a temporary storage + XStorage xResult = null; + XStream xStream = CreateTempFileStream( xMSF ); + if ( xStream == null ) + { + Error( "Can't create temp file stream!" ); + return null; + } + + try + { + xResult = createStorageFromStream( xFactory, xStream, ElementModes.WRITE ); + } + catch( Exception e ) + { + Error( "Can't create temp storage, exception: " + e ); + } + + return xResult; + } + + public XStorage cloneStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage ) + { + // create a copy of a last committed version of specified storage + XStorage xResult = null; + try + { + xResult = createTempStorage( xMSF, xFactory ); + if ( xResult != null ) + xStorage.copyLastCommitTo( xResult ); + } + catch( Exception e ) + { + Error( "Can't clone storage, exception: " + e ); + return null; + } + + return xResult; + } + + public XStorage cloneSubStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage, String sName ) + { + // create a copy of a last committed version of specified substorage + XStorage xResult = null; + try + { + xResult = createTempStorage( xMSF, xFactory ); + if ( xResult != null ) + xStorage.copyStorageElementLastCommitTo( sName, xResult ); + } + catch( Exception e ) + { + Error( "Can't clone substorage '" + sName + "', exception: " + e ); + return null; + } + + return xResult; + } + + public XStream cloneSubStream( XStorage xStorage, String sName ) + { + // clone existing substream + try + { + XStream xStream = xStorage.cloneStreamElement( sName ); + return xStream; + } + catch( Exception e ) + { + Error( "Can't clone substream '" + sName + "', exception: " + e ); + } + + return null; + } + + public void Error( String sError ) + { + m_aLogWriter.println( m_sTestPrefix + "Error: " + sError ); + } + + public void Message( String sMessage ) + { + m_aLogWriter.println( m_sTestPrefix + sMessage ); + } + + public void PrintRelations( StringPair[][] aRels ) + { + m_aLogWriter.println( "========" ); + for ( int nInd1 = 0; nInd1 < aRels.length; nInd1++ ) + { + for ( int nInd2 = 0; nInd2 < aRels[nInd1].length; nInd2++ ) + { + m_aLogWriter.println( "\"" + aRels[nInd1][nInd2].First + "\" = \"" + aRels[nInd1][nInd2].Second + "\", " ); + } + m_aLogWriter.println( "========" ); + } + } +} + diff --git a/package/qa/ofopxmlstorages/makefile.mk b/package/qa/ofopxmlstorages/makefile.mk new file mode 100644 index 000000000..5cf93e98e --- /dev/null +++ b/package/qa/ofopxmlstorages/makefile.mk @@ -0,0 +1,82 @@ +# +# 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 . +# + +PRJ = ..$/.. +TARGET = StorageUnitTest +PRJNAME = package +PACKAGE = complex$/ofopxmlstorages + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar + +JAVAFILES =\ + StorageUnitTest.java\ + StorageTest.java\ + TestHelper.java\ + Test01.java\ + Test02.java\ + Test03.java\ + Test04.java\ + Test05.java\ + Test06.java\ + Test07.java\ + Test08.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice --accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +RUN: run + +run: + java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_TEST) + + |