1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
35 m_xStorageFactory
= xStorageFactory
;
36 m_aTestHelper
= new TestHelper( "Test06: " );
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!" );
55 xTempStorage
.copyToStorage( null );
56 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
59 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
61 catch( com
.sun
.star
.uno
.Exception ue
)
65 m_aTestHelper
.Error( "Unexpected exception because of illegal parameter : " + e
);
69 // open new substorages
70 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
73 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
76 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
78 m_aTestHelper
.Error( "Can't create substorage!" );
82 // in case stream is open for reading it must exist
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!" );
89 catch( com
.sun
.star
.uno
.Exception ue
)
93 m_aTestHelper
.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e
);
97 // in case a storage is open for reading it must exist
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!" );
104 catch( com
.sun
.star
.uno
.Exception ue
)
108 m_aTestHelper
.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e
);
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!" );
119 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
123 m_aTestHelper
.Error( "Unexpected exception in case of try to remove nonexistent element : " + e
);
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!" );
134 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
138 m_aTestHelper
.Error( "Unexpected exception in case of try to rename nonexistent element : " + e
);
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!" );
149 catch( com
.sun
.star
.container
.ElementExistException ee
)
153 m_aTestHelper
.Error( "Unexpected exception in case of try to rename to the name of existent element : " + e
);
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!" );
164 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
166 catch( com
.sun
.star
.uno
.Exception ue
)
170 m_aTestHelper
.Error( "Unexpected exception in case empty reference is provided as target for copying : " + e
);
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!" );
181 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
183 catch( com
.sun
.star
.uno
.Exception ue
)
187 m_aTestHelper
.Error( "Unexpected exception in case empty reference is provided as target for moving : " + e
);
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!" );
203 // open a new substorage
204 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
206 ElementModes
.WRITE
);
207 if ( xTargetSubStorage
== null )
209 m_aTestHelper
.Error( "Can't create substorage!" );
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!" );
220 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
224 m_aTestHelper
.Error( "Unexpected exception in case of copying of nonexistent element: " + e
);
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!" );
235 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
239 m_aTestHelper
.Error( "Unexpected exception in case of moving of nonexistent element: " + e
);
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!" );
250 catch( com
.sun
.star
.container
.ElementExistException ee
)
254 m_aTestHelper
.Error( "Unexpected exception in case target for copying already exists: " + e
);
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!" );
265 catch( com
.sun
.star
.container
.ElementExistException ee
)
269 m_aTestHelper
.Error( "Unexpected exception in case target for moving already exists: " + e
);
278 m_aTestHelper
.Error( "Exception: " + e
);
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */