bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / Test11.java
blob02320db81dd4028f6e0648e581745203f8434b46
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.container.XNameAccess;
30 import com.sun.star.io.XStream;
32 import com.sun.star.embed.*;
34 import share.LogWriter;
35 import complex.storages.TestHelper;
36 import complex.storages.StorageTest;
38 public class Test11 implements StorageTest {
40 XMultiServiceFactory m_xMSF;
41 XSingleServiceFactory m_xStorageFactory;
42 TestHelper m_aTestHelper;
44 public Test11( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
46 m_xMSF = xMSF;
47 m_xStorageFactory = xStorageFactory;
48 m_aTestHelper = new TestHelper( aLogWriter, "Test11: " );
51 public boolean test()
53 try
55 // create temporary storage based on arbitrary medium
56 // after such a storage is closed it is lost
57 Object oTempStorage = m_xStorageFactory.createInstance();
58 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
59 if ( xTempStorage == null )
61 m_aTestHelper.Error( "Can't create temporary storage representation!" );
62 return false;
65 byte pBigBytes[] = new byte[33000];
66 for ( int nInd = 0; nInd < 33000; nInd++ )
67 pBigBytes[nInd] = (byte)( nInd % 128 );
69 String sPass1 = "111111111";
70 byte pBytes1[] = { 1, 1, 1, 1, 1 };
72 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
73 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1, sPass1 ) )
74 return false;
76 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
77 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "BigSubStream1", "MediaType1", true, pBigBytes, sPass1 ) )
78 return false;
80 // open a new substorage
81 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
82 "SubStorage1",
83 ElementModes.WRITE );
84 if ( xTempSubStorage == null )
86 m_aTestHelper.Error( "Can't create substorage!" );
87 return false;
90 String sPass2 = "2222222222";
91 byte pBytes2[] = { 2, 2, 2, 2, 2 };
93 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
94 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", true, pBytes2, sPass2 ) )
95 return false;
97 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
98 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes, sPass2 ) )
99 return false;
101 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
103 "MediaType3",
104 true,
105 ElementModes.WRITE ) )
106 return false;
108 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
109 "MediaType4",
110 false,
111 ElementModes.WRITE ) )
112 return false;
115 // check cloning at current state
118 // the new storage still was not committed so the clone must be empty
119 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
121 if ( xClonedSubStorage == null )
123 m_aTestHelper.Error( "The result of clone is empty!" );
124 return false;
127 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
128 if ( xClonedNameAccess == null )
130 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
131 return false;
134 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "", true, ElementModes.WRITE ) )
135 return false;
137 if ( xClonedNameAccess.hasElements() )
139 m_aTestHelper.Error( "The new substorage still was not committed so it must be empty!" );
140 return false;
143 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
144 return false;
146 xClonedSubStorage = null;
147 xClonedNameAccess = null;
149 // the new stream was opened, written and closed, that means flashed
150 // so the clone must contain all the information
151 XStream xClonedSubStream = m_aTestHelper.cloneEncrSubStream( xTempStorage, "SubStream1", sPass1 );
152 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream, "SubStream1", "MediaType1", true, pBytes1, true ) )
153 return false;
155 XStream xClonedBigSubStream = m_aTestHelper.cloneEncrSubStream( xTempStorage, "BigSubStream1", sPass1 );
156 if ( !m_aTestHelper.InternalCheckStream( xClonedBigSubStream, "BigSubStream1", "MediaType1", true, pBigBytes, true ) )
157 return false;
159 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
160 return false;
162 if ( !m_aTestHelper.disposeStream( xClonedBigSubStream, "BigSubStream1" ) )
163 return false;
166 // commit substorage and check cloning
169 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
170 return false;
172 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
173 if ( xClonedSubStorage == null )
175 m_aTestHelper.Error( "The result of clone is empty!" );
176 return false;
179 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "MediaType4", true, ElementModes.WRITE ) )
180 return false;
182 if ( !m_aTestHelper.checkEncrStream( xClonedSubStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
183 return false;
185 if ( !m_aTestHelper.checkEncrStream( xClonedSubStorage, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
186 return false;
189 // commit the root storage and check cloning
192 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
193 return false;
195 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
196 if ( xCloneOfRoot == null )
198 m_aTestHelper.Error( "The result of root clone is empty!" );
199 return false;
202 if ( !m_aTestHelper.checkStorageProperties( xCloneOfRoot, "MediaType3", true, ElementModes.WRITE ) )
203 return false;
205 if ( !m_aTestHelper.checkEncrStream( xCloneOfRoot, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
206 return false;
208 if ( !m_aTestHelper.checkEncrStream( xCloneOfRoot, "BigSubStream1", "MediaType1", pBigBytes, sPass1 ) )
209 return false;
211 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
212 if ( xSubStorageOfClone == null )
214 m_aTestHelper.Error( "The result of root clone is wrong!" );
215 return false;
218 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone, "MediaType4", false, ElementModes.READ ) )
219 return false;
221 if ( !m_aTestHelper.checkEncrStream( xSubStorageOfClone, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
222 return false;
224 if ( !m_aTestHelper.checkEncrStream( xSubStorageOfClone, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
225 return false;
227 return true;
229 catch( Exception e )
231 m_aTestHelper.Error( "Exception: " + e );
232 return false;