xref: /AOO41X/main/package/qa/ofopxmlstorages/Test06.java (revision a740f2aac71e58ccad9369fb423cc251ef909663)
1*a740f2aaSAndrew Rist /**************************************************************
2*a740f2aaSAndrew Rist  *
3*a740f2aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a740f2aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a740f2aaSAndrew Rist  * distributed with this work for additional information
6*a740f2aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a740f2aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a740f2aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*a740f2aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a740f2aaSAndrew Rist  *
11*a740f2aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a740f2aaSAndrew Rist  *
13*a740f2aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a740f2aaSAndrew Rist  * software distributed under the License is distributed on an
15*a740f2aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a740f2aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a740f2aaSAndrew Rist  * specific language governing permissions and limitations
18*a740f2aaSAndrew Rist  * under the License.
19*a740f2aaSAndrew Rist  *
20*a740f2aaSAndrew Rist  *************************************************************/
21*a740f2aaSAndrew Rist 
22cdf0e10cSrcweir package complex.ofopxmlstorages;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.uno.XInterface;
25cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
26cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.XInterface;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException;
33cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException;
34cdf0e10cSrcweir import com.sun.star.container.ElementExistException;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import com.sun.star.embed.*;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir import share.LogWriter;
39cdf0e10cSrcweir import complex.ofopxmlstorages.TestHelper;
40cdf0e10cSrcweir import complex.ofopxmlstorages.StorageTest;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir public class Test06 implements StorageTest {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	XMultiServiceFactory m_xMSF;
45cdf0e10cSrcweir 	XSingleServiceFactory m_xStorageFactory;
46cdf0e10cSrcweir 	TestHelper m_aTestHelper;
47cdf0e10cSrcweir 
Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )48cdf0e10cSrcweir 	public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		m_xMSF = xMSF;
51cdf0e10cSrcweir 		m_xStorageFactory = xStorageFactory;
52cdf0e10cSrcweir 		m_aTestHelper = new TestHelper( aLogWriter, "Test06: " );
53cdf0e10cSrcweir 	}
54cdf0e10cSrcweir 
test()55cdf0e10cSrcweir     public boolean test()
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		try
58cdf0e10cSrcweir 		{
59cdf0e10cSrcweir 			// create temporary storage based on arbitrary medium
60cdf0e10cSrcweir 			// after such a storage is closed it is lost
61cdf0e10cSrcweir 			XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
62cdf0e10cSrcweir 			if ( xTempStorage == null )
63cdf0e10cSrcweir 			{
64cdf0e10cSrcweir 				m_aTestHelper.Error( "Can't create temporary storage representation!" );
65cdf0e10cSrcweir 				return false;
66cdf0e10cSrcweir 			}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			try
69cdf0e10cSrcweir 			{
70cdf0e10cSrcweir 				xTempStorage.copyToStorage( null );
71cdf0e10cSrcweir 				m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
72cdf0e10cSrcweir 				return false;
73cdf0e10cSrcweir 			}
74cdf0e10cSrcweir 			catch( com.sun.star.lang.IllegalArgumentException iae )
75cdf0e10cSrcweir 			{}
76cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception ue )
77cdf0e10cSrcweir 			{}
78cdf0e10cSrcweir 			catch( Exception e )
79cdf0e10cSrcweir 			{
80cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e );
81cdf0e10cSrcweir 				return false;
82cdf0e10cSrcweir 			}
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			// open new substorages
85cdf0e10cSrcweir 			XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
86cdf0e10cSrcweir 																	"SubStorage1",
87cdf0e10cSrcweir 																	ElementModes.WRITE );
88cdf0e10cSrcweir 			XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
89cdf0e10cSrcweir 																	"SubStorage2",
90cdf0e10cSrcweir 																	ElementModes.WRITE );
91cdf0e10cSrcweir 			if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
92cdf0e10cSrcweir 			{
93cdf0e10cSrcweir 				m_aTestHelper.Error( "Can't create substorage!" );
94cdf0e10cSrcweir 				return false;
95cdf0e10cSrcweir 			}
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 			// in case stream is open for reading it must exist
98cdf0e10cSrcweir 			try
99cdf0e10cSrcweir 			{
100cdf0e10cSrcweir 				xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ );
101cdf0e10cSrcweir 				m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
102cdf0e10cSrcweir 				return false;
103cdf0e10cSrcweir 			}
104cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception ue )
105cdf0e10cSrcweir 			{}
106cdf0e10cSrcweir 			catch( Exception e )
107cdf0e10cSrcweir 			{
108cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e );
109cdf0e10cSrcweir 				return false;
110cdf0e10cSrcweir 			}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 			// in case a storage is open for reading it must exist
113cdf0e10cSrcweir 			try
114cdf0e10cSrcweir 			{
115cdf0e10cSrcweir 				xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ );
116cdf0e10cSrcweir 				m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
117cdf0e10cSrcweir 				return false;
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception ue )
120cdf0e10cSrcweir 			{}
121cdf0e10cSrcweir 			catch( Exception e )
122cdf0e10cSrcweir 			{
123cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e );
124cdf0e10cSrcweir 				return false;
125cdf0e10cSrcweir 			}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 			// in case of removing nonexistent element an exception must be thrown
128cdf0e10cSrcweir 			try
129cdf0e10cSrcweir 			{
130cdf0e10cSrcweir 				xTempSubStorage1.removeElement( "NonExistingElement" );
131cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
132cdf0e10cSrcweir 				return false;
133cdf0e10cSrcweir 			}
134cdf0e10cSrcweir 			catch( com.sun.star.container.NoSuchElementException ne )
135cdf0e10cSrcweir 			{}
136cdf0e10cSrcweir 			catch( Exception e )
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e );
139cdf0e10cSrcweir 				return false;
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			// in case of renaming of nonexistent element an exception must be thrown
143cdf0e10cSrcweir 			try
144cdf0e10cSrcweir 			{
145cdf0e10cSrcweir 				xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
146cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
147cdf0e10cSrcweir 				return false;
148cdf0e10cSrcweir 			}
149cdf0e10cSrcweir 			catch( com.sun.star.container.NoSuchElementException ne )
150cdf0e10cSrcweir 			{}
151cdf0e10cSrcweir 			catch( Exception e )
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e );
154cdf0e10cSrcweir 				return false;
155cdf0e10cSrcweir 			}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 			// in case of renaming to a name of existent element an exception must be thrown
158cdf0e10cSrcweir 			try
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
161cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
162cdf0e10cSrcweir 				return false;
163cdf0e10cSrcweir 			}
164cdf0e10cSrcweir 			catch( com.sun.star.container.ElementExistException ee )
165cdf0e10cSrcweir 			{}
166cdf0e10cSrcweir 			catch( Exception e )
167cdf0e10cSrcweir 			{
168cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e );
169cdf0e10cSrcweir 				return false;
170cdf0e10cSrcweir 			}
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 			// in case of copying target storage must be provided
173cdf0e10cSrcweir 			try
174cdf0e10cSrcweir 			{
175cdf0e10cSrcweir 				xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
176cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
177cdf0e10cSrcweir 				return false;
178cdf0e10cSrcweir 			}
179cdf0e10cSrcweir 			catch( com.sun.star.lang.IllegalArgumentException iae )
180cdf0e10cSrcweir 			{}
181cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception ue )
182cdf0e10cSrcweir 			{}
183cdf0e10cSrcweir 			catch( Exception e )
184cdf0e10cSrcweir 			{
185cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e );
186cdf0e10cSrcweir 				return false;
187cdf0e10cSrcweir 			}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			// in case of moving target storage must be provided
190cdf0e10cSrcweir 			try
191cdf0e10cSrcweir 			{
192cdf0e10cSrcweir 				xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
193cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
194cdf0e10cSrcweir 				return false;
195cdf0e10cSrcweir 			}
196cdf0e10cSrcweir 			catch( com.sun.star.lang.IllegalArgumentException iae )
197cdf0e10cSrcweir 			{}
198cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception ue )
199cdf0e10cSrcweir 			{}
200cdf0e10cSrcweir 			catch( Exception e )
201cdf0e10cSrcweir 			{
202cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e );
203cdf0e10cSrcweir 				return false;
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 			// prepare target for further testings
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 			// create new temporary storage based on arbitrary medium
210cdf0e10cSrcweir 			XStorage xTargetStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
211cdf0e10cSrcweir 			if ( xTargetStorage == null )
212cdf0e10cSrcweir 			{
213cdf0e10cSrcweir 				m_aTestHelper.Error( "Can't create temporary storage representation!" );
214cdf0e10cSrcweir 				return false;
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 			// open a new substorage
218cdf0e10cSrcweir 			XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
219cdf0e10cSrcweir 																	"SubStorage1",
220cdf0e10cSrcweir 																	ElementModes.WRITE );
221cdf0e10cSrcweir 			if ( xTargetSubStorage == null )
222cdf0e10cSrcweir 			{
223cdf0e10cSrcweir 				m_aTestHelper.Error( "Can't create substorage!" );
224cdf0e10cSrcweir 				return false;
225cdf0e10cSrcweir 			}
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 			// in case of copying of nonexistent element an exception must be thrown
228cdf0e10cSrcweir 			try
229cdf0e10cSrcweir 			{
230cdf0e10cSrcweir 				xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
231cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" );
232cdf0e10cSrcweir 				return false;
233cdf0e10cSrcweir 			}
234cdf0e10cSrcweir 			catch( com.sun.star.container.NoSuchElementException ne )
235cdf0e10cSrcweir 			{}
236cdf0e10cSrcweir 			catch( Exception e )
237cdf0e10cSrcweir 			{
238cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e );
239cdf0e10cSrcweir 				return false;
240cdf0e10cSrcweir 			}
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 			// in case of moving of nonexistent element an exception must be thrown
243cdf0e10cSrcweir 			try
244cdf0e10cSrcweir 			{
245cdf0e10cSrcweir 				xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
246cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" );
247cdf0e10cSrcweir 				return false;
248cdf0e10cSrcweir 			}
249cdf0e10cSrcweir 			catch( com.sun.star.container.NoSuchElementException ne )
250cdf0e10cSrcweir 			{}
251cdf0e10cSrcweir 			catch( Exception e )
252cdf0e10cSrcweir 			{
253cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e );
254cdf0e10cSrcweir 				return false;
255cdf0e10cSrcweir 			}
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 			// in case target for copying already exists an exception must be thrown
258cdf0e10cSrcweir 			try
259cdf0e10cSrcweir 			{
260cdf0e10cSrcweir 				xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
261cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
262cdf0e10cSrcweir 				return false;
263cdf0e10cSrcweir 			}
264cdf0e10cSrcweir 			catch( com.sun.star.container.ElementExistException ee )
265cdf0e10cSrcweir 			{}
266cdf0e10cSrcweir 			catch( Exception e )
267cdf0e10cSrcweir 			{
268cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e );
269cdf0e10cSrcweir 				return false;
270cdf0e10cSrcweir 			}
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 			// in case target for moving already exists an exception must be thrown
273cdf0e10cSrcweir 			try
274cdf0e10cSrcweir 			{
275cdf0e10cSrcweir 				xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
276cdf0e10cSrcweir 				m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
277cdf0e10cSrcweir 				return false;
278cdf0e10cSrcweir 			}
279cdf0e10cSrcweir 			catch( com.sun.star.container.ElementExistException ee )
280cdf0e10cSrcweir 			{}
281cdf0e10cSrcweir 			catch( Exception e )
282cdf0e10cSrcweir 			{
283cdf0e10cSrcweir 				m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e );
284cdf0e10cSrcweir 				return false;
285cdf0e10cSrcweir 			}
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 			return true;
289cdf0e10cSrcweir 		}
290cdf0e10cSrcweir 		catch( Exception e )
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			m_aTestHelper.Error( "Exception: " + e );
293cdf0e10cSrcweir 			return false;
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299