merge the formfield patch from ooo-build
[ooovba.git] / package / qa / ofopxmlstorages / Test07.java
blob5499281c57e56ab4caf629cbeff0b03b94d9b97b
1 package complex.ofopxmlstorages;
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.*;
14 import com.sun.star.beans.StringPair;
16 import share.LogWriter;
17 import complex.ofopxmlstorages.TestHelper;
18 import complex.ofopxmlstorages.StorageTest;
20 public class Test07 implements StorageTest {
22 XMultiServiceFactory m_xMSF;
23 XSingleServiceFactory m_xStorageFactory;
24 TestHelper m_aTestHelper;
26 public Test07( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
28 m_xMSF = xMSF;
29 m_xStorageFactory = xStorageFactory;
30 m_aTestHelper = new TestHelper( aLogWriter, "Test07: " );
33 public boolean test()
35 StringPair[][] aRelations1 =
36 { { new StringPair( "Id", "Num1" ) },
37 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
38 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
39 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
41 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
42 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
45 StringPair[][] aRelations2 =
46 { { new StringPair( "Id", "Num1" ) },
47 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
48 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
49 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
50 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
51 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
52 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
55 try
57 // create temporary storage based on arbitrary medium
58 // after such a storage is closed it is lost
59 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
60 if ( xTempStorage == null )
62 m_aTestHelper.Error( "Can't create temporary storage representation!" );
63 return false;
66 byte pBytes1[] = { 1, 1, 1, 1, 1 };
68 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
69 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage,
70 "SubStream1",
71 "MediaType1",
72 true,
73 pBytes1,
74 aRelations1 ) )
75 return false;
78 // open a new substorage
79 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
80 "SubStorage1",
81 ElementModes.WRITE );
82 if ( xTempSubStorage == null )
84 m_aTestHelper.Error( "Can't create substorage!" );
85 return false;
88 byte pBytes2[] = { 2, 2, 2, 2, 2 };
90 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
91 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
92 "SubStream2",
93 "MediaType2",
94 true,
95 pBytes2,
96 aRelations2 ) )
97 return false;
99 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
100 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
101 true,
102 ElementModes.WRITE,
103 aRelations2 ) )
104 return false;
106 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
107 false,
108 ElementModes.WRITE,
109 aRelations2 ) )
110 return false;
112 // ==============================
113 // check cloning at current state
114 // ==============================
116 // the new storage still was not commited so the clone must be empty
117 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" );
119 if ( xClonedSubStorage == null )
121 m_aTestHelper.Error( "The result of clone is empty!" );
122 return false;
125 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
126 if ( xClonedNameAccess == null )
128 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
129 return false;
132 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage,
133 true,
134 ElementModes.WRITE,
135 new StringPair[0][0] ) )
136 return false;
138 if ( xClonedNameAccess.hasElements() )
140 m_aTestHelper.Error( "The new substorage still was not commited so it must be empty!" );
141 return false;
144 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
145 return false;
147 xClonedSubStorage = null;
148 xClonedNameAccess = null;
150 // the new stream was opened, written and closed, that means flashed
151 // so the clone must contain all the information
152 XStream xClonedSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "SubStream1" );
153 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream,
154 "SubStream1",
155 "MediaType1",
156 pBytes1,
157 aRelations1 ) )
158 return false;
160 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
161 return false;
163 // ==============================
164 // commit substorage and check cloning
165 // ==============================
167 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
168 return false;
170 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" );
171 if ( xClonedSubStorage == null )
173 m_aTestHelper.Error( "The result of clone is empty!" );
174 return false;
177 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage,
178 true,
179 ElementModes.WRITE,
180 aRelations2 ) )
181 return false;
183 if ( !m_aTestHelper.checkStream( xClonedSubStorage,
184 "SubStream2",
185 "MediaType2",
186 pBytes2,
187 aRelations2 ) )
188 return false;
190 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage );
191 if ( xCloneOfRoot == null )
193 m_aTestHelper.Error( "The result of root clone is empty!" );
194 return false;
197 XNameAccess xCloneOfRootNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xCloneOfRoot );
198 if ( xCloneOfRootNA == null )
200 m_aTestHelper.Error( "XNameAccess is not implemented by the root clone!" );
201 return false;
204 if ( xCloneOfRootNA.hasElements() )
206 m_aTestHelper.Error( "The root storage still was not commited so it's clone must be empty!" );
207 return false;
210 if ( !m_aTestHelper.disposeStorage( xCloneOfRoot ) )
211 return false;
213 xCloneOfRoot = null;
215 // ==============================
216 // commit root storage and check cloning
217 // ==============================
219 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
220 return false;
222 xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage );
223 if ( xCloneOfRoot == null )
225 m_aTestHelper.Error( "The result of root clone is empty!" );
226 return false;
229 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
230 if ( xSubStorageOfClone == null )
232 m_aTestHelper.Error( "The result of root clone is wrong!" );
233 return false;
236 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone,
237 false,
238 ElementModes.READ,
239 aRelations2 ) )
240 return false;
242 if ( !m_aTestHelper.checkStream( xSubStorageOfClone,
243 "SubStream2",
244 "MediaType2",
245 pBytes2,
246 aRelations2 ) )
247 return false;
249 return true;
251 catch( Exception e )
253 m_aTestHelper.Error( "Exception: " + e );
254 return false;