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_114358 implements StorageTest { 20 21 XMultiServiceFactory m_xMSF; 22 XSingleServiceFactory m_xStorageFactory; 23 TestHelper m_aTestHelper; 24 25 public RegressionTest_114358( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 26 { 27 m_xMSF = xMSF; 28 m_xStorageFactory = xStorageFactory; 29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_114358: " ); 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 // commit substorage first 84 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 85 return false; 86 87 // commit the root storage so the contents must be stored now 88 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 89 return false; 90 91 // dispose substorage 92 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 93 return false; 94 95 // dispose the temporary storage 96 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 97 return false; 98 99 // ================================================ 100 // create a new storage based on the stream and change the substream 101 // as described in the bug description 102 // ================================================ 103 104 byte pBytes2[] = { 2, 2 }; 105 106 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 107 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 108 if ( xTempStorage == null ) 109 { 110 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 111 return false; 112 } 113 114 // open the substorage 115 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 116 "SubStorage1", 117 ElementModes.WRITE ); 118 if ( xTempSubStorage == null ) 119 { 120 m_aTestHelper.Error( "Can't create substorage!" ); 121 return false; 122 } 123 124 // open the substream, set new "MediaType" and "Compressed" properties to it, truncate and write new contents 125 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType4", true, pBytes2 ) ) 126 return false; 127 128 // commit substorage first 129 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 130 return false; 131 132 // commit the root storage so the contents must be stored now 133 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 134 return false; 135 136 // dispose substorage 137 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 138 return false; 139 140 // dispose the temporary storage 141 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 142 return false; 143 144 // ================================================ 145 // create a new readonly storage based on the stream and check the contents 146 // ================================================ 147 148 pArgs[1] = new Integer( ElementModes.READ ); 149 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 150 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 151 if ( xTempStorage == null ) 152 { 153 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 154 return false; 155 } 156 157 // open the substorage 158 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 159 "SubStorage1", 160 ElementModes.READ ); 161 if ( xTempSubStorage == null ) 162 { 163 m_aTestHelper.Error( "Can't create substorage!" ); 164 return false; 165 } 166 167 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) ) 168 return false; 169 170 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.READ ) ) 171 return false; 172 173 // the MediaType and the contents must be up to date 174 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType4", true, pBytes2 ) ) 175 return false; 176 177 // dispose used storage to free resources 178 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 179 return false; 180 181 return true; 182 } 183 catch( Exception e ) 184 { 185 m_aTestHelper.Error( "Exception: " + e ); 186 return false; 187 } 188 } 189 } 190 191