bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / Test06.java
blob7d379f1823e4e75821f6a6cb48593341fc807d30
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.storages;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
25 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
29 import com.sun.star.lang.IllegalArgumentException;
30 import com.sun.star.container.NoSuchElementException;
31 import com.sun.star.container.ElementExistException;
33 import com.sun.star.embed.*;
35 import share.LogWriter;
36 import complex.storages.TestHelper;
37 import complex.storages.StorageTest;
39 public class Test06 implements StorageTest {
41 XMultiServiceFactory m_xMSF;
42 XSingleServiceFactory m_xStorageFactory;
43 TestHelper m_aTestHelper;
45 public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
47 m_xMSF = xMSF;
48 m_xStorageFactory = xStorageFactory;
49 m_aTestHelper = new TestHelper( aLogWriter, "Test06: " );
52 public boolean test()
54 try
56 // create temporary storage based on arbitrary medium
57 // after such a storage is closed it is lost
58 Object oTempStorage = m_xStorageFactory.createInstance();
59 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
60 if ( xTempStorage == null )
62 m_aTestHelper.Error( "Can't create temporary storage representation!" );
63 return false;
66 try
68 xTempStorage.copyToStorage( null );
69 m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
70 return false;
72 catch( com.sun.star.lang.IllegalArgumentException iae )
74 catch( com.sun.star.uno.Exception ue )
76 catch( Exception e )
78 m_aTestHelper.Error( "Unexpected exception because of illegal parameter : " + e );
79 return false;
82 // open new substorages
83 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
84 "SubStorage1",
85 ElementModes.WRITE );
86 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
87 "SubStorage2",
88 ElementModes.WRITE );
89 if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
91 m_aTestHelper.Error( "Can't create substorage!" );
92 return false;
95 // in case stream is open for reading it must exist
96 try
98 xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ );
99 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
100 return false;
102 catch( com.sun.star.uno.Exception ue )
104 catch( Exception e )
106 m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e );
107 return false;
110 // in case a storage is open for reading it must exist
113 xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ );
114 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
115 return false;
117 catch( com.sun.star.uno.Exception ue )
119 catch( Exception e )
121 m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e );
122 return false;
125 // in case of removing nonexistent element an exception must be thrown
128 xTempSubStorage1.removeElement( "NonExistingElement" );
129 m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
130 return false;
132 catch( com.sun.star.container.NoSuchElementException ne )
134 catch( Exception e )
136 m_aTestHelper.Error( "Unexpected exception in case of try to remove nonexistent element : " + e );
137 return false;
140 // in case of renaming of nonexistent element an exception must be thrown
143 xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
144 m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
145 return false;
147 catch( com.sun.star.container.NoSuchElementException ne )
149 catch( Exception e )
151 m_aTestHelper.Error( "Unexpected exception in case of try to rename nonexistent element : " + e );
152 return false;
155 // in case of renaming to a name of existent element an exception must be thrown
158 xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
159 m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
160 return false;
162 catch( com.sun.star.container.ElementExistException ee )
164 catch( Exception e )
166 m_aTestHelper.Error( "Unexpected exception in case of try to rename to the name of existent element : " + e );
167 return false;
170 // in case of copying target storage must be provided
173 xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
174 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
175 return false;
177 catch( com.sun.star.lang.IllegalArgumentException iae )
179 catch( com.sun.star.uno.Exception ue )
181 catch( Exception e )
183 m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for copying : " + e );
184 return false;
187 // in case of moving target storage must be provided
190 xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
191 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
192 return false;
194 catch( com.sun.star.lang.IllegalArgumentException iae )
196 catch( com.sun.star.uno.Exception ue )
198 catch( Exception e )
200 m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for moving : " + e );
201 return false;
205 // prepare target for further testings
207 // create new temporary storage based on arbitrary medium
208 Object oTargetStorage = m_xStorageFactory.createInstance();
209 XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
210 if ( xTargetStorage == null )
212 m_aTestHelper.Error( "Can't create temporary storage representation!" );
213 return false;
216 // open a new substorage
217 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
218 "SubStorage1",
219 ElementModes.WRITE );
220 if ( xTargetSubStorage == null )
222 m_aTestHelper.Error( "Can't create substorage!" );
223 return false;
226 // in case of copying of nonexistent element an exception must be thrown
229 xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
230 m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexistent element!" );
231 return false;
233 catch( com.sun.star.container.NoSuchElementException ne )
235 catch( Exception e )
237 m_aTestHelper.Error( "Unexpected exception in case of copying of nonexistent element: " + e );
238 return false;
241 // in case of moving of nonexistent element an exception must be thrown
244 xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
245 m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexistent element!" );
246 return false;
248 catch( com.sun.star.container.NoSuchElementException ne )
250 catch( Exception e )
252 m_aTestHelper.Error( "Unexpected exception in case of moving of nonexistent element: " + e );
253 return false;
256 // in case target for copying already exists an exception must be thrown
259 xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
260 m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
261 return false;
263 catch( com.sun.star.container.ElementExistException ee )
265 catch( Exception e )
267 m_aTestHelper.Error( "Unexpected exception in case target for copying already exists: " + e );
268 return false;
271 // in case target for moving already exists an exception must be thrown
274 xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
275 m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
276 return false;
278 catch( com.sun.star.container.ElementExistException ee )
280 catch( Exception e )
282 m_aTestHelper.Error( "Unexpected exception in case target for moving already exists: " + e );
283 return false;
287 return true;
289 catch( Exception e )
291 m_aTestHelper.Error( "Exception: " + e );
292 return false;