1 package complex
.ofopxmlstorages
;
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
.*;
12 import com
.sun
.star
.beans
.StringPair
;
14 import share
.LogWriter
;
15 import complex
.ofopxmlstorages
.TestHelper
;
16 import complex
.ofopxmlstorages
.StorageTest
;
18 public class Test01
implements StorageTest
{
20 XMultiServiceFactory m_xMSF
;
21 XSingleServiceFactory m_xStorageFactory
;
22 TestHelper m_aTestHelper
;
24 public Test01( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
27 m_xStorageFactory
= xStorageFactory
;
28 m_aTestHelper
= new TestHelper( aLogWriter
, "Test01: " );
33 StringPair
[][] aRelations1
=
34 { { new StringPair( "Id", "Num1" ) },
35 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
36 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
37 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
38 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
39 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
43 StringPair
[][] aRelations2
=
44 { { new StringPair( "Id", "Num1" ) },
45 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
46 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
47 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
48 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
49 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
50 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
55 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
56 if ( sTempFileURL
== null || sTempFileURL
== "" )
58 m_aTestHelper
.Error( "No valid temporary file was created!" );
62 // create temporary storage based on arbitrary medium
63 // after such a storage is closed it is lost
64 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
65 if ( xTempStorage
== null )
67 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
71 // open a new substorage
72 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
75 if ( xTempSubStorage
== null )
77 m_aTestHelper
.Error( "Can't create substorage!" );
81 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
92 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
94 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
95 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
103 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
104 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
110 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
111 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
117 // create temporary storage based on a previously created temporary file
118 XStorage xTempFileStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
120 ElementModes
.WRITE
);
121 if ( xTempFileStorage
== null )
123 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
127 // copy xTempStorage to xTempFileStorage
128 // xTempFileStorage will be automatically commited
129 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
132 // dispose used storages to free resources
133 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
136 // ================================================
137 // now check all the written and copied information
138 // ================================================
140 // the temporary file must not be locked any more after storage disposing
141 XStorage xResultStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
143 ElementModes
.WRITE
);
144 if ( xResultStorage
== null )
146 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
150 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
156 // open existing substorage
157 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
160 if ( xResultSubStorage
== null )
162 m_aTestHelper
.Error( "Can't open existing substorage!" );
166 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
172 if ( !m_aTestHelper
.checkStream( xResultSubStorage
,
179 if ( !m_aTestHelper
.checkStream( xResultSubStorage
,
186 // dispose used storages to free resources
187 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
194 m_aTestHelper
.Error( "Exception: " + e
);