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
.container
.XNameAccess
;
13 import com
.sun
.star
.beans
.StringPair
;
15 import share
.LogWriter
;
16 import complex
.ofopxmlstorages
.TestHelper
;
17 import complex
.ofopxmlstorages
.StorageTest
;
19 public class Test03
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public Test03( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "Test03: " );
36 StringPair
[][] aRelations
=
37 { { new StringPair( "Id", "Num1" ) },
38 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
39 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
40 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
41 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
42 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
43 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
46 // create temporary storage based on arbitrary medium
47 // after such a storage is closed it is lost
48 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
49 if ( xTempStorage
== null )
51 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
55 // open a new substorage
56 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
59 if ( xTempSubStorage
== null )
61 m_aTestHelper
.Error( "Can't create substorage!" );
65 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
67 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
68 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
,
76 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
78 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
79 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
87 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
94 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
97 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
100 // ================================================
101 // check storage hyerarchy tree
102 // ================================================
104 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
106 xTempStorage
.isStorageElement( "does not exist" );
107 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
110 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
115 m_aTestHelper
.Error( "Wrong exception is thrown by isStorageElement() call: " + e
);
120 xTempStorage
.isStreamElement( "does not exist" );
121 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
124 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
129 m_aTestHelper
.Error( "Wrong exception is thrown by isStreamElement() call: " + e
);
133 XNameAccess xRootNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xTempStorage
);
134 if ( xRootNameAccess
== null )
136 m_aTestHelper
.Error( "Root storage doesn't support XNameAccess!" );
141 if ( !xTempStorage
.isStorageElement( "SubStorage1" ) || xTempStorage
.isStreamElement( "SubStorage1" ) )
143 m_aTestHelper
.Error( "Child 'SubStorage1' can not be detected as storage!" );
147 if ( xTempStorage
.isStorageElement( "SubStream1" ) || !xTempStorage
.isStreamElement( "SubStream1" ) )
149 m_aTestHelper
.Error( "Child 'SubStream1' can not be detected as stream!" );
155 m_aTestHelper
.Error( "Child's type can not be detected, exception: " + e
);
160 // check that root storage contents are represented correctly
161 String sRootCont
[] = xRootNameAccess
.getElementNames();
163 if ( sRootCont
.length
!= 2 )
165 m_aTestHelper
.Error( "Root storage contains wrong amount of children!" );
169 if ( !( sRootCont
[0].equals( "SubStorage1" ) && sRootCont
[1].equals( "SubStream1" )
170 || sRootCont
[0].equals( "SubStream1" ) && sRootCont
[1].equals( "SubStorage1" ) )
171 || !( xRootNameAccess
.hasByName( "SubStream1" ) && xRootNameAccess
.hasByName( "SubStorage1" ) ) )
173 m_aTestHelper
.Error( "Root storage contains wrong list of children!" );
177 // get storage through XNameAccess
178 XStorage xResultSubStorage
= getStorageFromNameAccess( xRootNameAccess
, "SubStorage1" );
179 if ( xResultSubStorage
== null )
182 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
188 XNameAccess xChildAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResultSubStorage
);
189 if ( xChildAccess
== null )
191 m_aTestHelper
.Error( "Child storage doesn't support XNameAccess!" );
195 if ( !xChildAccess
.hasByName( "SubStream2" )
196 || !xResultSubStorage
.isStreamElement( "SubStream2" )
197 || xResultSubStorage
.isStorageElement( "SubStream2" ) )
199 m_aTestHelper
.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
207 m_aTestHelper
.Error( "Exception: " + e
);
212 public XStorage
getStorageFromNameAccess( XNameAccess xAccess
, String sName
)
216 Object oStorage
= xAccess
.getByName( sName
);
217 XStorage xResult
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
219 if ( xResult
!= null )
222 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess!" );
226 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess, exception: " + e
);