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 Test02
implements StorageTest
{
40 XMultiServiceFactory m_xMSF
;
41 XSingleServiceFactory m_xStorageFactory
;
42 TestHelper m_aTestHelper
;
44 public Test02( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
47 m_xStorageFactory
= xStorageFactory
;
48 m_aTestHelper
= new TestHelper( aLogWriter
, "Test02: " );
55 StringPair
[][] aRelations
=
56 { { new StringPair( "Id", "Num1" ) },
57 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
58 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
59 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
60 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
61 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
62 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
66 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
67 if ( xTempFileStream
== null )
70 // create storage based on the temporary stream
71 XStorage xTempStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
74 if ( xTempStorage
== null )
76 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
80 // open a new substorage
81 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
84 if ( xTempSubStorage
== null )
86 m_aTestHelper
.Error( "Can't create substorage!" );
90 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
92 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
93 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
101 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
108 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
109 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
115 // commit substorage first
116 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
119 // commit the root storage so the contents must be stored now
120 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
123 // dispose used storage to free resources
124 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
129 // now check all the written information
132 // close the output part of the temporary stream
133 // the output part must present since we already wrote to the stream
134 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
137 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
138 if ( xTempInStream
== null )
143 XStorage xResultStorage
= m_aTestHelper
.createStorageFromInputStream( m_xStorageFactory
, xTempInStream
);
144 if ( xResultStorage
== null )
146 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
150 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, true, ElementModes
.READ
, aRelations
) )
153 // open existing substorage
154 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
157 if ( xResultSubStorage
== null )
159 m_aTestHelper
.Error( "Can't open existing substorage!" );
163 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
169 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", pBytes1
, aRelations
) )
176 m_aTestHelper
.Error( "Exception: " + e
);