1 package complex
.storages
;
3 import com
.sun
.star
.uno
.XInterface
;
4 import com
.sun
.star
.lang
.XMultiServiceFactory
;
5 import com
.sun
.star
.lang
.XSingleServiceFactory
;
7 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
8 import com
.sun
.star
.uno
.UnoRuntime
;
9 import com
.sun
.star
.uno
.XInterface
;
11 import com
.sun
.star
.container
.XNameAccess
;
12 import com
.sun
.star
.io
.XStream
;
14 import com
.sun
.star
.embed
.*;
16 import share
.LogWriter
;
17 import complex
.storages
.TestHelper
;
18 import complex
.storages
.StorageTest
;
20 public class Test11
implements StorageTest
{
22 XMultiServiceFactory m_xMSF
;
23 XSingleServiceFactory m_xStorageFactory
;
24 TestHelper m_aTestHelper
;
26 public Test11( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
29 m_xStorageFactory
= xStorageFactory
;
30 m_aTestHelper
= new TestHelper( aLogWriter
, "Test11: " );
37 // create temporary storage based on arbitrary medium
38 // after such a storage is closed it is lost
39 Object oTempStorage
= m_xStorageFactory
.createInstance();
40 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
41 if ( xTempStorage
== null )
43 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
47 byte pBigBytes
[] = new byte[33000];
48 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
49 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
51 String sPass1
= "111111111";
52 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
54 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
55 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
, sPass1
) )
58 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
59 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
, sPass1
) )
62 // open a new substorage
63 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
66 if ( xTempSubStorage
== null )
68 m_aTestHelper
.Error( "Can't create substorage!" );
72 String sPass2
= "2222222222";
73 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempSubStorage
, "SubStream2", "MediaType2", true, pBytes2
, sPass2
) )
79 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
80 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempSubStorage
, "BigSubStream2", "MediaType2", true, pBigBytes
, sPass2
) )
83 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
87 ElementModes
.WRITE
) )
90 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
93 ElementModes
.WRITE
) )
96 // ==============================
97 // check cloning at current state
98 // ==============================
100 // the new storage still was not commited so the clone must be empty
101 XStorage xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
103 if ( xClonedSubStorage
== null )
105 m_aTestHelper
.Error( "The result of clone is empty!" );
109 XNameAccess xClonedNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xClonedSubStorage
);
110 if ( xClonedNameAccess
== null )
112 m_aTestHelper
.Error( "XNameAccess is not implemented by the clone!" );
116 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "", true, ElementModes
.WRITE
) )
119 if ( xClonedNameAccess
.hasElements() )
121 m_aTestHelper
.Error( "The new substorage still was not commited so it must be empty!" );
125 if ( !m_aTestHelper
.disposeStorage( xClonedSubStorage
) )
128 xClonedSubStorage
= null;
129 xClonedNameAccess
= null;
131 // the new stream was opened, written and closed, that means flashed
132 // so the clone must contain all the information
133 XStream xClonedSubStream
= m_aTestHelper
.cloneEncrSubStream( xTempStorage
, "SubStream1", sPass1
);
134 if ( !m_aTestHelper
.InternalCheckStream( xClonedSubStream
, "SubStream1", "MediaType1", true, pBytes1
, true ) )
137 XStream xClonedBigSubStream
= m_aTestHelper
.cloneEncrSubStream( xTempStorage
, "BigSubStream1", sPass1
);
138 if ( !m_aTestHelper
.InternalCheckStream( xClonedBigSubStream
, "BigSubStream1", "MediaType1", true, pBigBytes
, true ) )
141 if ( !m_aTestHelper
.disposeStream( xClonedSubStream
, "SubStream1" ) )
144 if ( !m_aTestHelper
.disposeStream( xClonedBigSubStream
, "BigSubStream1" ) )
147 // ==============================
148 // commit substorage and check cloning
149 // ==============================
151 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
154 xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
155 if ( xClonedSubStorage
== null )
157 m_aTestHelper
.Error( "The result of clone is empty!" );
161 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "MediaType4", true, ElementModes
.WRITE
) )
164 if ( !m_aTestHelper
.checkEncrStream( xClonedSubStorage
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
167 if ( !m_aTestHelper
.checkEncrStream( xClonedSubStorage
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
170 // ==============================
171 // commit the root storage and check cloning
172 // ==============================
174 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
177 XStorage xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xStorageFactory
, xTempStorage
);
178 if ( xCloneOfRoot
== null )
180 m_aTestHelper
.Error( "The result of root clone is empty!" );
184 if ( !m_aTestHelper
.checkStorageProperties( xCloneOfRoot
, "MediaType3", true, ElementModes
.WRITE
) )
187 if ( !m_aTestHelper
.checkEncrStream( xCloneOfRoot
, "SubStream1", "MediaType1", pBytes1
, sPass1
) )
190 if ( !m_aTestHelper
.checkEncrStream( xCloneOfRoot
, "BigSubStream1", "MediaType1", pBigBytes
, sPass1
) )
193 XStorage xSubStorageOfClone
= xCloneOfRoot
.openStorageElement( "SubStorage1", ElementModes
.READ
);
194 if ( xSubStorageOfClone
== null )
196 m_aTestHelper
.Error( "The result of root clone is wrong!" );
200 if ( !m_aTestHelper
.checkStorageProperties( xSubStorageOfClone
, "MediaType4", false, ElementModes
.READ
) )
203 if ( !m_aTestHelper
.checkEncrStream( xSubStorageOfClone
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
206 if ( !m_aTestHelper
.checkEncrStream( xSubStorageOfClone
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
213 m_aTestHelper
.Error( "Exception: " + e
);