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
;
30 import com
.sun
.star
.embed
.*;
32 import share
.LogWriter
;
33 import complex
.storages
.TestHelper
;
34 import complex
.storages
.StorageTest
;
36 public class RegressionTest_i55821
implements StorageTest
{
38 XMultiServiceFactory m_xMSF
;
39 XSingleServiceFactory m_xStorageFactory
;
40 TestHelper m_aTestHelper
;
42 public RegressionTest_i55821( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
45 m_xStorageFactory
= xStorageFactory
;
46 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i55821: " );
54 // create a temporary stream and a storage based on it
55 // fill the storage with the data that will be used for testing
58 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
59 if ( xTempFileStream
== null )
62 // create storage based on the temporary stream
63 Object pArgs
[] = new Object
[2];
64 pArgs
[0] = (Object
) xTempFileStream
;
65 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
67 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
68 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
69 if ( xTempStorage
== null )
71 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
75 String sPass
= "12345";
76 byte pBytes
[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
78 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
79 // the stream will not be encrypted
80 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", false, pBytes
, sPass
) )
83 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
86 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes
, sPass
) )
89 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
92 // dispose used storages to free resources
93 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
97 // reopen the target storage readonly, and check contents
100 // the temporary file must not be locked any more after storage disposing
101 pArgs
[1] = Integer
.valueOf( ElementModes
.READ
);
102 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
103 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
104 if ( xResultStorage
== null )
106 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
110 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes
, sPass
) )
113 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes
, sPass
) )
116 // dispose used storages to free resources
117 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
124 m_aTestHelper
.Error( "Exception: " + e
);