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_i49755
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public RegressionTest_i49755( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i49755: " );
54 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
55 if ( xTempFileStream
== null )
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!" );
71 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
72 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
75 ElementModes
.WRITE
) )
79 byte pBytes
[] = new byte[36000];
80 for ( int nInd
= 0; nInd
< 36000; nInd
++ )
81 pBytes
[nInd
] = (byte)( nInd
% 128 );
83 // open a new substorage
84 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
87 if ( xTempSubStorage
== null )
89 m_aTestHelper
.Error( "Can't create substorage!" );
93 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
94 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
97 ElementModes
.WRITE
) )
100 // open a new substorage
101 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
103 ElementModes
.WRITE
);
104 if ( xTempSubStorage
== null )
106 m_aTestHelper
.Error( "Can't create substorage!" );
110 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
111 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
114 ElementModes
.WRITE
) )
117 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
118 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubStream1", "MediaType4", true, pBytes
) )
121 // open a new substorage
122 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
124 ElementModes
.WRITE
);
125 if ( xTempSubStorage1
== null )
127 m_aTestHelper
.Error( "Can't create substorage!" );
131 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
132 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage1
,
135 ElementModes
.WRITE
) )
138 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
139 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
143 // commit substorages first
144 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
147 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
150 if ( !m_aTestHelper
.commitStorage( xTempSubStorage1
) )
153 // commit the root storage so the contents must be stored now
154 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
157 // dispose used storage to free resources
158 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
162 // now change the contents of the second substorage
163 // without changing of the contents of the first substorage
166 Object oStep2TempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
167 XStorage xStep2TempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStep2TempStorage
);
168 if ( xStep2TempStorage
== null )
170 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
174 XStorage xStep2TempSubStorage1
= m_aTestHelper
.openSubStorage( xStep2TempStorage
,
176 ElementModes
.WRITE
);
177 if ( xStep2TempSubStorage1
== null )
179 m_aTestHelper
.Error( "Can't create substorage!" );
183 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
184 if ( !m_aTestHelper
.WriteBytesToSubstream( xStep2TempSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
187 if ( !m_aTestHelper
.commitStorage( xStep2TempSubStorage1
) )
190 // commit the root storage so the contents must be stored now
191 if ( !m_aTestHelper
.commitStorage( xStep2TempStorage
) )
194 // dispose used storage to free resources
195 if ( !m_aTestHelper
.disposeStorage( xStep2TempStorage
) )
200 // now check all the written information
201 // and the raw stream contents
204 // close the output part of the temporary stream
205 // the output part must present since we already wrote to the stream
206 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
209 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
210 if ( xTempInStream
== null )
214 // since no mode is provided the result storage must be opened readonly
215 Object pOneArg
[] = new Object
[1];
216 pOneArg
[0] = (Object
) xTempInStream
;
218 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
219 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
220 if ( xResultStorage
== null )
222 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
226 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType1", true, ElementModes
.READ
) )
229 // open existing substorage
230 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
233 if ( xResultSubStorage
== null )
235 m_aTestHelper
.Error( "Can't open existing substorage!" );
239 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType2", false, ElementModes
.READ
) )
242 // open existing substorage
243 XStorage xResultSubSubStorage
= m_aTestHelper
.openSubStorage( xResultSubStorage
,
246 if ( xResultSubSubStorage
== null )
248 m_aTestHelper
.Error( "Can't open existing substorage!" );
252 if ( !m_aTestHelper
.checkStorageProperties( xResultSubSubStorage
, "MediaType3", false, ElementModes
.READ
) )
255 if ( !m_aTestHelper
.checkStream( xResultSubSubStorage
, "SubStream1", "MediaType4", true, pBytes
) )
260 XStorage xResultSubStorage1
= m_aTestHelper
.openSubStorage( xResultStorage
,
263 if ( xResultSubStorage1
== null )
265 m_aTestHelper
.Error( "Can't open existing substorage!" );
269 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage1
, "MediaType5", false, ElementModes
.READ
) )
272 if ( !m_aTestHelper
.checkStream( xResultSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
276 // dispose used storages to free resources
277 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
284 m_aTestHelper
.Error( "Exception: " + e
);