nss: upgrade to release 3.73
[LibreOffice.git] / package / qa / storages / RegressionTest_i27773.java
blobf5e455192af25d7925250d3b6a5512dae2decf6d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.storages;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
25 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
28 import com.sun.star.io.XStream;
29 import com.sun.star.io.XInputStream;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.uno.AnyConverter;
33 import com.sun.star.embed.*;
35 import share.LogWriter;
36 import complex.storages.TestHelper;
37 import complex.storages.StorageTest;
40 // Tests also fix for i51352
43 public class RegressionTest_i27773 implements StorageTest {
45 XMultiServiceFactory m_xMSF;
46 XSingleServiceFactory m_xStorageFactory;
47 TestHelper m_aTestHelper;
49 public RegressionTest_i27773( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
51 m_xMSF = xMSF;
52 m_xStorageFactory = xStorageFactory;
53 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i27773: " );
56 public boolean test()
58 try
60 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
61 if ( xTempFileStream == null )
62 return false;
64 if ( true )
66 // for debugging proposes
68 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xTempFileStream );
69 if ( xPropSet != null )
71 try
73 String sTempURL = AnyConverter.toString( xPropSet.getPropertyValue( "Uri" ) );
74 // m_aTestHelper.Message( "URL: " + sTempURL );
75 xPropSet.setPropertyValue( "RemoveFile", Boolean.FALSE );
77 catch ( Exception e )
83 // create storage based on the temporary stream
84 Object pArgs[] = new Object[2];
85 pArgs[0] = (Object) xTempFileStream;
86 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
88 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
89 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
90 if ( xTempStorage == null )
92 m_aTestHelper.Error( "Can't create temporary storage representation!" );
93 return false;
96 // open a new substorage
97 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
98 "SubStorage1",
99 ElementModes.WRITE );
100 if ( xTempSubStorage == null )
102 m_aTestHelper.Error( "Can't create substorage!" );
103 return false;
106 // open an empty substorage
107 XStorage xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage,
108 "EmptySubStorage1",
109 ElementModes.WRITE );
110 if ( xEmptySubStorage == null )
112 m_aTestHelper.Error( "Can't create substorage!" );
113 return false;
116 // open an empty substorage
117 XStorage xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
118 "EmptySubSubStorage1",
119 ElementModes.WRITE );
120 if ( xEmptySubSubStorage == null )
122 m_aTestHelper.Error( "Can't create substorage!" );
123 return false;
127 byte pBytes1[] = { 1, 1, 1, 1, 1 };
129 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
130 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
131 return false;
133 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
134 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
135 "MediaType2",
136 true,
137 ElementModes.WRITE ) )
138 return false;
140 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
141 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubStorage,
142 "MediaType3",
143 false,
144 ElementModes.WRITE ) )
145 return false;
147 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
148 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
149 "MediaType4",
150 false,
151 ElementModes.WRITE ) )
152 return false;
154 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
155 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubSubStorage,
156 "MediaType5",
157 false,
158 ElementModes.WRITE ) )
159 return false;
162 // make a copy of substorage
164 if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempStorage, "SubStorage1_copy" ) )
165 return false;
167 if ( !m_aTestHelper.copyElementTo( xTempStorage, "EmptySubStorage1", xTempStorage, "EmptySubStorage1_copy" ) )
168 return false;
171 // copy all the changed and noncommitted substorages
172 // and dispose them
175 if ( !m_aTestHelper.commitStorage( xEmptySubSubStorage ) )
176 return false;
178 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
179 return false;
181 if ( !m_aTestHelper.commitStorage( xEmptySubStorage ) )
182 return false;
184 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
185 return false;
187 // dispose substorages
189 if ( !m_aTestHelper.disposeStorage( xEmptySubSubStorage ) )
190 return false;
192 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
193 return false;
195 if ( !m_aTestHelper.disposeStorage( xEmptySubStorage ) )
196 return false;
198 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
199 return false;
202 // reopen the storage in readonly mode and check contents
205 pArgs[1] = Integer.valueOf( ElementModes.READ );
207 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
208 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
209 if ( xTempStorage == null )
211 m_aTestHelper.Error( "Can't create temporary storage representation!" );
212 return false;
215 // open original substorage
216 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
217 "SubStorage1",
218 ElementModes.READ );
219 if ( xTempSubStorage == null )
221 m_aTestHelper.Error( "Can't create substorage!" );
222 return false;
225 // open copy of the original substorage
226 XStorage xTempSubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage,
227 "SubStorage1_copy",
228 ElementModes.READ );
229 if ( xTempSubStorage_copy == null )
231 m_aTestHelper.Error( "Can't create substorage!" );
232 return false;
235 // open empty substorage
236 xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage,
237 "EmptySubStorage1",
238 ElementModes.READ );
239 if ( xEmptySubStorage == null )
241 m_aTestHelper.Error( "Can't create substorage!" );
242 return false;
245 // open copy of empty substorage
246 XStorage xEmptySubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage,
247 "EmptySubStorage1_copy",
248 ElementModes.READ );
249 if ( xEmptySubStorage_copy == null )
251 m_aTestHelper.Error( "Can't create substorage!" );
252 return false;
255 // open an empty substorage of the substorage
256 xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
257 "EmptySubSubStorage1",
258 ElementModes.READ );
259 if ( xEmptySubSubStorage == null )
261 m_aTestHelper.Error( "Can't create substorage!" );
262 return false;
265 // open an empty substorage of the substorage copy
266 XStorage xEmptySubSubStorage_inCopy = m_aTestHelper.openSubStorage( xTempSubStorage_copy,
267 "EmptySubSubStorage1",
268 ElementModes.READ );
269 if ( xEmptySubSubStorage_inCopy == null )
271 m_aTestHelper.Error( "Can't create substorage!" );
272 return false;
276 // check contents
278 if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage, "MediaType5", false, ElementModes.READ ) )
279 return false;
281 if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage_inCopy, "MediaType5", false, ElementModes.READ ) )
282 return false;
284 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.READ ) )
285 return false;
287 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage_copy, "MediaType4", false, ElementModes.READ ) )
288 return false;
290 if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage, "MediaType3", false, ElementModes.READ ) )
291 return false;
293 if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage_copy, "MediaType3", false, ElementModes.READ ) )
294 return false;
296 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
297 return false;
299 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
300 return false;
302 if ( !m_aTestHelper.checkStream( xTempSubStorage_copy, "SubStream1", "MediaType1", true, pBytes1 ) )
303 return false;
305 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
306 // any resource, later the garbage collector will release the object and it must die by refcount
308 return true;
310 catch( Exception e )
312 m_aTestHelper.Error( "Exception: " + e );
313 return false;