1 package storagetesting
;
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 storagetesting
.TestHelper
;
15 import storagetesting
.StorageTest
;
17 public class Test03
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test03( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( "Test03: " );
34 // create temporary storage based on arbitrary medium
35 // after such a storage is closed it is lost
36 Object oTempStorage
= m_xStorageFactory
.createInstance();
37 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
38 if ( xTempStorage
== null )
40 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
44 // open a new substorage
45 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
47 ElementModes
.ELEMENT_WRITE
);
48 if ( xTempSubStorage
== null )
50 m_aTestHelper
.Error( "Can't create substorage!" );
54 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
56 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
57 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
60 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
62 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
63 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
66 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
67 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
70 ElementModes
.ELEMENT_WRITE
) )
73 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
76 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
79 // ================================================
80 // check storage hyerarchy tree
81 // ================================================
83 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
85 xTempStorage
.isStorageElement( "does not exist" );
86 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
89 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
94 m_aTestHelper
.Error( "Wrong exception is thrown by isStorageElement() call: " + e
);
99 xTempStorage
.isStreamElement( "does not exist" );
100 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
103 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
108 m_aTestHelper
.Error( "Wrong exception is thrown by isStreamElement() call: " + e
);
112 XNameAccess xRootNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xTempStorage
);
113 if ( xRootNameAccess
== null )
115 m_aTestHelper
.Error( "Root storage doesn't support XNameAccess!" );
120 if ( !xTempStorage
.isStorageElement( "SubStorage1" ) || xTempStorage
.isStreamElement( "SubStorage1" ) )
122 m_aTestHelper
.Error( "Child 'SubStorage1' can not be detected as storage!" );
126 if ( xTempStorage
.isStorageElement( "SubStream1" ) || !xTempStorage
.isStreamElement( "SubStream1" ) )
128 m_aTestHelper
.Error( "Child 'SubStream1' can not be detected as stream!" );
134 m_aTestHelper
.Error( "Child's type can not be detected, exception: " + e
);
139 // check that root storage contents are represented correctly
140 String sRootCont
[] = xRootNameAccess
.getElementNames();
142 if ( sRootCont
.length
!= 2 )
144 m_aTestHelper
.Error( "Root storage contains wrong amount of children!" );
148 if ( !( sRootCont
[0].equals( "SubStorage1" ) && sRootCont
[1].equals( "SubStream1" )
149 || sRootCont
[0].equals( "SubStream1" ) && sRootCont
[1].equals( "SubStorage1" ) )
150 || !( xRootNameAccess
.hasByName( "SubStream1" ) && xRootNameAccess
.hasByName( "SubStorage1" ) ) )
152 m_aTestHelper
.Error( "Root storage contains wrong list of children!" );
156 // get storage through XNameAccess
157 XStorage xResultSubStorage
= getStorageFromNameAccess( xRootNameAccess
, "SubStorage1" );
158 if ( xResultSubStorage
== null )
161 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType3", false, ElementModes
.ELEMENT_READ
) )
164 XNameAccess xChildAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResultSubStorage
);
165 if ( xChildAccess
== null )
167 m_aTestHelper
.Error( "Child storage doesn't support XNameAccess!" );
171 if ( !xChildAccess
.hasByName( "SubStream2" )
172 || !xResultSubStorage
.isStreamElement( "SubStream2" )
173 || xResultSubStorage
.isStorageElement( "SubStream2" ) )
175 m_aTestHelper
.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
183 m_aTestHelper
.Error( "Exception: " + e
);
188 public XStorage
getStorageFromNameAccess( XNameAccess xAccess
, String sName
)
192 Object oStorage
= xAccess
.getByName( sName
);
193 XStorage xResult
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
195 if ( xResult
!= null )
198 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess!" );
202 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess, exception: " + e
);