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
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.lang
.XSingleServiceFactory
;
24 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.XInterface
;
28 import com
.sun
.star
.container
.XNameAccess
;
29 import com
.sun
.star
.io
.XStream
;
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 Test07
implements StorageTest
{
40 XMultiServiceFactory m_xMSF
;
41 XSingleServiceFactory m_xStorageFactory
;
42 TestHelper m_aTestHelper
;
44 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
47 m_xStorageFactory
= xStorageFactory
;
48 m_aTestHelper
= new TestHelper( aLogWriter
, "Test07: " );
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" ) }
63 StringPair
[][] aRelations2
=
64 { { new StringPair( "Id", "Num1" ) },
65 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
66 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
67 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
68 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
69 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
70 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
75 // create temporary storage based on arbitrary medium
76 // after such a storage is closed it is lost
77 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
78 if ( xTempStorage
== null )
80 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
84 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
86 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
87 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
,
96 // open a new substorage
97 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
100 if ( xTempSubStorage
== null )
102 m_aTestHelper
.Error( "Can't create substorage!" );
106 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
108 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
109 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
117 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
118 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
124 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
131 // check cloning at current state
134 // the new storage still was not committed so the clone must be empty
135 XStorage xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
, "SubStorage1" );
137 if ( xClonedSubStorage
== null )
139 m_aTestHelper
.Error( "The result of clone is empty!" );
143 XNameAccess xClonedNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xClonedSubStorage
);
144 if ( xClonedNameAccess
== null )
146 m_aTestHelper
.Error( "XNameAccess is not implemented by the clone!" );
150 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
,
153 new StringPair
[0][0] ) )
156 if ( xClonedNameAccess
.hasElements() )
158 m_aTestHelper
.Error( "The new substorage still was not committed so it must be empty!" );
162 if ( !m_aTestHelper
.disposeStorage( xClonedSubStorage
) )
165 xClonedSubStorage
= null;
166 xClonedNameAccess
= null;
168 // the new stream was opened, written and closed, that means flashed
169 // so the clone must contain all the information
170 XStream xClonedSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "SubStream1" );
171 if ( !m_aTestHelper
.InternalCheckStream( xClonedSubStream
,
178 if ( !m_aTestHelper
.disposeStream( xClonedSubStream
, "SubStream1" ) )
182 // commit substorage and check cloning
185 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
188 xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
, "SubStorage1" );
189 if ( xClonedSubStorage
== null )
191 m_aTestHelper
.Error( "The result of clone is empty!" );
195 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
,
201 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
,
208 XStorage xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
);
209 if ( xCloneOfRoot
== null )
211 m_aTestHelper
.Error( "The result of root clone is empty!" );
215 XNameAccess xCloneOfRootNA
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xCloneOfRoot
);
216 if ( xCloneOfRootNA
== null )
218 m_aTestHelper
.Error( "XNameAccess is not implemented by the root clone!" );
222 if ( xCloneOfRootNA
.hasElements() )
224 m_aTestHelper
.Error( "The root storage still was not committed so it's clone must be empty!" );
228 if ( !m_aTestHelper
.disposeStorage( xCloneOfRoot
) )
234 // commit root storage and check cloning
237 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
240 xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
);
241 if ( xCloneOfRoot
== null )
243 m_aTestHelper
.Error( "The result of root clone is empty!" );
247 XStorage xSubStorageOfClone
= xCloneOfRoot
.openStorageElement( "SubStorage1", ElementModes
.READ
);
248 if ( xSubStorageOfClone
== null )
250 m_aTestHelper
.Error( "The result of root clone is wrong!" );
254 if ( !m_aTestHelper
.checkStorageProperties( xSubStorageOfClone
,
260 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
,
271 m_aTestHelper
.Error( "Exception: " + e
);