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 pBigBytes
[] = new byte[33000];
56 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
57 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
59 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
60 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
) )
63 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
64 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "BigSubStream2", "MediaType2", false, pBigBytes
) )
67 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
73 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes2
) )
79 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
80 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
83 ElementModes
.WRITE
) )
86 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
89 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
92 // ================================================
93 // check storage hyerarchy tree
94 // ================================================
96 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
98 xTempStorage
.isStorageElement( "does not exist" );
99 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
102 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
107 m_aTestHelper
.Error( "Wrong exception is thrown by isStorageElement() call: " + e
);
112 xTempStorage
.isStreamElement( "does not exist" );
113 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
116 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
121 m_aTestHelper
.Error( "Wrong exception is thrown by isStreamElement() call: " + e
);
125 XNameAccess xRootNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xTempStorage
);
126 if ( xRootNameAccess
== null )
128 m_aTestHelper
.Error( "Root storage doesn't support XNameAccess!" );
133 if ( !xTempStorage
.isStorageElement( "SubStorage1" ) || xTempStorage
.isStreamElement( "SubStorage1" ) )
135 m_aTestHelper
.Error( "Child 'SubStorage1' can not be detected as storage!" );
139 if ( xTempStorage
.isStorageElement( "SubStream1" ) || !xTempStorage
.isStreamElement( "SubStream1" ) )
141 m_aTestHelper
.Error( "Child 'SubStream1' can not be detected as stream!" );
147 m_aTestHelper
.Error( "Child's type can not be detected, exception: " + e
);
152 // check that root storage contents are represented correctly
153 String sRootCont
[] = xRootNameAccess
.getElementNames();
155 if ( sRootCont
.length
!= 3 )
157 m_aTestHelper
.Error( "Root storage contains wrong amount of children!" );
162 for ( int nInd
= 0; nInd
< sRootCont
.length
; nInd
++ )
164 if ( sRootCont
[nInd
].equals( "SubStorage1" ) )
166 else if ( sRootCont
[nInd
].equals( "SubStream1" ) )
168 else if ( sRootCont
[nInd
].equals( "BigSubStream1" ) )
172 if ( nFlag
!= 7 || !( xRootNameAccess
.hasByName( "BigSubStream1" ) && xRootNameAccess
.hasByName( "SubStream1" ) && xRootNameAccess
.hasByName( "SubStorage1" ) ) )
174 m_aTestHelper
.Error( "Root storage contains wrong list of children!" );
178 // get storage through XNameAccess
179 XStorage xResultSubStorage
= getStorageFromNameAccess( xRootNameAccess
, "SubStorage1" );
180 if ( xResultSubStorage
== null )
183 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType3", false, ElementModes
.READ
) )
186 XNameAccess xChildAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResultSubStorage
);
187 if ( xChildAccess
== null )
189 m_aTestHelper
.Error( "Child storage doesn't support XNameAccess!" );
193 if ( !( xChildAccess
.hasByName( "SubStream2" ) && xChildAccess
.hasByName( "BigSubStream2" ) )
194 || !xResultSubStorage
.isStreamElement( "SubStream2" )
195 || !xResultSubStorage
.isStreamElement( "BigSubStream2" ) )
197 m_aTestHelper
.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
205 m_aTestHelper
.Error( "Exception: " + e
);
210 public XStorage
getStorageFromNameAccess( XNameAccess xAccess
, String sName
)
214 Object oStorage
= xAccess
.getByName( sName
);
215 XStorage xResult
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
217 if ( xResult
!= null )
220 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess!" );
224 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess, exception: " + e
);