bump product version to 7.6.3.2-android
[LibreOffice.git] / package / qa / storages / Test01.java
bloba5d76bcca0153da3428b256d8a65fe4f83561c98
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 Test01 implements StorageTest {
37 XMultiServiceFactory m_xMSF;
38 XSingleServiceFactory m_xStorageFactory;
39 TestHelper m_aTestHelper;
41 public Test01( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
43 m_xMSF = xMSF;
44 m_xStorageFactory = xStorageFactory;
45 m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
48 public boolean test()
50 try
52 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
53 if ( sTempFileURL == null || sTempFileURL == "" )
55 m_aTestHelper.Error( "No valid temporary file was created!" );
56 return false;
59 // create temporary storage based on arbitrary medium
60 // after such a storage is closed it is lost
61 Object oTempStorage = m_xStorageFactory.createInstance();
62 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
63 if ( xTempStorage == null )
65 m_aTestHelper.Error( "Can't create temporary storage representation!" );
66 return false;
69 // open a new substorage
70 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
71 "SubStorage1",
72 ElementModes.WRITE );
73 if ( xTempSubStorage == null )
75 m_aTestHelper.Error( "Can't create substorage!" );
76 return false;
79 byte pBigBytes[] = new byte[33000];
80 for ( int nInd = 0; nInd < 33000; nInd++ )
81 pBigBytes[nInd] = (byte)( nInd % 128 );
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
85 return false;
87 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
88 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "BigSubStream2", "MediaType2", false, pBigBytes ) )
89 return false;
91 byte pBytes1[] = { 1, 1, 1, 1, 1 };
93 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
94 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
95 return false;
97 byte pBytes2[] = { 2, 2, 2, 2, 2 };
99 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
100 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes2 ) )
101 return false;
103 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
104 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
105 "MediaType3",
106 true,
107 ElementModes.WRITE ) )
108 return false;
110 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
111 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
112 "MediaType4",
113 false,
114 ElementModes.WRITE ) )
115 return false;
117 // create temporary storage based on a previously created temporary file
118 Object pArgs[] = new Object[2];
119 pArgs[0] = (Object) sTempFileURL;
120 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
122 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
123 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
124 if ( xTempFileStorage == null )
126 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
127 return false;
130 // copy xTempStorage to xTempFileStorage
131 // xTempFileStorage will be automatically committed
132 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
133 return false;
135 // dispose used storages to free resources
136 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
137 return false;
140 // now check all the written and copied information
143 // the temporary file must not be locked any more after storage disposing
144 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
145 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
146 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
147 if ( xResultStorage == null )
149 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
150 return false;
153 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) )
154 return false;
156 // open existing substorage
157 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
158 "SubStorage1",
159 ElementModes.READ );
160 if ( xResultSubStorage == null )
162 m_aTestHelper.Error( "Can't open existing substorage!" );
163 return false;
166 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
167 return false;
169 if ( !m_aTestHelper.checkStream( xResultSubStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
170 return false;
172 if ( !m_aTestHelper.checkStream( xResultSubStorage, "BigSubStream2", "MediaType2", false, pBigBytes ) )
173 return false;
175 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
176 return false;
178 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream2", "MediaType2", false, pBytes2 ) )
179 return false;
181 // dispose used storages to free resources
182 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
183 return false;
185 return true;
187 catch( Exception e )
189 m_aTestHelper.Error( "Exception: " + e );
190 return false;