nss: upgrade to release 3.73
[LibreOffice.git] / package / qa / storages / Test13.java
blob649f9d88b4d7b20fe3f81c0f385806bf5028ff60
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;
29 import com.sun.star.embed.*;
31 import share.LogWriter;
32 import complex.storages.TestHelper;
33 import complex.storages.StorageTest;
35 public class Test13 implements StorageTest {
37 XMultiServiceFactory m_xMSF;
38 XSingleServiceFactory m_xStorageFactory;
39 TestHelper m_aTestHelper;
41 public Test13( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
43 m_xMSF = xMSF;
44 m_xStorageFactory = xStorageFactory;
45 m_aTestHelper = new TestHelper( aLogWriter, "Test13: " );
48 public boolean test()
50 String aStreamPrefix = "";
51 for ( int nInd = 0; nInd < 4; ++nInd, aStreamPrefix += "SubStorage" + nInd )
52 if ( !testForPath( aStreamPrefix ) )
53 return false;
55 return true;
58 public boolean testForPath( String aStreamPrefix )
60 try
62 String aSubStream1Path = aStreamPrefix + "SubStream1";
63 String aSubStream2Path = aStreamPrefix + "SubStream2";
64 String aSubStream3Path = aStreamPrefix + "SubStream3";
65 String aBigSubStream1Path = aStreamPrefix + "BigSubStream1";
66 String aBigSubStream2Path = aStreamPrefix + "BigSubStream2";
67 String aBigSubStream3Path = aStreamPrefix + "BigSubStream3";
69 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
70 if ( sTempFileURL == null || sTempFileURL == "" )
72 m_aTestHelper.Error( "No valid temporary file was created!" );
73 return false;
76 // create temporary storage based on a previously created temporary file
77 Object pArgs[] = new Object[2];
78 pArgs[0] = (Object) sTempFileURL;
79 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
81 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
82 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
83 if ( xTempFileStorage == null )
85 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
86 return false;
89 byte pBigBytes[] = new byte[33000];
90 for ( int nInd = 0; nInd < 33000; nInd++ )
91 pBigBytes[nInd] = (byte)( nInd % 128 );
93 byte pBytes1[] = { 1, 1, 1, 1, 1 };
95 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
96 // and commit
97 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, true ) )
98 return false;
99 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType1", true, pBigBytes, true ) )
100 return false;
102 byte pBytes2[] = { 2, 2, 2, 2, 2 };
104 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
105 // and commit
106 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, true ) )
107 return false;
108 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes, true ) )
109 return false;
111 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
112 // and don't commit
113 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, false ) )
114 return false;
115 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream3Path, "MediaType2", false, pBigBytes, false ) )
116 return false;
118 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
119 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
120 "MediaType3",
121 true,
122 ElementModes.WRITE ) )
123 return false;
125 // commit the root storage so the contents must be stored now
126 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
127 return false;
129 // dispose used storages to free resources
130 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
131 return false;
134 // now reopen the storage,
135 // check all the written and copied information
136 // and change it
139 // the temporary file must not be locked any more after storage disposing
140 oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
141 xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
142 if ( xTempFileStorage == null )
144 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
145 return false;
148 if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) )
149 return false;
151 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1 ) )
152 return false;
154 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType1", true, pBigBytes ) )
155 return false;
157 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2 ) )
158 return false;
160 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes ) )
161 return false;
163 if ( !m_aTestHelper.cantOpenStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ ) )
164 return false;
166 if ( !m_aTestHelper.cantOpenStreamH( xTempFileStorage, aBigSubStream3Path, ElementModes.READ ) )
167 return false;
169 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
170 // and commit
171 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, true ) )
172 return false;
173 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType3", true, pBigBytes, true ) )
174 return false;
177 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
178 // and don't commit
179 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, false ) )
180 return false;
181 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType3", true, pBigBytes, false ) )
182 return false;
184 // commit the root storage so the contents must be stored now
185 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
186 return false;
188 // dispose used storages to free resources
189 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
190 return false;
193 // now reopen the storage,
194 // check all the written information
197 // the temporary file must not be locked any more after storage disposing
198 pArgs[1] = Integer.valueOf( ElementModes.READ );
199 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
200 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
201 if ( xResultStorage == null )
203 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
204 return false;
207 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
208 return false;
210 if ( !m_aTestHelper.checkStreamH( xResultStorage, aSubStream1Path, "MediaType3", true, pBytes2 ) )
211 return false;
212 if ( !m_aTestHelper.checkStreamH( xResultStorage, aBigSubStream1Path, "MediaType3", true, pBigBytes ) )
213 return false;
215 // the following stream was not committed last time, so the last change must be lost
216 if ( !m_aTestHelper.checkStreamH( xResultStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes ) )
217 return false;
219 // dispose used storages to free resources
220 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
221 return false;
223 return true;
225 catch( Exception e )
227 m_aTestHelper.Error( "Exception: " + e );
228 return false;