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
.*;
12 import com
.sun
.star
.container
.XNameAccess
;
14 import share
.LogWriter
;
15 import complex
.storages
.TestHelper
;
16 import complex
.storages
.StorageTest
;
18 public class Test03
implements StorageTest
{
20 XMultiServiceFactory m_xMSF
;
21 XSingleServiceFactory m_xStorageFactory
;
22 TestHelper m_aTestHelper
;
24 public Test03( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
27 m_xStorageFactory
= xStorageFactory
;
28 m_aTestHelper
= new TestHelper( aLogWriter
, "Test03: " );
35 // create temporary storage based on arbitrary medium
36 // after such a storage is closed it is lost
37 Object oTempStorage
= m_xStorageFactory
.createInstance();
38 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
39 if ( xTempStorage
== null )
41 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
45 // open a new substorage
46 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
49 if ( xTempSubStorage
== null )
51 m_aTestHelper
.Error( "Can't create substorage!" );
55 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
57 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
58 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
61 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
63 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
64 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
67 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
68 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
71 ElementModes
.WRITE
) )
74 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
77 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
80 // ================================================
81 // check storage hyerarchy tree
82 // ================================================
84 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
86 xTempStorage
.isStorageElement( "does not exist" );
87 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
90 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
95 m_aTestHelper
.Error( "Wrong exception is thrown by isStorageElement() call: " + e
);
100 xTempStorage
.isStreamElement( "does not exist" );
101 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
104 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
109 m_aTestHelper
.Error( "Wrong exception is thrown by isStreamElement() call: " + e
);
113 XNameAccess xRootNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xTempStorage
);
114 if ( xRootNameAccess
== null )
116 m_aTestHelper
.Error( "Root storage doesn't support XNameAccess!" );
121 if ( !xTempStorage
.isStorageElement( "SubStorage1" ) || xTempStorage
.isStreamElement( "SubStorage1" ) )
123 m_aTestHelper
.Error( "Child 'SubStorage1' can not be detected as storage!" );
127 if ( xTempStorage
.isStorageElement( "SubStream1" ) || !xTempStorage
.isStreamElement( "SubStream1" ) )
129 m_aTestHelper
.Error( "Child 'SubStream1' can not be detected as stream!" );
135 m_aTestHelper
.Error( "Child's type can not be detected, exception: " + e
);
140 // check that root storage contents are represented correctly
141 String sRootCont
[] = xRootNameAccess
.getElementNames();
143 if ( sRootCont
.length
!= 2 )
145 m_aTestHelper
.Error( "Root storage contains wrong amount of children!" );
149 if ( !( sRootCont
[0].equals( "SubStorage1" ) && sRootCont
[1].equals( "SubStream1" )
150 || sRootCont
[0].equals( "SubStream1" ) && sRootCont
[1].equals( "SubStorage1" ) )
151 || !( xRootNameAccess
.hasByName( "SubStream1" ) && xRootNameAccess
.hasByName( "SubStorage1" ) ) )
153 m_aTestHelper
.Error( "Root storage contains wrong list of children!" );
157 // get storage through XNameAccess
158 XStorage xResultSubStorage
= getStorageFromNameAccess( xRootNameAccess
, "SubStorage1" );
159 if ( xResultSubStorage
== null )
162 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType3", false, ElementModes
.READ
) )
165 XNameAccess xChildAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResultSubStorage
);
166 if ( xChildAccess
== null )
168 m_aTestHelper
.Error( "Child storage doesn't support XNameAccess!" );
172 if ( !xChildAccess
.hasByName( "SubStream2" )
173 || !xResultSubStorage
.isStreamElement( "SubStream2" )
174 || xResultSubStorage
.isStorageElement( "SubStream2" ) )
176 m_aTestHelper
.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
184 m_aTestHelper
.Error( "Exception: " + e
);
189 public XStorage
getStorageFromNameAccess( XNameAccess xAccess
, String sName
)
193 Object oStorage
= xAccess
.getByName( sName
);
194 XStorage xResult
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
196 if ( xResult
!= null )
199 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess!" );
203 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess, exception: " + e
);