bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i49755.java
blobd2b32b8b931ebe9b24343424c9b43396727dd26a
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_i49755 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i49755( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i49755: " );
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 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
72 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
73 "MediaType1",
74 true,
75 ElementModes.WRITE ) )
76 return false;
79 byte pBytes[] = new byte[36000];
80 for ( int nInd = 0; nInd < 36000; nInd++ )
81 pBytes[nInd] = (byte)( nInd % 128 );
83 // open a new substorage
84 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
85 "SubStorage1",
86 ElementModes.WRITE );
87 if ( xTempSubStorage == null )
89 m_aTestHelper.Error( "Can't create substorage!" );
90 return false;
93 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
94 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
95 "MediaType2",
96 false,
97 ElementModes.WRITE ) )
98 return false;
100 // open a new substorage
101 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
102 "SubStorage2",
103 ElementModes.WRITE );
104 if ( xTempSubStorage == null )
106 m_aTestHelper.Error( "Can't create substorage!" );
107 return false;
110 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
111 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
112 "MediaType3",
113 false,
114 ElementModes.WRITE ) )
115 return false;
117 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
118 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) )
119 return false;
121 // open a new substorage
122 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
123 "SubStorage3",
124 ElementModes.WRITE );
125 if ( xTempSubStorage1 == null )
127 m_aTestHelper.Error( "Can't create substorage!" );
128 return false;
131 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
132 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1,
133 "MediaType5",
134 false,
135 ElementModes.WRITE ) )
136 return false;
138 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
139 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
140 return false;
143 // commit substorages first
144 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
145 return false;
147 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
148 return false;
150 if ( !m_aTestHelper.commitStorage( xTempSubStorage1 ) )
151 return false;
153 // commit the root storage so the contents must be stored now
154 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
155 return false;
157 // dispose used storage to free resources
158 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
159 return false;
162 // now change the contents of the second substorage
163 // without changing of the contents of the first substorage
166 Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
167 XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage );
168 if ( xStep2TempStorage == null )
170 m_aTestHelper.Error( "Can't create temporary storage representation!" );
171 return false;
174 XStorage xStep2TempSubStorage1 = m_aTestHelper.openSubStorage( xStep2TempStorage,
175 "SubStorage3",
176 ElementModes.WRITE );
177 if ( xStep2TempSubStorage1 == null )
179 m_aTestHelper.Error( "Can't create substorage!" );
180 return false;
183 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
184 if ( !m_aTestHelper.WriteBytesToSubstream( xStep2TempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
185 return false;
187 if ( !m_aTestHelper.commitStorage( xStep2TempSubStorage1 ) )
188 return false;
190 // commit the root storage so the contents must be stored now
191 if ( !m_aTestHelper.commitStorage( xStep2TempStorage ) )
192 return false;
194 // dispose used storage to free resources
195 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
196 return false;
200 // now check all the written information
201 // and the raw stream contents
204 // close the output part of the temporary stream
205 // the output part must present since we already wrote to the stream
206 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
207 return false;
209 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
210 if ( xTempInStream == null )
211 return false;
213 // open input stream
214 // since no mode is provided the result storage must be opened readonly
215 Object pOneArg[] = new Object[1];
216 pOneArg[0] = (Object) xTempInStream;
218 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
219 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
220 if ( xResultStorage == null )
222 m_aTestHelper.Error( "Can't open storage based on input stream!" );
223 return false;
226 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType1", true, ElementModes.READ ) )
227 return false;
229 // open existing substorage
230 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
231 "SubStorage1",
232 ElementModes.READ );
233 if ( xResultSubStorage == null )
235 m_aTestHelper.Error( "Can't open existing substorage!" );
236 return false;
239 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType2", false, ElementModes.READ ) )
240 return false;
242 // open existing substorage
243 XStorage xResultSubSubStorage = m_aTestHelper.openSubStorage( xResultSubStorage,
244 "SubStorage2",
245 ElementModes.READ );
246 if ( xResultSubSubStorage == null )
248 m_aTestHelper.Error( "Can't open existing substorage!" );
249 return false;
252 if ( !m_aTestHelper.checkStorageProperties( xResultSubSubStorage, "MediaType3", false, ElementModes.READ ) )
253 return false;
255 if ( !m_aTestHelper.checkStream( xResultSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) )
256 return false;
260 XStorage xResultSubStorage1 = m_aTestHelper.openSubStorage( xResultStorage,
261 "SubStorage3",
262 ElementModes.READ );
263 if ( xResultSubStorage1 == null )
265 m_aTestHelper.Error( "Can't open existing substorage!" );
266 return false;
269 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage1, "MediaType5", false, ElementModes.READ ) )
270 return false;
272 if ( !m_aTestHelper.checkStream( xResultSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
273 return false;
276 // dispose used storages to free resources
277 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
278 return false;
280 return true;
282 catch( Exception e )
284 m_aTestHelper.Error( "Exception: " + e );
285 return false;