tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / odk / examples / java / Storage / Test06.java
blob027a4a2c1521f6be6d4a9ba56e827536e26da2b0
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com.sun.star.lang.XMultiServiceFactory;
21 import com.sun.star.lang.XSingleServiceFactory;
23 import com.sun.star.uno.UnoRuntime;
24 import com.sun.star.embed.*;
26 public class Test06 implements StorageTest {
28 XMultiServiceFactory m_xMSF;
29 XSingleServiceFactory m_xStorageFactory;
30 TestHelper m_aTestHelper;
32 public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
34 m_xMSF = xMSF;
35 m_xStorageFactory = xStorageFactory;
36 m_aTestHelper = new TestHelper( "Test06: " );
39 public boolean test()
41 try
43 // create temporary storage based on arbitrary medium
44 // after such a storage is closed it is lost
45 Object oTempStorage = m_xStorageFactory.createInstance();
46 XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage );
47 if ( xTempStorage == null )
49 m_aTestHelper.Error( "Can't create temporary storage representation!" );
50 return false;
53 try
55 xTempStorage.copyToStorage( null );
56 m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
57 return false;
59 catch( com.sun.star.lang.IllegalArgumentException iae )
61 catch( com.sun.star.uno.Exception ue )
63 catch( Exception e )
65 m_aTestHelper.Error( "Unexpected exception because of illegal parameter : " + e );
66 return false;
69 // open new substorages
70 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
71 "SubStorage1",
72 ElementModes.WRITE );
73 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
74 "SubStorage2",
75 ElementModes.WRITE );
76 if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
78 m_aTestHelper.Error( "Can't create substorage!" );
79 return false;
82 // in case stream is open for reading it must exist
83 try
85 xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ );
86 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
87 return false;
89 catch( com.sun.star.uno.Exception ue )
91 catch( Exception e )
93 m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e );
94 return false;
97 // in case a storage is open for reading it must exist
98 try
100 xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ );
101 m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
102 return false;
104 catch( com.sun.star.uno.Exception ue )
106 catch( Exception e )
108 m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e );
109 return false;
112 // in case of removing nonexistent element an exception must be thrown
115 xTempSubStorage1.removeElement( "NonExistingElement" );
116 m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" );
117 return false;
119 catch( com.sun.star.container.NoSuchElementException ne )
121 catch( Exception e )
123 m_aTestHelper.Error( "Unexpected exception in case of try to remove nonexistent element : " + e );
124 return false;
127 // in case of renaming of nonexistent element an exception must be thrown
130 xTempSubStorage1.renameElement( "NonExistingElement", "NewName" );
131 m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" );
132 return false;
134 catch( com.sun.star.container.NoSuchElementException ne )
136 catch( Exception e )
138 m_aTestHelper.Error( "Unexpected exception in case of try to rename nonexistent element : " + e );
139 return false;
142 // in case of renaming to a name of existent element an exception must be thrown
145 xTempStorage.renameElement( "SubStorage1", "SubStorage2" );
146 m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
147 return false;
149 catch( com.sun.star.container.ElementExistException ee )
151 catch( Exception e )
153 m_aTestHelper.Error( "Unexpected exception in case of try to rename to the name of existent element : " + e );
154 return false;
157 // in case of copying target storage must be provided
160 xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" );
161 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
162 return false;
164 catch( com.sun.star.lang.IllegalArgumentException iae )
166 catch( com.sun.star.uno.Exception ue )
168 catch( Exception e )
170 m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for copying : " + e );
171 return false;
174 // in case of moving target storage must be provided
177 xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" );
178 m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
179 return false;
181 catch( com.sun.star.lang.IllegalArgumentException iae )
183 catch( com.sun.star.uno.Exception ue )
185 catch( Exception e )
187 m_aTestHelper.Error( "Unexpected exception in case empty reference is provided as target for moving : " + e );
188 return false;
192 // prepare target for further testings
194 // create new temporary storage based on arbitrary medium
195 Object oTargetStorage = m_xStorageFactory.createInstance();
196 XStorage xTargetStorage = UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
197 if ( xTargetStorage == null )
199 m_aTestHelper.Error( "Can't create temporary storage representation!" );
200 return false;
203 // open a new substorage
204 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
205 "SubStorage1",
206 ElementModes.WRITE );
207 if ( xTargetSubStorage == null )
209 m_aTestHelper.Error( "Can't create substorage!" );
210 return false;
213 // in case of copying of nonexistent element an exception must be thrown
216 xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" );
217 m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexistent element!" );
218 return false;
220 catch( com.sun.star.container.NoSuchElementException ne )
222 catch( Exception e )
224 m_aTestHelper.Error( "Unexpected exception in case of copying of nonexistent element: " + e );
225 return false;
228 // in case of moving of nonexistent element an exception must be thrown
231 xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" );
232 m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexistent element!" );
233 return false;
235 catch( com.sun.star.container.NoSuchElementException ne )
237 catch( Exception e )
239 m_aTestHelper.Error( "Unexpected exception in case of moving of nonexistent element: " + e );
240 return false;
243 // in case target for copying already exists an exception must be thrown
246 xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
247 m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" );
248 return false;
250 catch( com.sun.star.container.ElementExistException ee )
252 catch( Exception e )
254 m_aTestHelper.Error( "Unexpected exception in case target for copying already exists: " + e );
255 return false;
258 // in case target for moving already exists an exception must be thrown
261 xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" );
262 m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" );
263 return false;
265 catch( com.sun.star.container.ElementExistException ee )
267 catch( Exception e )
269 m_aTestHelper.Error( "Unexpected exception in case target for moving already exists: " + e );
270 return false;
274 return true;
276 catch( Exception e )
278 m_aTestHelper.Error( "Exception: " + e );
279 return false;
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */