fix toolbar import
[ooovba.git] / package / qa / storages / Test14.java
blobfdc3c7fb299b8c3ef3b9848a3b42475fed832ead
1 package complex.storages;
3 import com.sun.star.uno.XInterface;
4 import com.sun.star.lang.XMultiServiceFactory;
5 import com.sun.star.lang.XSingleServiceFactory;
7 import com.sun.star.bridge.XUnoUrlResolver;
8 import com.sun.star.uno.UnoRuntime;
9 import com.sun.star.uno.XInterface;
11 import com.sun.star.embed.*;
13 import share.LogWriter;
14 import complex.storages.TestHelper;
15 import complex.storages.StorageTest;
17 public class Test14 implements StorageTest {
19 XMultiServiceFactory m_xMSF;
20 XSingleServiceFactory m_xStorageFactory;
21 TestHelper m_aTestHelper;
23 public Test14( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test14: " );
30 public boolean test()
32 String aStreamPrefix = "";
33 for ( int nInd = 0; nInd < 4; ++nInd, aStreamPrefix += "SubStorage" + nInd )
34 if ( !testForPath( aStreamPrefix ) )
35 return false;
37 return true;
40 public boolean testForPath( String aStreamPrefix )
42 try
44 String aSubStream1Path = aStreamPrefix + "SubStream1";
45 String aSubStream2Path = aStreamPrefix + "SubStream2";
46 String aSubStream3Path = aStreamPrefix + "SubStream3";
48 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
49 if ( sTempFileURL == null || sTempFileURL == "" )
51 m_aTestHelper.Error( "No valid temporary file was created!" );
52 return false;
55 // create temporary storage based on a previously created temporary file
56 Object pArgs[] = new Object[2];
57 pArgs[0] = (Object) sTempFileURL;
58 pArgs[1] = new Integer( ElementModes.WRITE );
60 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
61 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
62 if ( xTempFileStorage == null )
64 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
65 return false;
68 byte pBytes1[] = { 1, 1, 1, 1, 1 };
69 String sPass1 = "12345";
71 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
72 // and commit
73 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, sPass1, true ) )
74 return false;
76 byte pBytes2[] = { 2, 2, 2, 2, 2 };
77 String sPass2 = "54321";
79 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
80 // and commit
81 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, sPass2, true ) )
82 return false;
84 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
85 // and don't commit
86 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, sPass2, false ) )
87 return false;
89 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
90 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
91 "MediaType3",
92 true,
93 ElementModes.WRITE ) )
94 return false;
96 // commit the root storage so the contents must be stored now
97 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
98 return false;
100 // dispose used storages to free resources
101 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
102 return false;
104 // ================================================
105 // now reopen the storage,
106 // check all the written and copied information
107 // and change it
108 // ================================================
110 // the temporary file must not be locked any more after storage disposing
111 oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
112 xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
113 if ( xTempFileStorage == null )
115 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
116 return false;
119 if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) )
120 return false;
122 if ( !m_aTestHelper.checkEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", pBytes1, sPass1 ) )
123 return false;
125 if ( !m_aTestHelper.checkEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", pBytes2, sPass2 ) )
126 return false;
128 if ( !m_aTestHelper.cantOpenEncrStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ, sPass2 ) )
129 return false;
131 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
132 // and commit
133 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, sPass1, true ) )
134 return false;
136 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
137 // and don't commit
138 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, sPass2, false ) )
139 return false;
141 // commit the root storage so the contents must be stored now
142 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
143 return false;
145 // dispose used storages to free resources
146 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
147 return false;
149 // ================================================
150 // now reopen the storage,
151 // check all the written information
152 // ================================================
154 // the temporary file must not be locked any more after storage disposing
155 pArgs[1] = new Integer( ElementModes.READ );
156 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
157 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
158 if ( xResultStorage == null )
160 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
161 return false;
164 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
165 return false;
167 if ( !m_aTestHelper.checkEncrStreamH( xResultStorage, aSubStream1Path, "MediaType3", pBytes2, sPass1 ) )
168 return false;
170 // the following stream was not commited last time, so the last change must be lost
171 if ( !m_aTestHelper.checkEncrStreamH( xResultStorage, aSubStream2Path, "MediaType2", pBytes2, sPass2 ) )
172 return false;
174 // dispose used storages to free resources
175 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
176 return false;
178 return true;
180 catch( Exception e )
182 m_aTestHelper.Error( "Exception: " + e );
183 return false;