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_i46848
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public RegressionTest_i46848( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i46848: " );
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 // open a new substorage
72 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
75 if ( xTempSubStorage
== null )
77 m_aTestHelper
.Error( "Can't create substorage!" );
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
) )
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
91 ElementModes
.WRITE
) )
94 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
95 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
98 ElementModes
.WRITE
) )
101 // commit substorage first
102 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
105 // commit the root storage so the contents must be stored now
106 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
109 // dispose substorage
110 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
113 // dispose the temporary storage
114 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
118 // create a new storage based on the stream and change the mediatype of the substorage
119 // as described in the bug description
122 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
123 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
124 if ( xTempStorage
== null )
126 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
130 // open the substorage
131 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
133 ElementModes
.WRITE
);
134 if ( xTempSubStorage
== null )
136 m_aTestHelper
.Error( "Can't create substorage!" );
140 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
141 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
144 ElementModes
.WRITE
) )
147 // commit substorage first
148 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
151 // commit the root storage so the contents must be stored now
152 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
155 // dispose substorage
156 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
159 // dispose the temporary storage
160 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
164 // create a new readonly storage based on the stream and check the contents
167 pArgs
[1] = Integer
.valueOf( ElementModes
.READ
);
168 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
169 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
170 if ( xTempStorage
== null )
172 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
176 // open the substorage
177 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
180 if ( xTempSubStorage
== null )
182 m_aTestHelper
.Error( "Can't create substorage!" );
186 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType2", true, ElementModes
.READ
) )
189 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "ChangedMediaType3", false, ElementModes
.READ
) )
192 // the MediaType and the contents must be up to date
193 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
196 // dispose used storage to free resources
197 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
204 m_aTestHelper
.Error( "Exception: " + e
);