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
)
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 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
59 if ( xTempStorage
== null )
61 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
67 xTempStorage
.copyToStorage( null );
68 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
71 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
73 catch( com
.sun
.star
.uno
.Exception ue
)
77 m_aTestHelper
.Error( "Unexpected excepion because of illegal parameter : " + e
);
81 // open new substorages
82 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
85 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
88 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
90 m_aTestHelper
.Error( "Can't create substorage!" );
94 // in case stream is open for reading it must exist
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!" );
101 catch( com
.sun
.star
.uno
.Exception ue
)
105 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e
);
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!" );
116 catch( com
.sun
.star
.uno
.Exception ue
)
120 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e
);
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!" );
131 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
135 m_aTestHelper
.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e
);
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!" );
146 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
150 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e
);
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!" );
161 catch( com
.sun
.star
.container
.ElementExistException ee
)
165 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e
);
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!" );
176 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
178 catch( com
.sun
.star
.uno
.Exception ue
)
182 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e
);
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!" );
193 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
195 catch( com
.sun
.star
.uno
.Exception ue
)
199 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e
);
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!" );
214 // open a new substorage
215 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
217 ElementModes
.WRITE
);
218 if ( xTargetSubStorage
== null )
220 m_aTestHelper
.Error( "Can't create substorage!" );
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!" );
231 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
235 m_aTestHelper
.Error( "Unexpected excepion in case of copying of nonexistent element: " + e
);
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!" );
246 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
250 m_aTestHelper
.Error( "Unexpected excepion in case of moving of nonexistent element: " + e
);
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!" );
261 catch( com
.sun
.star
.container
.ElementExistException ee
)
265 m_aTestHelper
.Error( "Unexpected excepion in case target for copying already exists: " + e
);
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!" );
276 catch( com
.sun
.star
.container
.ElementExistException ee
)
280 m_aTestHelper
.Error( "Unexpected excepion in case target for moving already exists: " + e
);
289 m_aTestHelper
.Error( "Exception: " + e
);