fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / package / qa / ofopxmlstorages / Test03.java
blob1aef721688b7211e702696cf6defe40aa446f3a8
1 /*
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 )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "Test03: " );
50 public boolean test()
52 try
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!" );
70 return false;
73 // open a new substorage
74 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
75 "SubStorage1",
76 ElementModes.WRITE );
77 if ( xTempSubStorage == null )
79 m_aTestHelper.Error( "Can't create substorage!" );
80 return false;
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,
87 "SubStream1",
88 "MediaType1",
89 true,
90 pBytes1,
91 aRelations ) )
92 return false;
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,
98 "SubStream2",
99 "MediaType2",
100 false,
101 pBytes2,
102 aRelations ) )
103 return false;
105 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
106 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
107 false,
108 ElementModes.WRITE,
109 aRelations ) )
110 return false;
112 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
113 return false;
115 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
116 return false;
118 // ================================================
119 // check storage hyerarchy tree
120 // ================================================
122 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
123 try {
124 xTempStorage.isStorageElement( "does not exist" );
125 m_aTestHelper.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
126 return false;
128 catch( com.sun.star.container.NoSuchElementException ne )
131 catch( Exception e )
133 m_aTestHelper.Error( "Wrong exception is thrown by isStorageElement() call: " + e );
134 return false;
137 try {
138 xTempStorage.isStreamElement( "does not exist" );
139 m_aTestHelper.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
140 return false;
142 catch( com.sun.star.container.NoSuchElementException ne )
145 catch( Exception e )
147 m_aTestHelper.Error( "Wrong exception is thrown by isStreamElement() call: " + e );
148 return false;
151 XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage );
152 if ( xRootNameAccess == null )
154 m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" );
155 return false;
158 try {
159 if ( !xTempStorage.isStorageElement( "SubStorage1" ) || xTempStorage.isStreamElement( "SubStorage1" ) )
161 m_aTestHelper.Error( "Child 'SubStorage1' can not be detected as storage!" );
162 return false;
165 if ( xTempStorage.isStorageElement( "SubStream1" ) || !xTempStorage.isStreamElement( "SubStream1" ) )
167 m_aTestHelper.Error( "Child 'SubStream1' can not be detected as stream!" );
168 return false;
171 catch( Exception e )
173 m_aTestHelper.Error( "Child's type can not be detected, exception: " + e );
174 return false;
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!" );
184 return false;
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!" );
192 return false;
195 // get storage through XNameAccess
196 XStorage xResultSubStorage = getStorageFromNameAccess( xRootNameAccess, "SubStorage1" );
197 if ( xResultSubStorage == null )
198 return false;
200 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage,
201 false,
202 ElementModes.READ,
203 aRelations ) )
204 return false;
206 XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage );
207 if ( xChildAccess == null )
209 m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" );
210 return false;
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'!" );
218 return false;
221 return true;
223 catch( Exception e )
225 m_aTestHelper.Error( "Exception: " + e );
226 return false;
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 )
238 return xResult;
239 else
240 m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess!" );
242 catch( Exception e )
244 m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess, exception: " + e );
247 return null;