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
.lang
.IllegalArgumentException
;
12 import com
.sun
.star
.container
.NoSuchElementException
;
13 import com
.sun
.star
.container
.ElementExistException
;
15 import com
.sun
.star
.embed
.*;
17 import share
.LogWriter
;
18 import complex
.storages
.TestHelper
;
19 import complex
.storages
.StorageTest
;
21 public class Test06
implements StorageTest
{
23 XMultiServiceFactory m_xMSF
;
24 XSingleServiceFactory m_xStorageFactory
;
25 TestHelper m_aTestHelper
;
27 public Test06( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
30 m_xStorageFactory
= xStorageFactory
;
31 m_aTestHelper
= new TestHelper( aLogWriter
, "Test06: " );
38 // create temporary storage based on arbitrary medium
39 // after such a storage is closed it is lost
40 Object oTempStorage
= m_xStorageFactory
.createInstance();
41 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
42 if ( xTempStorage
== null )
44 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
50 xTempStorage
.copyToStorage( null );
51 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
54 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
56 catch( com
.sun
.star
.uno
.Exception ue
)
60 m_aTestHelper
.Error( "Unexpected excepion because of illegal parameter : " + e
);
64 // open new substorages
65 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
68 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
71 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
73 m_aTestHelper
.Error( "Can't create substorage!" );
77 // in case stream is open for reading it must exist
80 xTempSubStorage1
.openStreamElement( "NonExistingStream", ElementModes
.READ
);
81 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
84 catch( com
.sun
.star
.uno
.Exception ue
)
88 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e
);
92 // in case a storage is open for reading it must exist
95 xTempSubStorage1
.openStreamElement( "NonExistingStorage", ElementModes
.READ
);
96 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
99 catch( com
.sun
.star
.uno
.Exception ue
)
103 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e
);
107 // in case of removing nonexistent element an exception must be thrown
110 xTempSubStorage1
.removeElement( "NonExistingElement" );
111 m_aTestHelper
.Error( "An exception must be thrown in case of removing nonexistent element!" );
114 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
118 m_aTestHelper
.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e
);
122 // in case of renaming of nonexistent element an exception must be thrown
125 xTempSubStorage1
.renameElement( "NonExistingElement", "NewName" );
126 m_aTestHelper
.Error( "An exception must be thrown in case of renaming nonexistent element!" );
129 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
133 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e
);
137 // in case of renaming to a name of existent element an exception must be thrown
140 xTempStorage
.renameElement( "SubStorage1", "SubStorage2" );
141 m_aTestHelper
.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
144 catch( com
.sun
.star
.container
.ElementExistException ee
)
148 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e
);
152 // in case of copying target storage must be provided
155 xTempStorage
.copyElementTo( "SubStorage1", null, "SubStorage1" );
156 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
159 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
161 catch( com
.sun
.star
.uno
.Exception ue
)
165 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e
);
169 // in case of moving target storage must be provided
172 xTempStorage
.moveElementTo( "SubStorage1", null, "SubStorage1" );
173 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
176 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
178 catch( com
.sun
.star
.uno
.Exception ue
)
182 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e
);
187 // prepare target for further testings
189 // create new temporary storage based on arbitrary medium
190 Object oTargetStorage
= m_xStorageFactory
.createInstance();
191 XStorage xTargetStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTargetStorage
);
192 if ( xTargetStorage
== null )
194 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
198 // open a new substorage
199 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
201 ElementModes
.WRITE
);
202 if ( xTargetSubStorage
== null )
204 m_aTestHelper
.Error( "Can't create substorage!" );
208 // in case of copying of nonexistent element an exception must be thrown
211 xTempStorage
.copyElementTo( "Nonexistent element", xTargetStorage
, "Target" );
212 m_aTestHelper
.Error( "An exception must be thrown in case of copying of nonexisting element!" );
215 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
219 m_aTestHelper
.Error( "Unexpected excepion in case of copying of nonexistent element: " + e
);
223 // in case of moving of nonexistent element an exception must be thrown
226 xTempStorage
.moveElementTo( "Nonexistent element", xTargetStorage
, "Target" );
227 m_aTestHelper
.Error( "An exception must be thrown in case of moving of nonexisting element!" );
230 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
234 m_aTestHelper
.Error( "Unexpected excepion in case of moving of nonexistent element: " + e
);
238 // in case target for copying already exists an exception must be thrown
241 xTempStorage
.copyElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
242 m_aTestHelper
.Error( "An exception must be thrown in case target for copying already exists!" );
245 catch( com
.sun
.star
.container
.ElementExistException ee
)
249 m_aTestHelper
.Error( "Unexpected excepion in case target for copying already exists: " + e
);
253 // in case target for moving already exists an exception must be thrown
256 xTempStorage
.moveElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
257 m_aTestHelper
.Error( "An exception must be thrown in case target for moving already exists!" );
260 catch( com
.sun
.star
.container
.ElementExistException ee
)
264 m_aTestHelper
.Error( "Unexpected excepion in case target for moving already exists: " + e
);
273 m_aTestHelper
.Error( "Exception: " + e
);