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 Test16
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test16( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test16: " );
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
,
53 "SubStorage\u0442\u0435\u0441\u04421",
55 if ( xTempSubStorage
== null )
57 m_aTestHelper
.Error( "Can't create substorage!" );
61 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
63 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
64 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1
) )
67 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2
) )
73 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
74 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
77 ElementModes
.WRITE
) )
80 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
81 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
84 ElementModes
.WRITE
) )
87 // create temporary storage based on a previously created temporary file
88 Object pArgs
[] = new Object
[2];
89 pArgs
[0] = (Object
) sTempFileURL
;
90 pArgs
[1] = new Integer( ElementModes
.WRITE
);
92 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
93 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
94 if ( xTempFileStorage
== null )
96 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
100 // copy xTempStorage to xTempFileStorage
101 // xTempFileStorage will be automatically commited
102 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
105 // dispose used storages to free resources
106 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
109 // ================================================
110 // now check all the written and copied information
111 // ================================================
113 // the temporary file must not be locked any more after storage disposing
114 pArgs
[1] = new Integer( ElementModes
.WRITE
);
115 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
116 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
117 if ( xResultStorage
== null )
119 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
123 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.WRITE
) )
126 // open existing substorage
127 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
128 "SubStorage\u0442\u0435\u0441\u04421",
130 if ( xResultSubStorage
== null )
132 m_aTestHelper
.Error( "Can't open existing substorage!" );
136 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.READ
) )
139 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1
) )
142 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2
) )
145 // dispose used storages to free resources
146 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
153 m_aTestHelper
.Error( "Exception: " + e
);