Update ooo320-m1
[ooovba.git] / package / qa / ofopxmlstorages / Test01.java
blob04510ea73e050f5fa8c709b25bd83f89d7178932
1 package complex.ofopxmlstorages;
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.*;
12 import com.sun.star.beans.StringPair;
14 import share.LogWriter;
15 import complex.ofopxmlstorages.TestHelper;
16 import complex.ofopxmlstorages.StorageTest;
18 public class Test01 implements StorageTest {
20 XMultiServiceFactory m_xMSF;
21 XSingleServiceFactory m_xStorageFactory;
22 TestHelper m_aTestHelper;
24 public Test01( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
26 m_xMSF = xMSF;
27 m_xStorageFactory = xStorageFactory;
28 m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
31 public boolean test()
33 StringPair[][] aRelations1 =
34 { { new StringPair( "Id", "Num1" ) },
35 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
36 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
37 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
38 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
39 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
43 StringPair[][] aRelations2 =
44 { { new StringPair( "Id", "Num1" ) },
45 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
46 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
47 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
48 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
49 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
50 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
53 try
55 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
56 if ( sTempFileURL == null || sTempFileURL == "" )
58 m_aTestHelper.Error( "No valid temporary file was created!" );
59 return false;
62 // create temporary storage based on arbitrary medium
63 // after such a storage is closed it is lost
64 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
65 if ( xTempStorage == null )
67 m_aTestHelper.Error( "Can't create temporary storage representation!" );
68 return false;
71 // open a new substorage
72 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
73 "SubStorage1",
74 ElementModes.WRITE );
75 if ( xTempSubStorage == null )
77 m_aTestHelper.Error( "Can't create substorage!" );
78 return false;
81 byte pBytes1[] = { 1, 1, 1, 1, 1 };
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
85 "SubStream1",
86 "MediaType1",
87 true,
88 pBytes1,
89 aRelations1 ) )
90 return false;
92 byte pBytes2[] = { 2, 2, 2, 2, 2 };
94 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
95 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
96 "SubStream2",
97 "MediaType2",
98 false,
99 pBytes2,
100 aRelations2 ) )
101 return false;
103 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
104 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
105 true,
106 ElementModes.WRITE,
107 aRelations1 ) )
108 return false;
110 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
111 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
112 false,
113 ElementModes.WRITE,
114 aRelations1 ) )
115 return false;
117 // create temporary storage based on a previously created temporary file
118 XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
119 sTempFileURL,
120 ElementModes.WRITE );
121 if ( xTempFileStorage == null )
123 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
124 return false;
127 // copy xTempStorage to xTempFileStorage
128 // xTempFileStorage will be automatically commited
129 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
130 return false;
132 // dispose used storages to free resources
133 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
134 return false;
136 // ================================================
137 // now check all the written and copied information
138 // ================================================
140 // the temporary file must not be locked any more after storage disposing
141 XStorage xResultStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
142 sTempFileURL,
143 ElementModes.WRITE );
144 if ( xResultStorage == null )
146 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
147 return false;
150 if ( !m_aTestHelper.checkStorageProperties( xResultStorage,
151 true,
152 ElementModes.WRITE,
153 aRelations1 ) )
154 return false;
156 // open existing substorage
157 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
158 "SubStorage1",
159 ElementModes.READ );
160 if ( xResultSubStorage == null )
162 m_aTestHelper.Error( "Can't open existing substorage!" );
163 return false;
166 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage,
167 false,
168 ElementModes.READ,
169 aRelations1 ) )
170 return false;
172 if ( !m_aTestHelper.checkStream( xResultSubStorage,
173 "SubStream1",
174 "MediaType1",
175 pBytes1,
176 aRelations1 ) )
177 return false;
179 if ( !m_aTestHelper.checkStream( xResultSubStorage,
180 "SubStream2",
181 "MediaType2",
182 pBytes2,
183 aRelations2 ) )
184 return false;
186 // dispose used storages to free resources
187 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
188 return false;
190 return true;
192 catch( Exception e )
194 m_aTestHelper.Error( "Exception: " + e );
195 return false;