merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test11.java
blob5663c1e5774694842f6c8f1b0cead44972827454
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.container.XNameAccess;
12 import com.sun.star.io.XStream;
14 import com.sun.star.embed.*;
16 import share.LogWriter;
17 import complex.storages.TestHelper;
18 import complex.storages.StorageTest;
20 public class Test11 implements StorageTest {
22 XMultiServiceFactory m_xMSF;
23 XSingleServiceFactory m_xStorageFactory;
24 TestHelper m_aTestHelper;
26 public Test11( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
28 m_xMSF = xMSF;
29 m_xStorageFactory = xStorageFactory;
30 m_aTestHelper = new TestHelper( aLogWriter, "Test11: " );
33 public boolean test()
35 try
37 // create temporary storage based on arbitrary medium
38 // after such a storage is closed it is lost
39 Object oTempStorage = m_xStorageFactory.createInstance();
40 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
41 if ( xTempStorage == null )
43 m_aTestHelper.Error( "Can't create temporary storage representation!" );
44 return false;
47 byte pBigBytes[] = new byte[33000];
48 for ( int nInd = 0; nInd < 33000; nInd++ )
49 pBigBytes[nInd] = (byte)( nInd % 128 );
51 String sPass1 = "111111111";
52 byte pBytes1[] = { 1, 1, 1, 1, 1 };
54 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
55 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1, sPass1 ) )
56 return false;
58 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
59 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "BigSubStream1", "MediaType1", true, pBigBytes, sPass1 ) )
60 return false;
62 // open a new substorage
63 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
64 "SubStorage1",
65 ElementModes.WRITE );
66 if ( xTempSubStorage == null )
68 m_aTestHelper.Error( "Can't create substorage!" );
69 return false;
72 String sPass2 = "2222222222";
73 byte pBytes2[] = { 2, 2, 2, 2, 2 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", true, pBytes2, sPass2 ) )
77 return false;
79 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
80 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes, sPass2 ) )
81 return false;
83 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
85 "MediaType3",
86 true,
87 ElementModes.WRITE ) )
88 return false;
90 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
91 "MediaType4",
92 false,
93 ElementModes.WRITE ) )
94 return false;
96 // ==============================
97 // check cloning at current state
98 // ==============================
100 // the new storage still was not commited so the clone must be empty
101 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
103 if ( xClonedSubStorage == null )
105 m_aTestHelper.Error( "The result of clone is empty!" );
106 return false;
109 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
110 if ( xClonedNameAccess == null )
112 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
113 return false;
116 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "", true, ElementModes.WRITE ) )
117 return false;
119 if ( xClonedNameAccess.hasElements() )
121 m_aTestHelper.Error( "The new substorage still was not commited so it must be empty!" );
122 return false;
125 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
126 return false;
128 xClonedSubStorage = null;
129 xClonedNameAccess = null;
131 // the new stream was opened, written and closed, that means flashed
132 // so the clone must contain all the information
133 XStream xClonedSubStream = m_aTestHelper.cloneEncrSubStream( xTempStorage, "SubStream1", sPass1 );
134 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream, "SubStream1", "MediaType1", true, pBytes1, true ) )
135 return false;
137 XStream xClonedBigSubStream = m_aTestHelper.cloneEncrSubStream( xTempStorage, "BigSubStream1", sPass1 );
138 if ( !m_aTestHelper.InternalCheckStream( xClonedBigSubStream, "BigSubStream1", "MediaType1", true, pBigBytes, true ) )
139 return false;
141 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
142 return false;
144 if ( !m_aTestHelper.disposeStream( xClonedBigSubStream, "BigSubStream1" ) )
145 return false;
147 // ==============================
148 // commit substorage and check cloning
149 // ==============================
151 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
152 return false;
154 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
155 if ( xClonedSubStorage == null )
157 m_aTestHelper.Error( "The result of clone is empty!" );
158 return false;
161 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "MediaType4", true, ElementModes.WRITE ) )
162 return false;
164 if ( !m_aTestHelper.checkEncrStream( xClonedSubStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
165 return false;
167 if ( !m_aTestHelper.checkEncrStream( xClonedSubStorage, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
168 return false;
170 // ==============================
171 // commit the root storage and check cloning
172 // ==============================
174 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
175 return false;
177 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
178 if ( xCloneOfRoot == null )
180 m_aTestHelper.Error( "The result of root clone is empty!" );
181 return false;
184 if ( !m_aTestHelper.checkStorageProperties( xCloneOfRoot, "MediaType3", true, ElementModes.WRITE ) )
185 return false;
187 if ( !m_aTestHelper.checkEncrStream( xCloneOfRoot, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
188 return false;
190 if ( !m_aTestHelper.checkEncrStream( xCloneOfRoot, "BigSubStream1", "MediaType1", pBigBytes, sPass1 ) )
191 return false;
193 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
194 if ( xSubStorageOfClone == null )
196 m_aTestHelper.Error( "The result of root clone is wrong!" );
197 return false;
200 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone, "MediaType4", false, ElementModes.READ ) )
201 return false;
203 if ( !m_aTestHelper.checkEncrStream( xSubStorageOfClone, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
204 return false;
206 if ( !m_aTestHelper.checkEncrStream( xSubStorageOfClone, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
207 return false;
209 return true;
211 catch( Exception e )
213 m_aTestHelper.Error( "Exception: " + e );
214 return false;