bump product version to 4.1.6.2
[LibreOffice.git] / package / qa / storages / Test10.java
blob455d33173ef5addc685014cdff25c6d7a0424e0c
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.lang.XMultiServiceFactory;
22 import com.sun.star.lang.XSingleServiceFactory;
24 import com.sun.star.bridge.XUnoUrlResolver;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
28 import com.sun.star.container.XNameAccess;
29 import com.sun.star.io.XStream;
31 import com.sun.star.embed.*;
33 import share.LogWriter;
34 import complex.storages.TestHelper;
35 import complex.storages.StorageTest;
37 public class Test10 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public Test10( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "Test10: " );
50 public boolean test()
52 try
54 // create temporary storage based on arbitrary medium
55 // after such a storage is closed it is lost
56 Object oTempStorage = m_xStorageFactory.createInstance();
57 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
58 if ( xTempStorage == null )
60 m_aTestHelper.Error( "Can't create temporary storage representation!" );
61 return false;
64 byte pBigBytes[] = new byte[33000];
65 for ( int nInd = 0; nInd < 33000; nInd++ )
66 pBigBytes[nInd] = (byte)( nInd % 128 );
68 byte pBytes1[] = { 1, 1, 1, 1, 1 };
70 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
71 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
72 return false;
74 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
75 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
76 return false;
79 // open a new substorage
80 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
81 "SubStorage1",
82 ElementModes.WRITE );
83 if ( xTempSubStorage == null )
85 m_aTestHelper.Error( "Can't create substorage!" );
86 return false;
89 byte pBytes2[] = { 2, 2, 2, 2, 2 };
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", true, pBytes2 ) )
93 return false;
95 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
96 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes ) )
97 return false;
99 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
100 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
101 "MediaType3",
102 true,
103 ElementModes.WRITE ) )
104 return false;
106 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
107 "MediaType4",
108 false,
109 ElementModes.WRITE ) )
110 return false;
112 // ==============================
113 // check cloning at current state
114 // ==============================
116 // the new storage still was not commited so the clone must be empty
117 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
119 if ( xClonedSubStorage == null )
121 m_aTestHelper.Error( "The result of clone is empty!" );
122 return false;
125 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
126 if ( xClonedNameAccess == null )
128 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
129 return false;
132 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "", true, ElementModes.WRITE ) )
133 return false;
135 if ( xClonedNameAccess.hasElements() )
137 m_aTestHelper.Error( "The new substorage still was not commited so it must be empty!" );
138 return false;
141 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
142 return false;
144 xClonedSubStorage = null;
145 xClonedNameAccess = null;
147 // the new stream was opened, written and closed, that means flashed
148 // so the clone must contain all the information
149 XStream xClonedSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "SubStream1" );
150 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream, "SubStream1", "MediaType1", true, pBytes1, true ) )
151 return false;
153 XStream xClonedBigSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "BigSubStream1" );
154 if ( !m_aTestHelper.InternalCheckStream( xClonedBigSubStream, "BigSubStream1", "MediaType1", true, pBigBytes, true ) )
155 return false;
157 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
158 return false;
160 if ( !m_aTestHelper.disposeStream( xClonedBigSubStream, "BigSubStream1" ) )
161 return false;
163 // ==============================
164 // commit substorage and check cloning
165 // ==============================
167 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
168 return false;
170 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xStorageFactory, xTempStorage, "SubStorage1" );
171 if ( xClonedSubStorage == null )
173 m_aTestHelper.Error( "The result of clone is empty!" );
174 return false;
177 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage, "MediaType4", true, ElementModes.WRITE ) )
178 return false;
180 if ( !m_aTestHelper.checkStream( xClonedSubStorage, "SubStream2", "MediaType2", true, pBytes2 ) )
181 return false;
183 if ( !m_aTestHelper.checkStream( xClonedSubStorage, "BigSubStream2", "MediaType2", true, pBigBytes ) )
184 return false;
186 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
187 if ( xCloneOfRoot == null )
189 m_aTestHelper.Error( "The result of root clone is empty!" );
190 return false;
193 XNameAccess xCloneOfRootNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xCloneOfRoot );
194 if ( xCloneOfRootNA == null )
196 m_aTestHelper.Error( "XNameAccess is not implemented by the root clone!" );
197 return false;
200 if ( xCloneOfRootNA.hasElements() )
202 m_aTestHelper.Error( "The root storage still was not commited so it's clone must be empty!" );
203 return false;
206 if ( !m_aTestHelper.disposeStorage( xCloneOfRoot ) )
207 return false;
209 xCloneOfRoot = null;
211 // ==============================
212 // commit root storage and check cloning
213 // ==============================
215 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
216 return false;
218 xCloneOfRoot = m_aTestHelper.cloneStorage( m_xStorageFactory, xTempStorage );
219 if ( xCloneOfRoot == null )
221 m_aTestHelper.Error( "The result of root clone is empty!" );
222 return false;
225 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
226 if ( xSubStorageOfClone == null )
228 m_aTestHelper.Error( "The result of root clone is wrong!" );
229 return false;
232 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone, "MediaType4", false, ElementModes.READ ) )
233 return false;
235 if ( !m_aTestHelper.checkStream( xSubStorageOfClone, "SubStream2", "MediaType2", true, pBytes2 ) )
236 return false;
238 if ( !m_aTestHelper.checkStream( xSubStorageOfClone, "BigSubStream2", "MediaType2", true, pBigBytes ) )
239 return false;
241 return true;
243 catch( Exception e )
245 m_aTestHelper.Error( "Exception: " + e );
246 return false;