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
.embed
.*;
30 import com
.sun
.star
.container
.XNameAccess
;
31 import com
.sun
.star
.beans
.StringPair
;
33 import share
.LogWriter
;
34 import complex
.ofopxmlstorages
.TestHelper
;
35 import complex
.ofopxmlstorages
.StorageTest
;
37 public class Test03
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public Test03( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "Test03: " );
54 StringPair
[][] aRelations
=
55 { { new StringPair( "Id", "Num1" ) },
56 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
57 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
58 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
59 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
60 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
61 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
64 // create temporary storage based on arbitrary medium
65 // after such a storage is closed it is lost
66 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
67 if ( xTempStorage
== null )
69 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
73 // open a new substorage
74 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
77 if ( xTempSubStorage
== null )
79 m_aTestHelper
.Error( "Can't create substorage!" );
83 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
85 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
86 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
,
94 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
96 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
97 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
,
105 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
106 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
112 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
115 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
118 // ================================================
119 // check storage hyerarchy tree
120 // ================================================
122 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
124 xTempStorage
.isStorageElement( "does not exist" );
125 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
128 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
133 m_aTestHelper
.Error( "Wrong exception is thrown by isStorageElement() call: " + e
);
138 xTempStorage
.isStreamElement( "does not exist" );
139 m_aTestHelper
.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
142 catch( com
.sun
.star
.container
.NoSuchElementException ne
)
147 m_aTestHelper
.Error( "Wrong exception is thrown by isStreamElement() call: " + e
);
151 XNameAccess xRootNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xTempStorage
);
152 if ( xRootNameAccess
== null )
154 m_aTestHelper
.Error( "Root storage doesn't support XNameAccess!" );
159 if ( !xTempStorage
.isStorageElement( "SubStorage1" ) || xTempStorage
.isStreamElement( "SubStorage1" ) )
161 m_aTestHelper
.Error( "Child 'SubStorage1' can not be detected as storage!" );
165 if ( xTempStorage
.isStorageElement( "SubStream1" ) || !xTempStorage
.isStreamElement( "SubStream1" ) )
167 m_aTestHelper
.Error( "Child 'SubStream1' can not be detected as stream!" );
173 m_aTestHelper
.Error( "Child's type can not be detected, exception: " + e
);
178 // check that root storage contents are represented correctly
179 String sRootCont
[] = xRootNameAccess
.getElementNames();
181 if ( sRootCont
.length
!= 2 )
183 m_aTestHelper
.Error( "Root storage contains wrong amount of children!" );
187 if ( !( sRootCont
[0].equals( "SubStorage1" ) && sRootCont
[1].equals( "SubStream1" )
188 || sRootCont
[0].equals( "SubStream1" ) && sRootCont
[1].equals( "SubStorage1" ) )
189 || !( xRootNameAccess
.hasByName( "SubStream1" ) && xRootNameAccess
.hasByName( "SubStorage1" ) ) )
191 m_aTestHelper
.Error( "Root storage contains wrong list of children!" );
195 // get storage through XNameAccess
196 XStorage xResultSubStorage
= getStorageFromNameAccess( xRootNameAccess
, "SubStorage1" );
197 if ( xResultSubStorage
== null )
200 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
,
206 XNameAccess xChildAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResultSubStorage
);
207 if ( xChildAccess
== null )
209 m_aTestHelper
.Error( "Child storage doesn't support XNameAccess!" );
213 if ( !xChildAccess
.hasByName( "SubStream2" )
214 || !xResultSubStorage
.isStreamElement( "SubStream2" )
215 || xResultSubStorage
.isStorageElement( "SubStream2" ) )
217 m_aTestHelper
.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
225 m_aTestHelper
.Error( "Exception: " + e
);
230 public XStorage
getStorageFromNameAccess( XNameAccess xAccess
, String sName
)
234 Object oStorage
= xAccess
.getByName( sName
);
235 XStorage xResult
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
237 if ( xResult
!= null )
240 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess!" );
244 m_aTestHelper
.Error( "Can't retrieve substorage '" + sName
+ "' through XNameAccess, exception: " + e
);