bump product version to 4.1.6.2
[LibreOffice.git] / package / qa / storages / RegressionTest_i59886.java
blob0a951dcc147ee928ead9e2764122b2688090d5c8
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_i59886 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i59886( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i59886: " );
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] = new Integer( 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 byte pBytes[] = new byte[36000];
72 for ( int nInd = 0; nInd < 36000; nInd++ )
73 pBytes[nInd] = (byte)( nInd % 128 );
75 String sPass = "12345";
77 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
78 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes, sPass ) )
79 return false;
81 // open a new substorage
82 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
83 "SubStorage1",
84 ElementModes.WRITE );
85 if ( xTempSubStorage == null )
87 m_aTestHelper.Error( "Can't create substorage!" );
88 return false;
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) )
93 return false;
95 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
96 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
97 "MediaType3",
98 true,
99 ElementModes.WRITE ) )
100 return false;
102 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
103 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
104 "MediaType4",
105 false,
106 ElementModes.WRITE ) )
107 return false;
109 // commit substorage first
110 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
111 return false;
113 // commit the root storage so the contents must be stored now
114 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
115 return false;
117 // dispose used storage to free resources
118 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
119 return false;
121 // ================================================
122 // now reopen the storage, set the common storage key
123 // and copy the storage
124 // ================================================
126 Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
127 XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage );
128 if ( xStep2TempStorage == null )
130 m_aTestHelper.Error( "Can't create temporary storage representation!" );
131 return false;
135 XStorage xStep2TempSubStorage = m_aTestHelper.openSubStorage( xStep2TempStorage,
136 "SubStorage1",
137 ElementModes.WRITE );
138 if ( xStep2TempSubStorage == null )
140 m_aTestHelper.Error( "Can't create substorage!" );
141 return false;
144 // set the common storage password
145 XEncryptionProtectedSource xEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xStep2TempStorage );
146 if ( xEncr == null )
148 m_aTestHelper.Error( "The storage does not support encryption access!" );
149 return false;
153 xEncr.setEncryptionPassword( sPass );
155 catch( Exception e )
157 m_aTestHelper.Error( "Can not set the common storage password!" );
158 return false;
161 // open the stream for writing and read them so that the cache is created, but do not change
162 byte pDummyData[][] = new byte[1][3];
163 XStream xTempStream1 = m_aTestHelper.OpenStream( xStep2TempStorage, "SubStream1", ElementModes.WRITE );
164 XStream xTempStream2 = m_aTestHelper.OpenStream( xStep2TempSubStorage, "SubStream2", ElementModes.WRITE );
165 if ( xTempStream1 == null || xTempStream2 == null )
166 return false;
168 XInputStream xTempInStream1 = xTempStream1.getInputStream();
169 XInputStream xTempInStream2 = xTempStream2.getInputStream();
170 if ( xTempInStream1 == null || xTempInStream2 == null )
172 m_aTestHelper.Error( "No input stream is available!" );
173 return false;
176 xTempInStream1.readBytes( pDummyData, 3 );
177 xTempInStream2.readBytes( pDummyData, 3 );
180 // create temporary storage, it will be checked later
181 Object oTargetStorage = m_xStorageFactory.createInstance();
182 XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
183 if ( xTargetStorage == null )
185 m_aTestHelper.Error( "Can't create temporary storage representation!" );
186 return false;
189 // copy the current storage to the target
192 xStep2TempStorage.copyToStorage( xTargetStorage );
194 catch( Exception e )
196 m_aTestHelper.Error( "Can not copy the storage with common storage password!" );
197 return false;
200 // dispose used storage to free resources
201 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
202 return false;
204 // ================================================
205 // now check all the information in the copy
206 // ================================================
208 if ( !m_aTestHelper.checkStorageProperties( xTargetStorage, "MediaType3", true, ElementModes.WRITE ) )
209 return false;
211 // open existing substorage
212 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
213 "SubStorage1",
214 ElementModes.WRITE );
215 if ( xTargetSubStorage == null )
217 m_aTestHelper.Error( "Can't open existing substorage!" );
218 return false;
221 if ( !m_aTestHelper.checkStorageProperties( xTargetSubStorage, "MediaType4", false, ElementModes.WRITE ) )
222 return false;
224 // set the common storage password
225 XEncryptionProtectedSource xTargetEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTargetStorage );
226 if ( xTargetEncr == null )
228 m_aTestHelper.Error( "The storage does not support encryption access!" );
229 return false;
233 xTargetEncr.setEncryptionPassword( sPass );
235 catch( Exception e )
237 m_aTestHelper.Error( "Can not set the common storage password!" );
238 return false;
241 // check the streams
242 if ( !m_aTestHelper.checkStream( xTargetStorage, "SubStream1", "MediaType1", true, pBytes ) )
243 return false;
244 if ( !m_aTestHelper.checkStream( xTargetSubStorage, "SubStream2", "MediaType2", true, pBytes ) )
245 return false;
248 // dispose used storages to free resources
249 if ( !m_aTestHelper.disposeStorage( xTargetStorage ) )
250 return false;
252 return true;
254 catch( Exception e )
256 m_aTestHelper.Error( "Exception: " + e );
257 return false;