bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i30677.java
blobfaee91afe5591722d572f078ab08ef275c7b57b7
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;
31 import com.sun.star.embed.*;
33 import share.LogWriter;
34 import complex.storages.TestHelper;
35 import complex.storages.StorageTest;
37 public class RegressionTest_i30677 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i30677( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i30677: " );
50 public boolean test()
52 try
54 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
55 if ( xTempFileStream == null )
56 return false;
58 // create storage based on the temporary stream
59 Object pArgs[] = new Object[2];
60 pArgs[0] = (Object) xTempFileStream;
61 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
63 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
64 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
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 // open a new subsubstorage
82 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
83 "SubSubStorage1",
84 ElementModes.WRITE );
85 if ( xTempSubSubStorage == null )
87 m_aTestHelper.Error( "Can't create substorage!" );
88 return false;
91 byte pBytes1[] = { 1, 1, 1, 1, 1 };
93 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
94 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes1 ) )
95 return false;
97 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
98 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
99 "MediaType2",
100 true,
101 ElementModes.WRITE ) )
102 return false;
104 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
105 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
106 "MediaType3",
107 false,
108 ElementModes.WRITE ) )
109 return false;
111 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
112 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
113 "MediaType4",
114 false,
115 ElementModes.WRITE ) )
116 return false;
119 // commit the storages
122 // commit lowlevel substorage first
123 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
124 return false;
126 // commit substorage
127 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
128 return false;
130 // commit substorage to let the renaming take place
131 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
132 return false;
135 // dispose the storages
138 // dispose lowerest substorage
139 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
140 return false;
142 // dispose substorage
143 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
144 return false;
146 // dispose the temporary storage
147 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
148 return false;
151 // reopen the storage and rewrite the stream
154 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
155 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
156 if ( xTempStorage == null )
158 m_aTestHelper.Error( "Can't create temporary storage representation!" );
159 return false;
162 // open the substorages
164 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
165 "SubStorage1",
166 ElementModes.WRITE );
167 if ( xTempSubStorage == null )
169 m_aTestHelper.Error( "Can't create substorage!" );
170 return false;
173 // open the lowlevel substorages
175 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
176 "SubSubStorage1",
177 ElementModes.WRITE );
178 if ( xTempSubSubStorage == null )
180 m_aTestHelper.Error( "Can't create substorage!" );
181 return false;
184 byte pBytes2[] = { 2, 2, 2, 2, 2 };
186 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
187 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) )
188 return false;
191 // commit the storages
194 // commit lowlevel substorage first
195 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
196 return false;
198 // commit substorage
199 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
200 return false;
202 // commit substorage to let the renaming take place
203 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
204 return false;
207 // dispose the storages
210 // dispose lowerest substorage
211 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
212 return false;
214 // dispose substorage
215 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
216 return false;
218 // dispose the temporary storage
219 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
220 return false;
223 // reopen the storages and check the contents
226 pArgs[1] = Integer.valueOf( ElementModes.READ );
227 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
228 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
229 if ( xTempStorage == null )
231 m_aTestHelper.Error( "Can't create temporary storage representation!" );
232 return false;
235 // open the substorages
237 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
238 "SubStorage1",
239 ElementModes.READ );
240 if ( xTempSubStorage == null )
242 m_aTestHelper.Error( "Can't create substorage!" );
243 return false;
246 // open the lowlevel substorages
248 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
249 "SubSubStorage1",
250 ElementModes.READ );
251 if ( xTempSubSubStorage == null )
253 m_aTestHelper.Error( "Can't create substorage!" );
254 return false;
257 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType4", false, ElementModes.READ ) )
258 return false;
260 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.READ ) )
261 return false;
263 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
264 return false;
266 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) )
267 return false;
269 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
270 // any resource, later the garbage collector will release the object and it must die by refcount
272 return true;
274 catch( Exception e )
276 m_aTestHelper.Error( "Exception: " + e );
277 return false;