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 import com
.sun
.star
.lang
.XMultiServiceFactory
;
20 import com
.sun
.star
.lang
.XSingleServiceFactory
;
22 import com
.sun
.star
.uno
.UnoRuntime
;
23 import com
.sun
.star
.embed
.*;
25 public class Test06
implements StorageTest
{
27 XMultiServiceFactory m_xMSF
;
28 XSingleServiceFactory m_xStorageFactory
;
29 TestHelper m_aTestHelper
;
31 public Test06( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
34 m_xStorageFactory
= xStorageFactory
;
35 m_aTestHelper
= new TestHelper( "Test06: " );
42 // create temporary storage based on arbitrary medium
43 // after such a storage is closed it is lost
44 Object oTempStorage
= m_xStorageFactory
.createInstance();
45 XStorage xTempStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
46 if ( xTempStorage
== null )
48 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
54 xTempStorage
.copyToStorage( null );
55 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
58 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
60 catch( com
.sun
.star
.uno
.Exception ue
)
64 m_aTestHelper
.Error( "Unexpected excepion because of illegal parameter : " + e
);
68 // open new substorages
69 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
72 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
75 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
77 m_aTestHelper
.Error( "Can't create substorage!" );
81 // in case stream is open for reading it must exist
84 xTempSubStorage1
.openStreamElement( "NonExistingStream", ElementModes
.READ
);
85 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
88 catch( com
.sun
.star
.uno
.Exception ue
)
92 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e
);
96 // in case a storage is open for reading it must exist
99 xTempSubStorage1
.openStreamElement( "NonExistingStorage", ElementModes
.READ
);
100 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
103 catch( com
.sun
.star
.uno
.Exception ue
)
107 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e
);
111 // in case of removing nonexistent element an exception must be thrown
114 xTempSubStorage1
.removeElement( "NonExistingElement" );
115 m_aTestHelper
.Error( "An exception must be thrown in case of removing nonexistent element!" );
118 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
122 m_aTestHelper
.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e
);
126 // in case of renaming of nonexistent element an exception must be thrown
129 xTempSubStorage1
.renameElement( "NonExistingElement", "NewName" );
130 m_aTestHelper
.Error( "An exception must be thrown in case of renaming nonexistent element!" );
133 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
137 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e
);
141 // in case of renaming to a name of existent element an exception must be thrown
144 xTempStorage
.renameElement( "SubStorage1", "SubStorage2" );
145 m_aTestHelper
.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
148 catch( com
.sun
.star
.container
.ElementExistException ee
)
152 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e
);
156 // in case of copying target storage must be provided
159 xTempStorage
.copyElementTo( "SubStorage1", null, "SubStorage1" );
160 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
163 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
165 catch( com
.sun
.star
.uno
.Exception ue
)
169 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e
);
173 // in case of moving target storage must be provided
176 xTempStorage
.moveElementTo( "SubStorage1", null, "SubStorage1" );
177 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
180 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
182 catch( com
.sun
.star
.uno
.Exception ue
)
186 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e
);
191 // prepare target for further testings
193 // create new temporary storage based on arbitrary medium
194 Object oTargetStorage
= m_xStorageFactory
.createInstance();
195 XStorage xTargetStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTargetStorage
);
196 if ( xTargetStorage
== null )
198 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
202 // open a new substorage
203 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
205 ElementModes
.WRITE
);
206 if ( xTargetSubStorage
== null )
208 m_aTestHelper
.Error( "Can't create substorage!" );
212 // in case of copying of nonexistent element an exception must be thrown
215 xTempStorage
.copyElementTo( "Nonexistent element", xTargetStorage
, "Target" );
216 m_aTestHelper
.Error( "An exception must be thrown in case of copying of nonexisting element!" );
219 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
223 m_aTestHelper
.Error( "Unexpected excepion in case of copying of nonexistent element: " + e
);
227 // in case of moving of nonexistent element an exception must be thrown
230 xTempStorage
.moveElementTo( "Nonexistent element", xTargetStorage
, "Target" );
231 m_aTestHelper
.Error( "An exception must be thrown in case of moving of nonexisting element!" );
234 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
238 m_aTestHelper
.Error( "Unexpected excepion in case of moving of nonexistent element: " + e
);
242 // in case target for copying already exists an exception must be thrown
245 xTempStorage
.copyElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
246 m_aTestHelper
.Error( "An exception must be thrown in case target for copying already exists!" );
249 catch( com
.sun
.star
.container
.ElementExistException ee
)
253 m_aTestHelper
.Error( "Unexpected excepion in case target for copying already exists: " + e
);
257 // in case target for moving already exists an exception must be thrown
260 xTempStorage
.moveElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
261 m_aTestHelper
.Error( "An exception must be thrown in case target for moving already exists!" );
264 catch( com
.sun
.star
.container
.ElementExistException ee
)
268 m_aTestHelper
.Error( "Unexpected excepion in case target for moving already exists: " + e
);
277 m_aTestHelper
.Error( "Exception: " + e
);