fix toolbar import
[ooovba.git] / package / qa / storages / Test12.java
blob46fca01fcb33d75e7c122e06f7b5dff52fa063fc
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;
10 import com.sun.star.io.XStream;
11 import com.sun.star.io.XInputStream;
13 import com.sun.star.embed.*;
15 import share.LogWriter;
16 import complex.storages.TestHelper;
17 import complex.storages.StorageTest;
19 public class Test12 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public Test12( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "Test12: " );
32 public boolean test()
34 try
36 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
37 if ( xTempFileStream == null )
38 return false;
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 );
45 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
46 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
47 if ( xTempStorage == null )
49 m_aTestHelper.Error( "Can't create temporary storage representation!" );
50 return false;
53 // open a new substorage
54 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
55 "SubStorage1",
56 ElementModes.WRITE );
57 if ( xTempSubStorage == null )
59 m_aTestHelper.Error( "Can't create substorage!" );
60 return false;
63 byte pBytes1[] = { 1, 1, 1, 1, 1 };
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;
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;
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;
83 // commit substorage first
84 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
85 return false;
87 // commit the root storage so the contents must be stored now
88 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
89 return false;
91 // dispose substorage
92 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
93 return false;
95 // ================================================
96 // check substorage
97 // ================================================
99 if ( !checkSubStorages( xTempStorage, pBytes1 ) )
100 return false;
102 // dispose used storage to free resources
103 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
104 return false;
106 // ================================================
107 // now check all the written information with readwrite access
108 // ================================================
110 Object oResWriteStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
111 XStorage xResWriteStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResWriteStorage );
112 if ( xResWriteStorage == null )
114 m_aTestHelper.Error( "Can't open storage based on input stream!" );
115 return false;
118 if ( !m_aTestHelper.checkStorageProperties( xResWriteStorage, "MediaType2", true, ElementModes.WRITE ) )
119 return false;
121 if( !checkSubStorages( xResWriteStorage, pBytes1 ) )
122 return false;
124 // try to open for writing after opening for reading
125 XStorage xResWSubStorage = m_aTestHelper.openSubStorage( xResWriteStorage,
126 "SubStorage1",
127 ElementModes.WRITE );
128 if ( xResWSubStorage == null )
130 m_aTestHelper.Error( "Can't open substorage for writing after it was opened for reading!" );
131 return false;
134 if ( !m_aTestHelper.checkStorageProperties( xResWSubStorage, "MediaType3", false, ElementModes.WRITE ) )
135 return false;
137 if ( !m_aTestHelper.checkStream( xResWSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
138 return false;
140 // dispose used storage to free resources
141 if ( !m_aTestHelper.disposeStorage( xResWriteStorage ) )
142 return false;
145 // ================================================
146 // now check all the written information with readonly access
147 // ================================================
149 // close the output part of the temporary stream
150 // the output part must present since we already wrote to the stream
151 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
152 return false;
154 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
155 if ( xTempInStream == null )
156 return false;
158 // open input stream
159 // since no mode is provided the result storage must be opened readonly
160 Object pOneArg[] = new Object[1];
161 pOneArg[0] = (Object) xTempInStream;
163 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
164 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
165 if ( xResultStorage == null )
167 m_aTestHelper.Error( "Can't open storage based on input stream!" );
168 return false;
171 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType2", true, ElementModes.READ ) )
172 return false;
174 if( !checkSubStorages( xResultStorage, pBytes1 ) )
175 return false;
177 return true;
179 catch( Exception e )
181 m_aTestHelper.Error( "Exception: " + e );
182 return false;
186 private boolean checkSubStorages( XStorage xStorage, byte[] pBytes1 )
188 XStorage xReadSubStorage1 = m_aTestHelper.openSubStorage( xStorage,
189 "SubStorage1",
190 ElementModes.READ );
192 XStorage xReadSubStorage2 = m_aTestHelper.openSubStorage( xStorage,
193 "SubStorage1",
194 ElementModes.READ );
196 if ( xReadSubStorage1 == null || xReadSubStorage2 == null )
198 m_aTestHelper.Error( "Can't open substorage for reading!" );
199 return false;
202 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage1, "MediaType3", false, ElementModes.READ ) )
203 return false;
205 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage2, "MediaType3", false, ElementModes.READ ) )
206 return false;
208 if ( !m_aTestHelper.checkStream( xReadSubStorage1, "SubStream1", "MediaType1", true, pBytes1 ) )
209 return false;
211 if ( !m_aTestHelper.checkStream( xReadSubStorage2, "SubStream1", "MediaType1", true, pBytes1 ) )
212 return false;
214 if ( !m_aTestHelper.disposeStorage( xReadSubStorage1 ) )
215 return false;
217 if ( !m_aTestHelper.disposeStorage( xReadSubStorage2 ) )
218 return false;
220 return true;