bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_114358.java
blobf76216cf22d2dd285dcd4e27ced2a4f608b2c78d
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;
28 import com.sun.star.io.XStream;
29 import com.sun.star.io.XInputStream;
31 import com.sun.star.embed.*;
33 import share.LogWriter;
34 import complex.storages.TestHelper;
35 import complex.storages.StorageTest;
37 public class RegressionTest_114358 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_114358( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_114358: " );
50 public boolean test()
52 try
54 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
55 if ( xTempFileStream == null )
56 return false;
58 // create storage based on the temporary stream
59 Object pArgs[] = new Object[2];
60 pArgs[0] = (Object) xTempFileStream;
61 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
63 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
64 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
65 if ( xTempStorage == null )
67 m_aTestHelper.Error( "Can't create temporary storage representation!" );
68 return false;
71 // open a new substorage
72 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
73 "SubStorage1",
74 ElementModes.WRITE );
75 if ( xTempSubStorage == null )
77 m_aTestHelper.Error( "Can't create substorage!" );
78 return false;
81 byte pBytes1[] = { 1, 1, 1, 1, 1 };
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
85 return false;
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
89 "MediaType2",
90 true,
91 ElementModes.WRITE ) )
92 return false;
94 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
95 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
96 "MediaType3",
97 false,
98 ElementModes.WRITE ) )
99 return false;
101 // commit substorage first
102 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
103 return false;
105 // commit the root storage so the contents must be stored now
106 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
107 return false;
109 // dispose substorage
110 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
111 return false;
113 // dispose the temporary storage
114 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
115 return false;
118 // create a new storage based on the stream and change the substream
119 // as described in the bug description
122 byte pBytes2[] = { 2, 2 };
124 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
125 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
126 if ( xTempStorage == null )
128 m_aTestHelper.Error( "Can't create temporary storage representation!" );
129 return false;
132 // open the substorage
133 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
134 "SubStorage1",
135 ElementModes.WRITE );
136 if ( xTempSubStorage == null )
138 m_aTestHelper.Error( "Can't create substorage!" );
139 return false;
142 // open the substream, set new "MediaType" and "Compressed" properties to it, truncate and write new contents
143 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType4", true, pBytes2 ) )
144 return false;
146 // commit substorage first
147 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
148 return false;
150 // commit the root storage so the contents must be stored now
151 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
152 return false;
154 // dispose substorage
155 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
156 return false;
158 // dispose the temporary storage
159 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
160 return false;
163 // create a new readonly storage based on the stream and check the contents
166 pArgs[1] = Integer.valueOf( ElementModes.READ );
167 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
168 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
169 if ( xTempStorage == null )
171 m_aTestHelper.Error( "Can't create temporary storage representation!" );
172 return false;
175 // open the substorage
176 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
177 "SubStorage1",
178 ElementModes.READ );
179 if ( xTempSubStorage == null )
181 m_aTestHelper.Error( "Can't create substorage!" );
182 return false;
185 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
186 return false;
188 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.READ ) )
189 return false;
191 // the MediaType and the contents must be up to date
192 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType4", true, pBytes2 ) )
193 return false;
195 // dispose used storage to free resources
196 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
197 return false;
199 return true;
201 catch( Exception e )
203 m_aTestHelper.Error( "Exception: " + e );
204 return false;