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 Test18
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test18( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test18: " );
34 // test the default value of Compressed property
35 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
36 if ( sTempFileURL
== null || sTempFileURL
== "" )
38 m_aTestHelper
.Error( "No valid temporary file was created!" );
42 // create temporary storage based on arbitrary medium
43 // after such a storage is closed it is lost
44 Object oTempStorage
= m_xStorageFactory
.createInstance();
45 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
46 if ( xTempStorage
== null )
48 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
52 // open a new substorage
53 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
56 if ( xTempSubStorage
== null )
58 m_aTestHelper
.Error( "Can't create substorage!" );
62 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
64 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
65 if ( !m_aTestHelper
.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage
, "SubStream1", "image/jpeg", pBytes1
) )
68 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
69 if ( !m_aTestHelper
.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage
, "SubStream2", "image/png", pBytes1
) )
72 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
73 if ( !m_aTestHelper
.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage
, "SubStream3", "image/gif", pBytes1
) )
76 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
77 if ( !m_aTestHelper
.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage
, "SubStream4", "MediaType1", pBytes1
) )
80 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
81 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
84 ElementModes
.WRITE
) )
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
91 ElementModes
.WRITE
) )
94 // create temporary storage based on a previously created temporary file
95 Object pArgs
[] = new Object
[2];
96 pArgs
[0] = (Object
) sTempFileURL
;
97 pArgs
[1] = new Integer( ElementModes
.WRITE
);
99 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
100 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
101 if ( xTempFileStorage
== null )
103 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
107 // copy xTempStorage to xTempFileStorage
108 // xTempFileStorage will be automatically commited
109 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
112 // dispose used storages to free resources
113 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
116 // ================================================
117 // now check all the written and copied information
118 // ================================================
120 // the temporary file must not be locked any more after storage disposing
121 pArgs
[1] = new Integer( ElementModes
.WRITE
);
122 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
123 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
124 if ( xResultStorage
== null )
126 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
130 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.WRITE
) )
133 // open existing substorage
134 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
137 if ( xResultSubStorage
== null )
139 m_aTestHelper
.Error( "Can't open existing substorage!" );
143 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.READ
) )
146 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "image/jpeg", false, pBytes1
) )
149 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream2", "image/png", false, pBytes1
) )
152 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream3", "image/gif", false, pBytes1
) )
155 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream4", "MediaType1", true, pBytes1
) )
158 // dispose used storages to free resources
159 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
166 m_aTestHelper
.Error( "Exception: " + e
);