bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / Test16.java
blob36e945e74d124d689039a3558c61bc6d6ca9526e
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 Test16 implements StorageTest {
37 XMultiServiceFactory m_xMSF;
38 XSingleServiceFactory m_xStorageFactory;
39 TestHelper m_aTestHelper;
41 public Test16( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
43 m_xMSF = xMSF;
44 m_xStorageFactory = xStorageFactory;
45 m_aTestHelper = new TestHelper( aLogWriter, "Test16: " );
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 "SubStorage\u0442\u0435\u0441\u04421",
72 ElementModes.WRITE );
73 if ( xTempSubStorage == null )
75 m_aTestHelper.Error( "Can't create substorage!" );
76 return false;
79 byte pBytes1[] = { 1, 1, 1, 1, 1 };
81 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
82 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) )
83 return false;
85 byte pBytes2[] = { 2, 2, 2, 2, 2 };
87 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
88 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) )
89 return false;
91 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
92 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
93 "MediaType3",
94 true,
95 ElementModes.WRITE ) )
96 return false;
98 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
99 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
100 "MediaType4",
101 false,
102 ElementModes.WRITE ) )
103 return false;
105 // create temporary storage based on a previously created temporary file
106 Object pArgs[] = new Object[2];
107 pArgs[0] = (Object) sTempFileURL;
108 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
110 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
111 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
112 if ( xTempFileStorage == null )
114 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
115 return false;
118 // copy xTempStorage to xTempFileStorage
119 // xTempFileStorage will be automatically committed
120 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
121 return false;
123 // dispose used storages to free resources
124 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
125 return false;
128 // now check all the written and copied information
131 // the temporary file must not be locked any more after storage disposing
132 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
133 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
134 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
135 if ( xResultStorage == null )
137 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
138 return false;
141 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) )
142 return false;
144 // open existing substorage
145 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
146 "SubStorage\u0442\u0435\u0441\u04421",
147 ElementModes.READ );
148 if ( xResultSubStorage == null )
150 m_aTestHelper.Error( "Can't open existing substorage!" );
151 return false;
154 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
155 return false;
157 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) )
158 return false;
160 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) )
161 return false;
163 // dispose used storages to free resources
164 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
165 return false;
167 return true;
169 catch( Exception e )
171 m_aTestHelper.Error( "Exception: " + e );
172 return false;