1 package complex
.ofopxmlstorages
;
3 import com
.sun
.star
.lang
.XMultiServiceFactory
;
4 import com
.sun
.star
.lang
.XSingleServiceFactory
;
6 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
7 import com
.sun
.star
.uno
.UnoRuntime
;
8 import com
.sun
.star
.uno
.XInterface
;
10 import com
.sun
.star
.container
.XNameAccess
;
11 import com
.sun
.star
.io
.XStream
;
13 import com
.sun
.star
.embed
.*;
14 import com
.sun
.star
.beans
.StringPair
;
16 import share
.LogWriter
;
17 import complex
.ofopxmlstorages
.TestHelper
;
18 import complex
.ofopxmlstorages
.StorageTest
;
20 public class Test07
implements StorageTest
{
22 XMultiServiceFactory m_xMSF
;
23 XSingleServiceFactory m_xStorageFactory
;
24 TestHelper m_aTestHelper
;
26 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
29 m_xStorageFactory
= xStorageFactory
;
30 m_aTestHelper
= new TestHelper( aLogWriter
, "Test07: " );
35 StringPair
[][] aRelations1
=
36 { { new StringPair( "Id", "Num1" ) },
37 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
38 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
39 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
41 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
42 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
45 StringPair
[][] aRelations2
=
46 { { new StringPair( "Id", "Num1" ) },
47 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
48 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
49 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
50 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
51 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
52 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
57 // create temporary storage based on arbitrary medium
58 // after such a storage is closed it is lost
59 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
60 if ( xTempStorage
== null )
62 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
66 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
68 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
69 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
,
78 // open a new substorage
79 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
82 if ( xTempSubStorage
== null )
84 m_aTestHelper
.Error( "Can't create substorage!" );
88 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
90 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
91 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
99 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
100 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
106 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
112 // ==============================
113 // check cloning at current state
114 // ==============================
116 // the new storage still was not commited so the clone must be empty
117 XStorage xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
, "SubStorage1" );
119 if ( xClonedSubStorage
== null )
121 m_aTestHelper
.Error( "The result of clone is empty!" );
125 XNameAccess xClonedNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xClonedSubStorage
);
126 if ( xClonedNameAccess
== null )
128 m_aTestHelper
.Error( "XNameAccess is not implemented by the clone!" );
132 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
,
135 new StringPair
[0][0] ) )
138 if ( xClonedNameAccess
.hasElements() )
140 m_aTestHelper
.Error( "The new substorage still was not commited so it must be empty!" );
144 if ( !m_aTestHelper
.disposeStorage( xClonedSubStorage
) )
147 xClonedSubStorage
= null;
148 xClonedNameAccess
= null;
150 // the new stream was opened, written and closed, that means flashed
151 // so the clone must contain all the information
152 XStream xClonedSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "SubStream1" );
153 if ( !m_aTestHelper
.InternalCheckStream( xClonedSubStream
,
160 if ( !m_aTestHelper
.disposeStream( xClonedSubStream
, "SubStream1" ) )
163 // ==============================
164 // commit substorage and check cloning
165 // ==============================
167 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
170 xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
, "SubStorage1" );
171 if ( xClonedSubStorage
== null )
173 m_aTestHelper
.Error( "The result of clone is empty!" );
177 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
,
183 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
,
190 XStorage xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
);
191 if ( xCloneOfRoot
== null )
193 m_aTestHelper
.Error( "The result of root clone is empty!" );
197 XNameAccess xCloneOfRootNA
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xCloneOfRoot
);
198 if ( xCloneOfRootNA
== null )
200 m_aTestHelper
.Error( "XNameAccess is not implemented by the root clone!" );
204 if ( xCloneOfRootNA
.hasElements() )
206 m_aTestHelper
.Error( "The root storage still was not commited so it's clone must be empty!" );
210 if ( !m_aTestHelper
.disposeStorage( xCloneOfRoot
) )
215 // ==============================
216 // commit root storage and check cloning
217 // ==============================
219 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
222 xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xMSF
, m_xStorageFactory
, xTempStorage
);
223 if ( xCloneOfRoot
== null )
225 m_aTestHelper
.Error( "The result of root clone is empty!" );
229 XStorage xSubStorageOfClone
= xCloneOfRoot
.openStorageElement( "SubStorage1", ElementModes
.READ
);
230 if ( xSubStorageOfClone
== null )
232 m_aTestHelper
.Error( "The result of root clone is wrong!" );
236 if ( !m_aTestHelper
.checkStorageProperties( xSubStorageOfClone
,
242 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
,
253 m_aTestHelper
.Error( "Exception: " + e
);