merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test06.java
blob0803389a1edfb5a90974c46bee1a4858725ad8ca
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 )
29 m_xMSF = xMSF;
30 m_xStorageFactory = xStorageFactory;
31 m_aTestHelper = new TestHelper( aLogWriter, "Test06: " );
34 public boolean test()
36 try
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!" );
45 return false;
48 try
50 xTempStorage.copyToStorage( null );
51 m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
52 return false;
54 catch( com.sun.star.lang.IllegalArgumentException iae )
56 catch( com.sun.star.uno.Exception ue )
58 catch( Exception e )
60 m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e );
61 return false;
64 // open new substorages
65 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
66 "SubStorage1",
67 ElementModes.WRITE );
68 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
69 "SubStorage2",
70 ElementModes.WRITE );
71 if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
73 m_aTestHelper.Error( "Can't create substorage!" );
74 return false;
77 // in case stream is open for reading it must exist
78 try
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!" );
82 return false;
84 catch( com.sun.star.uno.Exception ue )
86 catch( Exception e )
88 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e );
89 return false;
92 // in case a storage is open for reading it must exist
93 try
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!" );
97 return false;
99 catch( com.sun.star.uno.Exception ue )
101 catch( Exception e )
103 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e );
104 return false;
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!" );
112 return false;
114 catch( com.sun.star.container.NoSuchElementException ne )
116 catch( Exception e )
118 m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e );
119 return false;
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!" );
127 return false;
129 catch( com.sun.star.container.NoSuchElementException ne )
131 catch( Exception e )
133 m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e );
134 return false;
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!" );
142 return false;
144 catch( com.sun.star.container.ElementExistException ee )
146 catch( Exception e )
148 m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e );
149 return false;
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!" );
157 return false;
159 catch( com.sun.star.lang.IllegalArgumentException iae )
161 catch( com.sun.star.uno.Exception ue )
163 catch( Exception e )
165 m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e );
166 return false;
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!" );
174 return false;
176 catch( com.sun.star.lang.IllegalArgumentException iae )
178 catch( com.sun.star.uno.Exception ue )
180 catch( Exception e )
182 m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e );
183 return false;
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!" );
195 return false;
198 // open a new substorage
199 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
200 "SubStorage1",
201 ElementModes.WRITE );
202 if ( xTargetSubStorage == null )
204 m_aTestHelper.Error( "Can't create substorage!" );
205 return false;
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!" );
213 return false;
215 catch( com.sun.star.container.NoSuchElementException ne )
217 catch( Exception e )
219 m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e );
220 return false;
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!" );
228 return false;
230 catch( com.sun.star.container.NoSuchElementException ne )
232 catch( Exception e )
234 m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e );
235 return false;
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!" );
243 return false;
245 catch( com.sun.star.container.ElementExistException ee )
247 catch( Exception e )
249 m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e );
250 return false;
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!" );
258 return false;
260 catch( com.sun.star.container.ElementExistException ee )
262 catch( Exception e )
264 m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e );
265 return false;
269 return true;
271 catch( Exception e )
273 m_aTestHelper.Error( "Exception: " + e );
274 return false;