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
;
10 import com
.sun
.star
.io
.XStream
;
11 import com
.sun
.star
.io
.XInputStream
;
13 import com
.sun
.star
.embed
.*;
14 import com
.sun
.star
.beans
.StringPair
;
16 import share
.LogWriter
;
17 import complex
.ofopxmlstorages
.TestHelper
;
18 import complex
.ofopxmlstorages
.StorageTest
;
20 public class Test02
implements StorageTest
{
22 XMultiServiceFactory m_xMSF
;
23 XSingleServiceFactory m_xStorageFactory
;
24 TestHelper m_aTestHelper
;
26 public Test02( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
29 m_xStorageFactory
= xStorageFactory
;
30 m_aTestHelper
= new TestHelper( aLogWriter
, "Test02: " );
37 StringPair
[][] aRelations
=
38 { { new StringPair( "Id", "Num1" ) },
39 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
40 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
41 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
42 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
43 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
44 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
48 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
49 if ( xTempFileStream
== null )
52 // create storage based on the temporary stream
53 XStorage xTempStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
56 if ( xTempStorage
== null )
58 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
62 // open a new substorage
63 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
66 if ( xTempSubStorage
== null )
68 m_aTestHelper
.Error( "Can't create substorage!" );
72 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
74 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
75 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
83 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
90 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
91 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
97 // commit substorage first
98 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
101 // commit the root storage so the contents must be stored now
102 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
105 // dispose used storage to free resources
106 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
110 // ================================================
111 // now check all the written information
112 // ================================================
114 // close the output part of the temporary stream
115 // the output part must present since we already wrote to the stream
116 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
119 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
120 if ( xTempInStream
== null )
125 XStorage xResultStorage
= m_aTestHelper
.createStorageFromInputStream( m_xStorageFactory
, xTempInStream
);
126 if ( xResultStorage
== null )
128 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
132 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, true, ElementModes
.READ
, aRelations
) )
135 // open existing substorage
136 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
139 if ( xResultSubStorage
== null )
141 m_aTestHelper
.Error( "Can't open existing substorage!" );
145 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
151 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", pBytes1
, aRelations
) )
158 m_aTestHelper
.Error( "Exception: " + e
);