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
;
28 import com
.sun
.star
.io
.XStream
;
30 import com
.sun
.star
.embed
.*;
31 import com
.sun
.star
.beans
.StringPair
;
33 import share
.LogWriter
;
34 import complex
.ofopxmlstorages
.TestHelper
;
35 import complex
.ofopxmlstorages
.StorageTest
;
37 public class Test05
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public Test05( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "Test05: " );
52 StringPair
[][] aRelations1
=
53 { { new StringPair( "Id", "Num1" ) },
54 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
55 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
56 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
57 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
58 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
59 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
62 StringPair
[][] aRelations2
=
63 { { new StringPair( "Id", "Num1" ) },
64 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
65 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
66 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
67 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
68 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
69 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
74 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
75 if ( sTempFileURL
== null || sTempFileURL
== "" )
77 m_aTestHelper
.Error( "No valid temporary file was created!" );
81 // create temporary storage based on a previously created temporary file
82 XStorage xTempFileStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
85 if ( xTempFileStorage
== null )
87 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
91 // open a new substorage
92 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempFileStorage
,
95 if ( xTempSubStorage
== null )
97 m_aTestHelper
.Error( "Can't create substorage!" );
101 // open a new substorage
102 XStorage xSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
104 ElementModes
.WRITE
);
105 if ( xSubSubStorage
== null )
107 m_aTestHelper
.Error( "Can't create substorage!" );
112 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
114 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
115 if ( !m_aTestHelper
.WriteBytesToSubstream( xSubSubStorage
,
123 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
125 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
126 if ( !m_aTestHelper
.WriteBytesToSubstream( xSubSubStorage
,
134 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
135 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempFileStorage
,
141 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
142 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
148 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
149 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xSubSubStorage
,
156 // commit all the storages
157 if ( !m_aTestHelper
.commitStorage( xSubSubStorage
) )
160 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
163 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
166 // try to open an opened substorage, open call must fail
167 if ( !m_aTestHelper
.cantOpenStorage( xTempFileStorage
, "SubStorage1" ) )
171 // reopen created streams
172 XStream xSubStream1
= m_aTestHelper
.OpenStream( xSubSubStorage
,
174 ElementModes
.WRITE
| ElementModes
.NOCREATE
);
175 XStream xSubStream2
= m_aTestHelper
.OpenStream( xSubSubStorage
,
177 ElementModes
.READ
| ElementModes
.NOCREATE
);
178 if ( xSubStream1
== null || xSubStream2
== null )
181 // it should be possible to have more than one copy of stream for reading
182 XStream xSubStream2clone
= m_aTestHelper
.OpenStream( xSubSubStorage
,
184 ElementModes
.READ
| ElementModes
.NOCREATE
);
185 if ( xSubStream2
== null )
189 // so now the first stream can not be open neither for reading nor for writing
190 if ( !m_aTestHelper
.cantOpenStream( xSubSubStorage
, "SubStream1", ElementModes
.WRITE
)
191 || !m_aTestHelper
.cantOpenStream( xSubSubStorage
, "SubStream1", ElementModes
.READ
) )
194 // the second stream can not be open for writing
195 if ( !m_aTestHelper
.cantOpenStream( xSubSubStorage
, "SubStream2", ElementModes
.WRITE
) )
199 // dispose xTestSubStorage, all the subtree must be disposed
200 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
203 // check that subtree was disposed correctly
206 xSubSubStorage
.isStreamElement( "SubStream1" );
207 m_aTestHelper
.Error( "Substorage was not disposed!" );
210 catch ( com
.sun
.star
.lang
.DisposedException de
)
212 catch ( Exception e
)
214 m_aTestHelper
.Error( "Wrong exception is thrown by disposed storage: " + e
);
220 xSubStream1
.getInputStream();
221 m_aTestHelper
.Error( "Writeable substream was not disposed!" );
224 catch ( com
.sun
.star
.lang
.DisposedException de
)
226 catch ( Exception e
)
228 m_aTestHelper
.Error( "Wrong exception is thrown by disposed stream: " + e
);
234 xSubStream2
.getInputStream();
235 m_aTestHelper
.Error( "Readonly substream was not disposed!" );
238 catch ( com
.sun
.star
.lang
.DisposedException de
)
240 catch ( Exception e
)
242 m_aTestHelper
.Error( "Wrong exception is thrown by disposed stream: " + e
);
247 // dispose root storage
248 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
253 // now check all the written and copied information
256 XStorage xResultStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
259 if ( xResultStorage
== null )
261 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
265 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
271 // open existing substorage
272 XStorage xResSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
275 if ( xResSubStorage
== null )
277 m_aTestHelper
.Error( "Can't open existing substorage 'SubSubStorage'!" );
281 if ( !m_aTestHelper
.checkStorageProperties( xResSubStorage
,
287 // open existing substorage
288 XStorage xResSubSubStorage
= m_aTestHelper
.openSubStorage( xResSubStorage
,
291 if ( xResSubSubStorage
== null )
293 m_aTestHelper
.Error( "Can't open existing substorage 'SubSubStorage'!" );
297 if ( !m_aTestHelper
.checkStorageProperties( xResSubSubStorage
,
304 if ( !m_aTestHelper
.checkStream( xResSubSubStorage
,
311 if ( !m_aTestHelper
.checkStream( xResSubSubStorage
,
318 // dispose used storages to free resources
319 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
326 m_aTestHelper
.Error( "Exception: " + e
);