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 Test17 implements StorageTest { 20 21 XMultiServiceFactory m_xMSF; 22 XSingleServiceFactory m_xStorageFactory; 23 TestHelper m_aTestHelper; 24 25 public Test17( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 26 { 27 m_xMSF = xMSF; 28 m_xStorageFactory = xStorageFactory; 29 m_aTestHelper = new TestHelper( aLogWriter, "Test17: " ); 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 54 byte pBytes1[] = { 1, 1, 1, 1, 1 }; 55 String pNames[] = { "SubStream1", "SubStream2", "SubStream3", "SubStream4", "SubStream5", "SubStream6", "SubStream7" }; 56 57 for ( int nInd = 0; nInd < pNames.length; nInd++ ) 58 { 59 // open a new substorage 60 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 61 "SubStorage1", 62 ElementModes.WRITE ); 63 if ( xTempSubStorage == null ) 64 { 65 m_aTestHelper.Error( "Can't create substorage!" ); 66 return false; 67 } 68 69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 70 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, pNames[nInd], "MediaType1", true, pBytes1 ) ) 71 return false; 72 73 // commit substorage first 74 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 75 return false; 76 77 // dispose used storage to free resources 78 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 79 return false; 80 } 81 82 // commit the root storage so the contents must be stored now 83 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 84 return false; 85 86 // dispose used storage to free resources 87 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 88 return false; 89 90 91 // ================================================ 92 // now check all the written information 93 // ================================================ 94 95 // close the output part of the temporary stream 96 // the output part must present since we already wrote to the stream 97 if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) 98 return false; 99 100 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); 101 if ( xTempInStream == null ) 102 return false; 103 104 105 // open input stream 106 // since no mode is provided the result storage must be opened readonly 107 Object pOneArg[] = new Object[1]; 108 pOneArg[0] = (Object) xTempInStream; 109 110 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg ); 111 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); 112 if ( xResultStorage == null ) 113 { 114 m_aTestHelper.Error( "Can't open storage based on input stream!" ); 115 return false; 116 } 117 118 // open existing substorage 119 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, 120 "SubStorage1", 121 ElementModes.READ ); 122 if ( xResultSubStorage == null ) 123 { 124 m_aTestHelper.Error( "Can't open existing substorage!" ); 125 return false; 126 } 127 128 for ( int nInd = 0; nInd < pNames.length; nInd++ ) 129 if ( !m_aTestHelper.checkStream( xResultSubStorage, pNames[nInd], "MediaType1", true, pBytes1 ) ) 130 return false; 131 132 return true; 133 } 134 catch( Exception e ) 135 { 136 m_aTestHelper.Error( "Exception: " + e ); 137 return false; 138 } 139 } 140 141 } 142 143