diff options
author | Oliver Bolte <obo@openoffice.org> | 2006-10-13 10:44:52 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2006-10-13 10:44:52 +0000 |
commit | 632f4e2cac7a29a4584c975cffb70c2e9b37b1f9 (patch) | |
tree | 2cc3e13f48b8df77d04d549b6a137d9fee3bcf82 /package/qa | |
parent | 9a98aa53f4eb66ed9abc2910efeb6d9413cd2d87 (diff) |
INTEGRATION: CWS opofxmlstorage (1.1.2); FILE ADDED
2006/04/21 11:38:11 mav 1.1.2.1: #i64612# test OFOPXML storage
Diffstat (limited to 'package/qa')
-rw-r--r-- | package/qa/ofopxmlstorages/Test04.java | 308 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test05.java | 314 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test06.java | 277 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test07.java | 258 |
4 files changed, 1157 insertions, 0 deletions
diff --git a/package/qa/ofopxmlstorages/Test04.java b/package/qa/ofopxmlstorages/Test04.java new file mode 100644 index 000000000000..9b5f8e52628e --- /dev/null +++ b/package/qa/ofopxmlstorages/Test04.java @@ -0,0 +1,308 @@ +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( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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 commited 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 completelly + 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 000000000000..90b093f372db --- /dev/null +++ b/package/qa/ofopxmlstorages/Test05.java @@ -0,0 +1,314 @@ +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( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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 then 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 000000000000..61969db88e12 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test06.java @@ -0,0 +1,277 @@ +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 excepion 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 excepion 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 excepion 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 excepion 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 excepion 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 excepion 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 excepion in case empty reference is provieded 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 excepion in case empty reference is provieded 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 nonexisting element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected excepion 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 nonexisting element!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + {} + catch( Exception e ) + { + m_aTestHelper.Error( "Unexpected excepion 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 excepion 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 excepion 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 000000000000..2f60a8c61201 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test07.java @@ -0,0 +1,258 @@ +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( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), 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 commited 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 commited 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 commited 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; + } + } +} + |