1 package complex.storages; 2 3 import com.sun.star.uno.XInterface; 4 import com.sun.star.lang.XMultiServiceFactory; 5 import com.sun.star.lang.XSingleServiceFactory; 6 7 import com.sun.star.bridge.XUnoUrlResolver; 8 import com.sun.star.uno.UnoRuntime; 9 import com.sun.star.uno.XInterface; 10 import com.sun.star.io.XStream; 11 import com.sun.star.io.XInputStream; 12 13 import com.sun.star.embed.*; 14 15 import share.LogWriter; 16 import complex.storages.TestHelper; 17 import complex.storages.StorageTest; 18 19 public class RegressionTest_i26398 implements StorageTest { 20 21 XMultiServiceFactory m_xMSF; 22 XSingleServiceFactory m_xStorageFactory; 23 TestHelper m_aTestHelper; 24 25 public RegressionTest_i26398( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 26 { 27 m_xMSF = xMSF; 28 m_xStorageFactory = xStorageFactory; 29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i26398: " ); 30 } 31 32 public boolean test() 33 { 34 try 35 { 36 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 37 if ( xTempFileStream == null ) 38 return false; 39 40 // create storage based on the temporary stream 41 Object pArgs[] = new Object[2]; 42 pArgs[0] = (Object) xTempFileStream; 43 pArgs[1] = new Integer( ElementModes.WRITE ); 44 45 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 46 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 47 if ( xTempStorage == null ) 48 { 49 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 50 return false; 51 } 52 53 // open a new substorage 54 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 55 "SubStorage1", 56 ElementModes.WRITE ); 57 if ( xTempSubStorage == null ) 58 { 59 m_aTestHelper.Error( "Can't create substorage!" ); 60 return false; 61 } 62 63 byte pBytes1[] = { 1, 1, 1, 1, 1 }; 64 65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 66 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) ) 67 return false; 68 69 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 70 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, 71 "MediaType2", 72 true, 73 ElementModes.WRITE ) ) 74 return false; 75 76 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 77 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, 78 "MediaType3", 79 false, 80 ElementModes.WRITE ) ) 81 return false; 82 83 84 // ================================================ 85 // commit the substorage, dispose it, reopen readonly 86 // and dispose the reopened substorage 87 // ================================================ 88 89 // commit substorage 90 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 91 return false; 92 93 // dispose substorage 94 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 95 return false; 96 97 // open a new substorage 98 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 99 "SubStorage1", 100 ElementModes.READ ); 101 if ( xTempSubStorage == null ) 102 { 103 m_aTestHelper.Error( "Can't create substorage!" ); 104 return false; 105 } 106 107 // dispose substorage 108 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 109 return false; 110 111 // ================================================ 112 // reopen the substorage in readwrite mode and check contents 113 // ================================================ 114 115 // open a new substorage 116 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 117 "SubStorage1", 118 ElementModes.WRITE ); 119 if ( xTempSubStorage == null ) 120 { 121 m_aTestHelper.Error( "Can't create substorage!" ); 122 return false; 123 } 124 125 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.WRITE ) ) 126 return false; 127 128 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.WRITE ) ) 129 return false; 130 131 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) ) 132 return false; 133 134 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock 135 // any resource, later the garbage collector will release the object and it must die by refcount 136 137 return true; 138 } 139 catch( Exception e ) 140 { 141 m_aTestHelper.Error( "Exception: " + e ); 142 return false; 143 } 144 } 145 } 146 147