1 package complex
.ofopxmlstorages
;
3 import com
.sun
.star
.uno
.XInterface
;
4 import com
.sun
.star
.lang
.XMultiServiceFactory
;
5 import com
.sun
.star
.lang
.XSingleServiceFactory
;
7 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
8 import com
.sun
.star
.uno
.UnoRuntime
;
9 import com
.sun
.star
.uno
.XInterface
;
11 import com
.sun
.star
.lang
.IllegalArgumentException
;
12 import com
.sun
.star
.container
.NoSuchElementException
;
13 import com
.sun
.star
.container
.ElementExistException
;
15 import com
.sun
.star
.embed
.*;
17 import share
.LogWriter
;
18 import complex
.ofopxmlstorages
.TestHelper
;
19 import complex
.ofopxmlstorages
.StorageTest
;
21 public class Test06
implements StorageTest
{
23 XMultiServiceFactory m_xMSF
;
24 XSingleServiceFactory m_xStorageFactory
;
25 TestHelper m_aTestHelper
;
27 public Test06( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
30 m_xStorageFactory
= xStorageFactory
;
31 m_aTestHelper
= new TestHelper( aLogWriter
, "Test06: " );
38 // create temporary storage based on arbitrary medium
39 // after such a storage is closed it is lost
40 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
41 if ( xTempStorage
== null )
43 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
49 xTempStorage
.copyToStorage( null );
50 m_aTestHelper
.Error( "The method must throw an exception because of illegal parameter!" );
53 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
55 catch( com
.sun
.star
.uno
.Exception ue
)
59 m_aTestHelper
.Error( "Unexpected excepion because of illegal parameter : " + e
);
63 // open new substorages
64 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
67 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
70 if ( xTempSubStorage1
== null || xTempSubStorage2
== null )
72 m_aTestHelper
.Error( "Can't create substorage!" );
76 // in case stream is open for reading it must exist
79 xTempSubStorage1
.openStreamElement( "NonExistingStream", ElementModes
.READ
);
80 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
83 catch( com
.sun
.star
.uno
.Exception ue
)
87 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e
);
91 // in case a storage is open for reading it must exist
94 xTempSubStorage1
.openStreamElement( "NonExistingStorage", ElementModes
.READ
);
95 m_aTestHelper
.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
98 catch( com
.sun
.star
.uno
.Exception ue
)
102 m_aTestHelper
.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e
);
106 // in case of removing nonexistent element an exception must be thrown
109 xTempSubStorage1
.removeElement( "NonExistingElement" );
110 m_aTestHelper
.Error( "An exception must be thrown in case of removing nonexistent element!" );
113 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
117 m_aTestHelper
.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e
);
121 // in case of renaming of nonexistent element an exception must be thrown
124 xTempSubStorage1
.renameElement( "NonExistingElement", "NewName" );
125 m_aTestHelper
.Error( "An exception must be thrown in case of renaming nonexistent element!" );
128 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
132 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e
);
136 // in case of renaming to a name of existent element an exception must be thrown
139 xTempStorage
.renameElement( "SubStorage1", "SubStorage2" );
140 m_aTestHelper
.Error( "An exception must be thrown in case of renaming to the name of existent element!" );
143 catch( com
.sun
.star
.container
.ElementExistException ee
)
147 m_aTestHelper
.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e
);
151 // in case of copying target storage must be provided
154 xTempStorage
.copyElementTo( "SubStorage1", null, "SubStorage1" );
155 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for copying!" );
158 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
160 catch( com
.sun
.star
.uno
.Exception ue
)
164 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e
);
168 // in case of moving target storage must be provided
171 xTempStorage
.moveElementTo( "SubStorage1", null, "SubStorage1" );
172 m_aTestHelper
.Error( "An exception must be thrown in case empty reference is provided as target for moving!" );
175 catch( com
.sun
.star
.lang
.IllegalArgumentException iae
)
177 catch( com
.sun
.star
.uno
.Exception ue
)
181 m_aTestHelper
.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e
);
186 // prepare target for further testings
188 // create new temporary storage based on arbitrary medium
189 XStorage xTargetStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
190 if ( xTargetStorage
== null )
192 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
196 // open a new substorage
197 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
199 ElementModes
.WRITE
);
200 if ( xTargetSubStorage
== null )
202 m_aTestHelper
.Error( "Can't create substorage!" );
206 // in case of copying of nonexistent element an exception must be thrown
209 xTempStorage
.copyElementTo( "Nonexistent element", xTargetStorage
, "Target" );
210 m_aTestHelper
.Error( "An exception must be thrown in case of copying of nonexisting element!" );
213 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
217 m_aTestHelper
.Error( "Unexpected excepion in case of copying of nonexistent element: " + e
);
221 // in case of moving of nonexistent element an exception must be thrown
224 xTempStorage
.moveElementTo( "Nonexistent element", xTargetStorage
, "Target" );
225 m_aTestHelper
.Error( "An exception must be thrown in case of moving of nonexisting element!" );
228 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
232 m_aTestHelper
.Error( "Unexpected excepion in case of moving of nonexistent element: " + e
);
236 // in case target for copying already exists an exception must be thrown
239 xTempStorage
.copyElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
240 m_aTestHelper
.Error( "An exception must be thrown in case target for copying already exists!" );
243 catch( com
.sun
.star
.container
.ElementExistException ee
)
247 m_aTestHelper
.Error( "Unexpected excepion in case target for copying already exists: " + e
);
251 // in case target for moving already exists an exception must be thrown
254 xTempStorage
.moveElementTo( "SubStorage1", xTargetStorage
, "SubStorage1" );
255 m_aTestHelper
.Error( "An exception must be thrown in case target for moving already exists!" );
258 catch( com
.sun
.star
.container
.ElementExistException ee
)
262 m_aTestHelper
.Error( "Unexpected excepion in case target for moving already exists: " + e
);
271 m_aTestHelper
.Error( "Exception: " + e
);