1 package storagetesting
;
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 storagetesting
.TestHelper
;
14 import storagetesting
.StorageTest
;
16 public class Test01
implements StorageTest
{
18 XMultiServiceFactory m_xMSF
;
19 XSingleServiceFactory m_xStorageFactory
;
20 TestHelper m_aTestHelper
;
22 public Test01( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
25 m_xStorageFactory
= xStorageFactory
;
26 m_aTestHelper
= new TestHelper( "Test01: " );
33 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
34 if ( sTempFileURL
== null || sTempFileURL
== "" )
36 m_aTestHelper
.Error( "No valid temporary file was created!" );
40 // create temporary storage based on arbitrary medium
41 // after such a storage is closed it is lost
42 Object oTempStorage
= m_xStorageFactory
.createInstance();
43 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
44 if ( xTempStorage
== null )
46 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
50 // open a new substorage
51 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
53 ElementModes
.ELEMENT_WRITE
);
54 if ( xTempSubStorage
== null )
56 m_aTestHelper
.Error( "Can't create substorage!" );
60 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
62 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
63 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
66 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
68 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
69 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
72 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
73 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
76 ElementModes
.ELEMENT_READWRITE
) )
79 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
80 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
83 ElementModes
.ELEMENT_WRITE
) )
86 // create temporary storage based on a previously created temporary file
87 Object pArgs
[] = new Object
[2];
88 pArgs
[0] = (Object
) sTempFileURL
;
89 pArgs
[1] = new Integer( ElementModes
.ELEMENT_WRITE
);
91 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
92 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
93 if ( xTempFileStorage
== null )
95 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
99 // copy xTempStorage to xTempFileStorage
100 // xTempFileStorage will be automatically commited
101 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
104 // dispose used storages to free resources
105 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
108 // ================================================
109 // now check all the written and copied information
110 // ================================================
112 // the temporary file must not be locked any more after storage disposing
113 pArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
114 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
115 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
116 if ( xResultStorage
== null )
118 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
122 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.ELEMENT_READWRITE
) )
125 // open existing substorage
126 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
128 ElementModes
.ELEMENT_READ
);
129 if ( xResultSubStorage
== null )
131 m_aTestHelper
.Error( "Can't open existing substorage!" );
135 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.ELEMENT_READ
) )
138 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", pBytes1
) )
141 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream2", "MediaType2", pBytes2
) )
144 // dispose used storages to free resources
145 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
152 m_aTestHelper
.Error( "Exception: " + e
);