Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / package / qa / ofopxmlstorages / Test06.java
blob6817134d32ada757d083da54a55f661b313abaa2
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.ofopxmlstorages;
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.ofopxmlstorages.TestHelper;
37 import complex.ofopxmlstorages.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 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
59 if ( xTempStorage == null )
61 m_aTestHelper.Error( "Can't create temporary storage representation!" );
62 return false;
65 try
67 xTempStorage.copyToStorage( null );
68 m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
69 return false;
71 catch( com.sun.star.lang.IllegalArgumentException iae )
73 catch( com.sun.star.uno.Exception ue )
75 catch( Exception e )
77 m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e );
78 return false;
81 // open new substorages
82 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
83 "SubStorage1",
84 ElementModes.WRITE );
85 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
86 "SubStorage2",
87 ElementModes.WRITE );
88 if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
90 m_aTestHelper.Error( "Can't create substorage!" );
91 return false;
94 // in case stream is open for reading it must exist
95 try
97 xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ );
98 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
99 return false;
101 catch( com.sun.star.uno.Exception ue )
103 catch( Exception e )
105 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e );
106 return false;
109 // in case a storage is open for reading it must exist
112 xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ );
113 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
114 return false;
116 catch( com.sun.star.uno.Exception ue )
118 catch( Exception e )
120 m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e );
121 return false;
124 // in case of removing nonexistent element an exception must be thrown
127 xTempSubStorage1.removeElement( "NonExistingElement" );
128 m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
129 return false;
131 catch( com.sun.star.container.NoSuchElementException ne )
133 catch( Exception e )
135 m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e );
136 return false;
139 // in case of renaming of nonexistent element an exception must be thrown
142 xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
143 m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
144 return false;
146 catch( com.sun.star.container.NoSuchElementException ne )
148 catch( Exception e )
150 m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e );
151 return false;
154 // in case of renaming to a name of existent element an exception must be thrown
157 xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
158 m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
159 return false;
161 catch( com.sun.star.container.ElementExistException ee )
163 catch( Exception e )
165 m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e );
166 return false;
169 // in case of copying target storage must be provided
172 xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
173 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
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 copying : " + e );
183 return false;
186 // in case of moving target storage must be provided
189 xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
190 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
191 return false;
193 catch( com.sun.star.lang.IllegalArgumentException iae )
195 catch( com.sun.star.uno.Exception ue )
197 catch( Exception e )
199 m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e );
200 return false;
204 // prepare target for further testings
206 // create new temporary storage based on arbitrary medium
207 XStorage xTargetStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
208 if ( xTargetStorage == null )
210 m_aTestHelper.Error( "Can't create temporary storage representation!" );
211 return false;
214 // open a new substorage
215 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
216 "SubStorage1",
217 ElementModes.WRITE );
218 if ( xTargetSubStorage == null )
220 m_aTestHelper.Error( "Can't create substorage!" );
221 return false;
224 // in case of copying of nonexistent element an exception must be thrown
227 xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
228 m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" );
229 return false;
231 catch( com.sun.star.container.NoSuchElementException ne )
233 catch( Exception e )
235 m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e );
236 return false;
239 // in case of moving of nonexistent element an exception must be thrown
242 xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
243 m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" );
244 return false;
246 catch( com.sun.star.container.NoSuchElementException ne )
248 catch( Exception e )
250 m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e );
251 return false;
254 // in case target for copying already exists an exception must be thrown
257 xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
258 m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
259 return false;
261 catch( com.sun.star.container.ElementExistException ee )
263 catch( Exception e )
265 m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e );
266 return false;
269 // in case target for moving already exists an exception must be thrown
272 xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
273 m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
274 return false;
276 catch( com.sun.star.container.ElementExistException ee )
278 catch( Exception e )
280 m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e );
281 return false;
285 return true;
287 catch( Exception e )
289 m_aTestHelper.Error( "Exception: " + e );
290 return false;