merge the formfield patch from ooo-build
[ooovba.git] / package / qa / ofopxmlstorages / Test03.java
blobee2a892d208035d1e4db5be7ea4e9ded69a44c76
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.embed.*;
12 import com.sun.star.container.XNameAccess;
13 import com.sun.star.beans.StringPair;
15 import share.LogWriter;
16 import complex.ofopxmlstorages.TestHelper;
17 import complex.ofopxmlstorages.StorageTest;
19 public class Test03 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public Test03( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "Test03: " );
32 public boolean test()
34 try
36 StringPair[][] aRelations =
37 { { new StringPair( "Id", "Num1" ) },
38 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
39 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
40 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
41 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
42 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
43 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
46 // create temporary storage based on arbitrary medium
47 // after such a storage is closed it is lost
48 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
49 if ( xTempStorage == null )
51 m_aTestHelper.Error( "Can't create temporary storage representation!" );
52 return false;
55 // open a new substorage
56 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
57 "SubStorage1",
58 ElementModes.WRITE );
59 if ( xTempSubStorage == null )
61 m_aTestHelper.Error( "Can't create substorage!" );
62 return false;
65 byte pBytes1[] = { 1, 1, 1, 1, 1 };
67 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
68 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage,
69 "SubStream1",
70 "MediaType1",
71 true,
72 pBytes1,
73 aRelations ) )
74 return false;
76 byte pBytes2[] = { 2, 2, 2, 2, 2 };
78 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
79 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
80 "SubStream2",
81 "MediaType2",
82 false,
83 pBytes2,
84 aRelations ) )
85 return false;
87 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
89 false,
90 ElementModes.WRITE,
91 aRelations ) )
92 return false;
94 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
95 return false;
97 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
98 return false;
100 // ================================================
101 // check storage hyerarchy tree
102 // ================================================
104 // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly
105 try {
106 xTempStorage.isStorageElement( "does not exist" );
107 m_aTestHelper.Error( "Nonexisting element doesn't detected by isStorageElement() call!" );
108 return false;
110 catch( com.sun.star.container.NoSuchElementException ne )
113 catch( Exception e )
115 m_aTestHelper.Error( "Wrong exception is thrown by isStorageElement() call: " + e );
116 return false;
119 try {
120 xTempStorage.isStreamElement( "does not exist" );
121 m_aTestHelper.Error( "Nonexisting element doesn't detected by isStreamElement() call!" );
122 return false;
124 catch( com.sun.star.container.NoSuchElementException ne )
127 catch( Exception e )
129 m_aTestHelper.Error( "Wrong exception is thrown by isStreamElement() call: " + e );
130 return false;
133 XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage );
134 if ( xRootNameAccess == null )
136 m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" );
137 return false;
140 try {
141 if ( !xTempStorage.isStorageElement( "SubStorage1" ) || xTempStorage.isStreamElement( "SubStorage1" ) )
143 m_aTestHelper.Error( "Child 'SubStorage1' can not be detected as storage!" );
144 return false;
147 if ( xTempStorage.isStorageElement( "SubStream1" ) || !xTempStorage.isStreamElement( "SubStream1" ) )
149 m_aTestHelper.Error( "Child 'SubStream1' can not be detected as stream!" );
150 return false;
153 catch( Exception e )
155 m_aTestHelper.Error( "Child's type can not be detected, exception: " + e );
156 return false;
160 // check that root storage contents are represented correctly
161 String sRootCont[] = xRootNameAccess.getElementNames();
163 if ( sRootCont.length != 2 )
165 m_aTestHelper.Error( "Root storage contains wrong amount of children!" );
166 return false;
169 if ( !( sRootCont[0].equals( "SubStorage1" ) && sRootCont[1].equals( "SubStream1" )
170 || sRootCont[0].equals( "SubStream1" ) && sRootCont[1].equals( "SubStorage1" ) )
171 || !( xRootNameAccess.hasByName( "SubStream1" ) && xRootNameAccess.hasByName( "SubStorage1" ) ) )
173 m_aTestHelper.Error( "Root storage contains wrong list of children!" );
174 return false;
177 // get storage through XNameAccess
178 XStorage xResultSubStorage = getStorageFromNameAccess( xRootNameAccess, "SubStorage1" );
179 if ( xResultSubStorage == null )
180 return false;
182 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage,
183 false,
184 ElementModes.READ,
185 aRelations ) )
186 return false;
188 XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage );
189 if ( xChildAccess == null )
191 m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" );
192 return false;
195 if ( !xChildAccess.hasByName( "SubStream2" )
196 || !xResultSubStorage.isStreamElement( "SubStream2" )
197 || xResultSubStorage.isStorageElement( "SubStream2" ) )
199 m_aTestHelper.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" );
200 return false;
203 return true;
205 catch( Exception e )
207 m_aTestHelper.Error( "Exception: " + e );
208 return false;
212 public XStorage getStorageFromNameAccess( XNameAccess xAccess, String sName )
216 Object oStorage = xAccess.getByName( sName );
217 XStorage xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStorage );
219 if ( xResult != null )
220 return xResult;
221 else
222 m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess!" );
224 catch( Exception e )
226 m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess, exception: " + e );
229 return null;