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
;
29 import com
.sun
.star
.embed
.*;
30 import com
.sun
.star
.beans
.StringPair
;
32 import share
.LogWriter
;
33 import complex
.ofopxmlstorages
.TestHelper
;
34 import complex
.ofopxmlstorages
.StorageTest
;
36 public class Test01
implements StorageTest
{
38 XMultiServiceFactory m_xMSF
;
39 XSingleServiceFactory m_xStorageFactory
;
40 TestHelper m_aTestHelper
;
42 public Test01( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
45 m_xStorageFactory
= xStorageFactory
;
46 m_aTestHelper
= new TestHelper( aLogWriter
, "Test01: " );
51 StringPair
[][] aRelations1
=
52 { { new StringPair( "Id", "Num1" ) },
53 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
54 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
55 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
56 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
57 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
58 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
61 StringPair
[][] aRelations2
=
62 { { new StringPair( "Id", "Num1" ) },
63 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
64 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
65 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
66 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
67 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
68 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
73 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
74 if ( sTempFileURL
== null || sTempFileURL
== "" )
76 m_aTestHelper
.Error( "No valid temporary file was created!" );
80 // create temporary storage based on arbitrary medium
81 // after such a storage is closed it is lost
82 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
83 if ( xTempStorage
== null )
85 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
89 // open a new substorage
90 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
93 if ( xTempSubStorage
== null )
95 m_aTestHelper
.Error( "Can't create substorage!" );
99 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
101 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
102 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
110 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
112 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
113 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
121 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
122 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
128 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
129 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
135 // create temporary storage based on a previously created temporary file
136 XStorage xTempFileStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
138 ElementModes
.WRITE
);
139 if ( xTempFileStorage
== null )
141 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
145 // copy xTempStorage to xTempFileStorage
146 // xTempFileStorage will be automatically committed
147 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
150 // dispose used storages to free resources
151 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
155 // now check all the written and copied information
158 // the temporary file must not be locked any more after storage disposing
159 XStorage xResultStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
161 ElementModes
.WRITE
);
162 if ( xResultStorage
== null )
164 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
168 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
174 // open existing substorage
175 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
178 if ( xResultSubStorage
== null )
180 m_aTestHelper
.Error( "Can't open existing substorage!" );
184 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
190 if ( !m_aTestHelper
.checkStream( xResultSubStorage
,
197 if ( !m_aTestHelper
.checkStream( xResultSubStorage
,
204 // dispose used storages to free resources
205 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
212 m_aTestHelper
.Error( "Exception: " + e
);