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
)
48 m_xStorageFactory
= xStorageFactory
;
49 m_aTestHelper
= new TestHelper( aLogWriter
, "Test06: " );
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!" );
68 xTempStorage
.copyToStorage( null );
69 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
72 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
74 catch( com
.sun
.star
.uno
.Exception ue
)
78 m_aTestHelper
.Error( "Unexpected exception because of illegal parameter : " + e
);
82 // open new substorages
83 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
86 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
89 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
91 m_aTestHelper
.Error( "Can't create substorage!" );
95 // in case stream is open for reading it must exist
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!" );
102 catch( com
.sun
.star
.uno
.Exception ue
)
106 m_aTestHelper
.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e
);
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!" );
117 catch( com
.sun
.star
.uno
.Exception ue
)
121 m_aTestHelper
.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e
);
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!" );
132 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
136 m_aTestHelper
.Error( "Unexpected exception in case of try to remove nonexistent element : " + e
);
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!" );
147 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
151 m_aTestHelper
.Error( "Unexpected exception in case of try to rename nonexistent element : " + e
);
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!" );
162 catch( com
.sun
.star
.container
.ElementExistException ee
)
166 m_aTestHelper
.Error( "Unexpected exception in case of try to rename to the name of existent element : " + e
);
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!" );
177 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
179 catch( com
.sun
.star
.uno
.Exception ue
)
183 m_aTestHelper
.Error( "Unexpected exception in case empty reference is provided as target for copying : " + e
);
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!" );
194 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
196 catch( com
.sun
.star
.uno
.Exception ue
)
200 m_aTestHelper
.Error( "Unexpected exception in case empty reference is provided as target for moving : " + e
);
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!" );
216 // open a new substorage
217 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
219 ElementModes
.WRITE
);
220 if ( xTargetSubStorage
== null )
222 m_aTestHelper
.Error( "Can't create substorage!" );
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!" );
233 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
237 m_aTestHelper
.Error( "Unexpected exception in case of copying of nonexistent element: " + e
);
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!" );
248 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
252 m_aTestHelper
.Error( "Unexpected exception in case of moving of nonexistent element: " + e
);
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!" );
263 catch( com
.sun
.star
.container
.ElementExistException ee
)
267 m_aTestHelper
.Error( "Unexpected exception in case target for copying already exists: " + e
);
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!" );
278 catch( com
.sun
.star
.container
.ElementExistException ee
)
282 m_aTestHelper
.Error( "Unexpected exception in case target for moving already exists: " + e
);
291 m_aTestHelper
.Error( "Exception: " + e
);