merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test10.java
blob35c3e6ecbce6ab58c9c31f0cfad6208ea3d691da
1 package complex.storages;
3 import com.sun.star.lang.XMultiServiceFactory;
4 import com.sun.star.lang.XSingleServiceFactory;
6 import com.sun.star.bridge.XUnoUrlResolver;
7 import com.sun.star.uno.UnoRuntime;
8 import com.sun.star.uno.XInterface;
10 import com.sun.star.container.XNameAccess;
11 import com.sun.star.io.XStream;
13 import com.sun.star.embed.*;
15 import share.LogWriter;
16 import complex.storages.TestHelper;
17 import complex.storages.StorageTest;
19 public class Test10 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public Test10( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "Test10: " );
32 public boolean test()
34 try
36 // create temporary storage based on arbitrary medium
37 // after such a storage is closed it is lost
38 Object oTempStorage = m_xStorageFactory.createInstance();
39 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
40 if ( xTempStorage == null )
42 m_aTestHelper.Error( "Can't create temporary storage representation!" );
43 return false;
46 byte pBigBytes[] = new byte[33000];
47 for ( int nInd = 0; nInd < 33000; nInd++ )
48 pBigBytes[nInd] = (byte)( nInd % 128 );
50 byte pBytes1[] = { 1, 1, 1, 1, 1 };
52 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
53 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
54 return false;
56 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
57 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
58 return false;
61 // open a new substorage
62 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
63 "SubStorage1",
64 ElementModes.WRITE );
65 if ( xTempSubStorage == null )
67 m_aTestHelper.Error( "Can't create substorage!" );
68 return false;
71 byte pBytes2[] = { 2, 2, 2, 2, 2 };
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", true, pBytes2 ) )
75 return false;
77 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
78 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes ) )
79 return false;
81 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
82 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
83 "MediaType3",
84 true,
85 ElementModes.WRITE ) )
86 return false;
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
89 "MediaType4",
90 false,
91 ElementModes.WRITE ) )
92 return false;
94 // ==============================
95 // check cloning at current state
96 // ==============================
98 // the new storage still was not commited so the clone must be empty
99 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
101 if ( xClonedSubStorage == null )
103 m_aTestHelper.Error( "The result of clone is empty!" );
104 return false;
107 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
108 if ( xClonedNameAccess == null )
110 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
111 return false;
114 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "", true, ElementModes.WRITE ) )
115 return false;
117 if ( xClonedNameAccess.hasElements() )
119 m_aTestHelper.Error( "The new substorage still was not commited so it must be empty!" );
120 return false;
123 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
124 return false;
126 xClonedSubStorage = null;
127 xClonedNameAccess = null;
129 // the new stream was opened, written and closed, that means flashed
130 // so the clone must contain all the information
131 XStream xClonedSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "SubStream1" );
132 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream, "SubStream1", "MediaType1", true, pBytes1, true ) )
133 return false;
135 XStream xClonedBigSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "BigSubStream1" );
136 if ( !m_aTestHelper.InternalCheckStream( xClonedBigSubStream, "BigSubStream1", "MediaType1", true, pBigBytes, true ) )
137 return false;
139 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
140 return false;
142 if ( !m_aTestHelper.disposeStream( xClonedBigSubStream, "BigSubStream1" ) )
143 return false;
145 // ==============================
146 // commit substorage and check cloning
147 // ==============================
149 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
150 return false;
152 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
153 if ( xClonedSubStorage == null )
155 m_aTestHelper.Error( "The result of clone is empty!" );
156 return false;
159 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "MediaType4", true, ElementModes.WRITE ) )
160 return false;
162 if ( !m_aTestHelper.checkStream( xClonedSubStorage, "SubStream2", "MediaType2", true, pBytes2 ) )
163 return false;
165 if ( !m_aTestHelper.checkStream( xClonedSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes ) )
166 return false;
168 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
169 if ( xCloneOfRoot == null )
171 m_aTestHelper.Error( "The result of root clone is empty!" );
172 return false;
175 XNameAccess xCloneOfRootNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xCloneOfRoot );
176 if ( xCloneOfRootNA == null )
178 m_aTestHelper.Error( "XNameAccess is not implemented by the root clone!" );
179 return false;
182 if ( xCloneOfRootNA.hasElements() )
184 m_aTestHelper.Error( "The root storage still was not commited so it's clone must be empty!" );
185 return false;
188 if ( !m_aTestHelper.disposeStorage( xCloneOfRoot ) )
189 return false;
191 xCloneOfRoot = null;
193 // ==============================
194 // commit root storage and check cloning
195 // ==============================
197 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
198 return false;
200 xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
201 if ( xCloneOfRoot == null )
203 m_aTestHelper.Error( "The result of root clone is empty!" );
204 return false;
207 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
208 if ( xSubStorageOfClone == null )
210 m_aTestHelper.Error( "The result of root clone is wrong!" );
211 return false;
214 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone, "MediaType4", false, ElementModes.READ ) )
215 return false;
217 if ( !m_aTestHelper.checkStream( xSubStorageOfClone, "SubStream2", "MediaType2", true, pBytes2 ) )
218 return false;
220 if ( !m_aTestHelper.checkStream( xSubStorageOfClone, "BigSubStream2", "MediaType2", true, pBigBytes ) )
221 return false;
223 return true;
225 catch( Exception e )
227 m_aTestHelper.Error( "Exception: " + e );
228 return false;