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
.ofopxmlstorages
;
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
.*;
32 import com
.sun
.star
.beans
.StringPair
;
34 import share
.LogWriter
;
35 import complex
.ofopxmlstorages
.TestHelper
;
36 import complex
.ofopxmlstorages
.StorageTest
;
38 public class Test08
implements StorageTest
{
40 XMultiServiceFactory m_xMSF
;
41 XSingleServiceFactory m_xStorageFactory
;
42 TestHelper m_aTestHelper
;
44 public Test08( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
47 m_xStorageFactory
= xStorageFactory
;
48 m_aTestHelper
= new TestHelper( aLogWriter
, "Test08: " );
53 StringPair
[][] aRelations1
=
54 { { new StringPair( "Id", "Num1" ) },
55 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
56 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
57 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
58 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
59 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
60 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
65 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
66 if ( xTempFileStream
== null )
69 // create storage based on the temporary stream
70 XStorage xTempStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
73 if ( xTempStorage
== null )
75 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
79 // open a new substorage
80 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
83 if ( xTempSubStorage
== null )
85 m_aTestHelper
.Error( "Can't create substorage!" );
89 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
100 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
101 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
107 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
108 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
114 // commit substorage first
115 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
118 // commit the root storage so the contents must be stored now
119 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
122 // dispose substorage
123 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
130 if ( !checkSubStorages( xTempStorage
, pBytes1
, aRelations1
) )
133 // dispose used storage to free resources
134 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
138 // now check all the written information with readwrite access
141 XStorage xResWriteStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
143 ElementModes
.WRITE
);
144 if ( xResWriteStorage
== null )
146 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
150 if ( !m_aTestHelper
.checkStorageProperties( xResWriteStorage
,
156 if( !checkSubStorages( xResWriteStorage
, pBytes1
, aRelations1
) )
159 // try to open for writing after opening for reading
160 XStorage xResWSubStorage
= m_aTestHelper
.openSubStorage( xResWriteStorage
,
162 ElementModes
.WRITE
);
163 if ( xResWSubStorage
== null )
165 m_aTestHelper
.Error( "Can't open substorage for writing after it was opened for reading!" );
169 if ( !m_aTestHelper
.checkStorageProperties( xResWSubStorage
,
175 if ( !m_aTestHelper
.checkStream( xResWSubStorage
,
182 // dispose used storage to free resources
183 if ( !m_aTestHelper
.disposeStorage( xResWriteStorage
) )
188 // now check all the written information with readonly access
191 // close the output part of the temporary stream
192 // the output part must present since we already wrote to the stream
193 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
196 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
197 if ( xTempInStream
== null )
201 // since no mode is provided the result storage must be opened readonly
202 XStorage xResultStorage
= m_aTestHelper
.createStorageFromInputStream( m_xStorageFactory
,
204 if ( xResultStorage
== null )
206 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
210 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
216 if( !checkSubStorages( xResultStorage
, pBytes1
, aRelations1
) )
223 m_aTestHelper
.Error( "Exception: " + e
);
228 private boolean checkSubStorages( XStorage xStorage
, byte[] pBytes1
, StringPair
[][] aRelations
)
230 XStorage xReadSubStorage1
= m_aTestHelper
.openSubStorage( xStorage
,
234 XStorage xReadSubStorage2
= m_aTestHelper
.openSubStorage( xStorage
,
238 if ( xReadSubStorage1
== null || xReadSubStorage2
== null )
240 m_aTestHelper
.Error( "Can't open substorage for reading!" );
244 if ( !m_aTestHelper
.checkStorageProperties( xReadSubStorage1
,
250 if ( !m_aTestHelper
.checkStorageProperties( xReadSubStorage2
,
256 if ( !m_aTestHelper
.checkStream( xReadSubStorage1
,
263 if ( !m_aTestHelper
.checkStream( xReadSubStorage2
,
270 if ( !m_aTestHelper
.disposeStorage( xReadSubStorage1
) )
273 if ( !m_aTestHelper
.disposeStorage( xReadSubStorage2
) )