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
.embed
.*;
13 import share
.LogWriter
;
14 import complex
.storages
.TestHelper
;
15 import complex
.storages
.StorageTest
;
17 public class Test01
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test01( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test01: " );
34 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
35 if ( sTempFileURL
== null || sTempFileURL
== "" )
37 m_aTestHelper
.Error( "No valid temporary file was created!" );
41 // create temporary storage based on arbitrary medium
42 // after such a storage is closed it is lost
43 Object oTempStorage
= m_xStorageFactory
.createInstance();
44 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
45 if ( xTempStorage
== null )
47 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
51 // open a new substorage
52 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
55 if ( xTempSubStorage
== null )
57 m_aTestHelper
.Error( "Can't create substorage!" );
61 byte pBigBytes
[] = new byte[33000];
62 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
63 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
66 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
) )
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "BigSubStream2", "MediaType2", false, pBigBytes
) )
73 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
79 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
81 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
82 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
85 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
86 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
89 ElementModes
.WRITE
) )
92 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
93 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
96 ElementModes
.WRITE
) )
99 // create temporary storage based on a previously created temporary file
100 Object pArgs
[] = new Object
[2];
101 pArgs
[0] = (Object
) sTempFileURL
;
102 pArgs
[1] = new Integer( ElementModes
.WRITE
);
104 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
105 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
106 if ( xTempFileStorage
== null )
108 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
112 // copy xTempStorage to xTempFileStorage
113 // xTempFileStorage will be automatically commited
114 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
117 // dispose used storages to free resources
118 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
121 // ================================================
122 // now check all the written and copied information
123 // ================================================
125 // the temporary file must not be locked any more after storage disposing
126 pArgs
[1] = new Integer( ElementModes
.WRITE
);
127 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
128 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
129 if ( xResultStorage
== null )
131 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
135 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.WRITE
) )
138 // open existing substorage
139 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
142 if ( xResultSubStorage
== null )
144 m_aTestHelper
.Error( "Can't open existing substorage!" );
148 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.READ
) )
151 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
) )
154 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "BigSubStream2", "MediaType2", false, pBigBytes
) )
157 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
160 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
163 // dispose used storages to free resources
164 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
171 m_aTestHelper
.Error( "Exception: " + e
);