Update ooo320-m1
[ooovba.git] / odk / examples / java / Storage / Test06.java
blob7ee3a832b5f344d83117c40ee57152514e0ff58a
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.lang.IllegalArgumentException;
12 import com.sun.star.container.NoSuchElementException;
13 import com.sun.star.container.ElementExistException;
15 import com.sun.star.embed.*;
17 import storagetesting.TestHelper;
18 import storagetesting.StorageTest;
20 public class Test06 implements StorageTest {
22 XMultiServiceFactory m_xMSF;
23 XSingleServiceFactory m_xStorageFactory;
24 TestHelper m_aTestHelper;
26 public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
28 m_xMSF = xMSF;
29 m_xStorageFactory = xStorageFactory;
30 m_aTestHelper = new TestHelper( "Test06: " );
33 public boolean test()
35 try
37 // create temporary storage based on arbitrary medium
38 // after such a storage is closed it is lost
39 Object oTempStorage = m_xStorageFactory.createInstance();
40 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
41 if ( xTempStorage == null )
43 m_aTestHelper.Error( "Can't create temporary storage representation!" );
44 return false;
47 try
49 xTempStorage.copyToStorage( null );
50 m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
51 return false;
53 catch( com.sun.star.lang.IllegalArgumentException iae )
55 catch( com.sun.star.uno.Exception ue )
57 catch( Exception e )
59 m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e );
60 return false;
63 // open new substorages
64 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
65 "SubStorage1",
66 ElementModes.ELEMENT_WRITE );
67 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
68 "SubStorage2",
69 ElementModes.ELEMENT_WRITE );
70 if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
72 m_aTestHelper.Error( "Can't create substorage!" );
73 return false;
76 // in case stream is open for reading it must exist
77 try
79 xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.ELEMENT_READ );
80 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
81 return false;
83 catch( com.sun.star.uno.Exception ue )
85 catch( Exception e )
87 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e );
88 return false;
91 // in case a storage is open for reading it must exist
92 try
94 xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.ELEMENT_READ );
95 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
96 return false;
98 catch( com.sun.star.uno.Exception ue )
100 catch( Exception e )
102 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e );
103 return false;
106 // in case of removing nonexistent element an exception must be thrown
109 xTempSubStorage1.removeElement( "NonExistingElement" );
110 m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
111 return false;
113 catch( com.sun.star.container.NoSuchElementException ne )
115 catch( Exception e )
117 m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e );
118 return false;
121 // in case of renaming of nonexistent element an exception must be thrown
124 xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
125 m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
126 return false;
128 catch( com.sun.star.container.NoSuchElementException ne )
130 catch( Exception e )
132 m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e );
133 return false;
136 // in case of renaming to a name of existent element an exception must be thrown
139 xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
140 m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
141 return false;
143 catch( com.sun.star.container.ElementExistException ee )
145 catch( Exception e )
147 m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e );
148 return false;
151 // in case of copying target storage must be provided
154 xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
155 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
156 return false;
158 catch( com.sun.star.lang.IllegalArgumentException iae )
160 catch( com.sun.star.uno.Exception ue )
162 catch( Exception e )
164 m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e );
165 return false;
168 // in case of moving target storage must be provided
171 xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
172 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
173 return false;
175 catch( com.sun.star.lang.IllegalArgumentException iae )
177 catch( com.sun.star.uno.Exception ue )
179 catch( Exception e )
181 m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e );
182 return false;
186 // prepare target for further testings
188 // create new temporary storage based on arbitrary medium
189 Object oTargetStorage = m_xStorageFactory.createInstance();
190 XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
191 if ( xTargetStorage == null )
193 m_aTestHelper.Error( "Can't create temporary storage representation!" );
194 return false;
197 // open a new substorage
198 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
199 "SubStorage1",
200 ElementModes.ELEMENT_WRITE );
201 if ( xTargetSubStorage == null )
203 m_aTestHelper.Error( "Can't create substorage!" );
204 return false;
207 // in case of copying of nonexistent element an exception must be thrown
210 xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
211 m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" );
212 return false;
214 catch( com.sun.star.container.NoSuchElementException ne )
216 catch( Exception e )
218 m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e );
219 return false;
222 // in case of moving of nonexistent element an exception must be thrown
225 xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
226 m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" );
227 return false;
229 catch( com.sun.star.container.NoSuchElementException ne )
231 catch( Exception e )
233 m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e );
234 return false;
237 // in case target for copying already exists an exception must be thrown
240 xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
241 m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
242 return false;
244 catch( com.sun.star.container.ElementExistException ee )
246 catch( Exception e )
248 m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e );
249 return false;
252 // in case target for moving already exists an exception must be thrown
255 xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
256 m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
257 return false;
259 catch( com.sun.star.container.ElementExistException ee )
261 catch( Exception e )
263 m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e );
264 return false;
268 return true;
270 catch( Exception e )
272 m_aTestHelper.Error( "Exception: " + e );
273 return false;