1 package complex
.storages
;
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
.*;
15 import share
.LogWriter
;
16 import complex
.storages
.TestHelper
;
17 import complex
.storages
.StorageTest
;
19 public class Test10
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public Test10( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "Test10: " );
36 // create temporary storage based on arbitrary medium
37 // after such a storage is closed it is lost
38 Object oTempStorage
= m_xStorageFactory
.createInstance();
39 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
40 if ( xTempStorage
== null )
42 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
46 byte pBigBytes
[] = new byte[33000];
47 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
48 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
50 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
52 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
53 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
56 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
57 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
) )
61 // open a new substorage
62 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
65 if ( xTempSubStorage
== null )
67 m_aTestHelper
.Error( "Can't create substorage!" );
71 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", true, pBytes2
) )
77 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
78 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
81 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
82 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
85 ElementModes
.WRITE
) )
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
91 ElementModes
.WRITE
) )
94 // ==============================
95 // check cloning at current state
96 // ==============================
98 // the new storage still was not commited so the clone must be empty
99 XStorage xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
101 if ( xClonedSubStorage
== null )
103 m_aTestHelper
.Error( "The result of clone is empty!" );
107 XNameAccess xClonedNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xClonedSubStorage
);
108 if ( xClonedNameAccess
== null )
110 m_aTestHelper
.Error( "XNameAccess is not implemented by the clone!" );
114 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "", true, ElementModes
.WRITE
) )
117 if ( xClonedNameAccess
.hasElements() )
119 m_aTestHelper
.Error( "The new substorage still was not commited so it must be empty!" );
123 if ( !m_aTestHelper
.disposeStorage( xClonedSubStorage
) )
126 xClonedSubStorage
= null;
127 xClonedNameAccess
= null;
129 // the new stream was opened, written and closed, that means flashed
130 // so the clone must contain all the information
131 XStream xClonedSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "SubStream1" );
132 if ( !m_aTestHelper
.InternalCheckStream( xClonedSubStream
, "SubStream1", "MediaType1", true, pBytes1
, true ) )
135 XStream xClonedBigSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "BigSubStream1" );
136 if ( !m_aTestHelper
.InternalCheckStream( xClonedBigSubStream
, "BigSubStream1", "MediaType1", true, pBigBytes
, true ) )
139 if ( !m_aTestHelper
.disposeStream( xClonedSubStream
, "SubStream1" ) )
142 if ( !m_aTestHelper
.disposeStream( xClonedBigSubStream
, "BigSubStream1" ) )
145 // ==============================
146 // commit substorage and check cloning
147 // ==============================
149 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
152 xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
153 if ( xClonedSubStorage
== null )
155 m_aTestHelper
.Error( "The result of clone is empty!" );
159 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "MediaType4", true, ElementModes
.WRITE
) )
162 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
, "SubStream2", "MediaType2", true, pBytes2
) )
165 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
168 XStorage xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xStorageFactory
, xTempStorage
);
169 if ( xCloneOfRoot
== null )
171 m_aTestHelper
.Error( "The result of root clone is empty!" );
175 XNameAccess xCloneOfRootNA
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xCloneOfRoot
);
176 if ( xCloneOfRootNA
== null )
178 m_aTestHelper
.Error( "XNameAccess is not implemented by the root clone!" );
182 if ( xCloneOfRootNA
.hasElements() )
184 m_aTestHelper
.Error( "The root storage still was not commited so it's clone must be empty!" );
188 if ( !m_aTestHelper
.disposeStorage( xCloneOfRoot
) )
193 // ==============================
194 // commit root storage and check cloning
195 // ==============================
197 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
200 xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xStorageFactory
, xTempStorage
);
201 if ( xCloneOfRoot
== null )
203 m_aTestHelper
.Error( "The result of root clone is empty!" );
207 XStorage xSubStorageOfClone
= xCloneOfRoot
.openStorageElement( "SubStorage1", ElementModes
.READ
);
208 if ( xSubStorageOfClone
== null )
210 m_aTestHelper
.Error( "The result of root clone is wrong!" );
214 if ( !m_aTestHelper
.checkStorageProperties( xSubStorageOfClone
, "MediaType4", false, ElementModes
.READ
) )
217 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
, "SubStream2", "MediaType2", true, pBytes2
) )
220 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
227 m_aTestHelper
.Error( "Exception: " + e
);