merge the formfield patch from ooo-build
[ooovba.git] / package / qa / ofopxmlstorages / Test02.java
blob3b85a5b5c9c81b76e77473dc9836df4f24eaeb5e
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;
10 import com.sun.star.io.XStream;
11 import com.sun.star.io.XInputStream;
13 import com.sun.star.embed.*;
14 import com.sun.star.beans.StringPair;
16 import share.LogWriter;
17 import complex.ofopxmlstorages.TestHelper;
18 import complex.ofopxmlstorages.StorageTest;
20 public class Test02 implements StorageTest {
22 XMultiServiceFactory m_xMSF;
23 XSingleServiceFactory m_xStorageFactory;
24 TestHelper m_aTestHelper;
26 public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
28 m_xMSF = xMSF;
29 m_xStorageFactory = xStorageFactory;
30 m_aTestHelper = new TestHelper( aLogWriter, "Test02: " );
33 public boolean test()
35 try
37 StringPair[][] aRelations =
38 { { new StringPair( "Id", "Num1" ) },
39 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
40 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
41 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
42 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
43 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
44 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
48 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
49 if ( xTempFileStream == null )
50 return false;
52 // create storage based on the temporary stream
53 XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
54 xTempFileStream,
55 ElementModes.WRITE );
56 if ( xTempStorage == null )
58 m_aTestHelper.Error( "Can't create temporary storage representation!" );
59 return false;
62 // open a new substorage
63 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
64 "SubStorage1",
65 ElementModes.WRITE );
66 if ( xTempSubStorage == null )
68 m_aTestHelper.Error( "Can't create substorage!" );
69 return false;
72 byte pBytes1[] = { 1, 1, 1, 1, 1 };
74 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
75 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
76 "SubStream1",
77 "MediaType1",
78 true,
79 pBytes1,
80 aRelations ) )
81 return false;
83 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
85 true,
86 ElementModes.WRITE,
87 aRelations ) )
88 return false;
90 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
91 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
92 false,
93 ElementModes.WRITE,
94 aRelations ) )
95 return false;
97 // commit substorage first
98 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
99 return false;
101 // commit the root storage so the contents must be stored now
102 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
103 return false;
105 // dispose used storage to free resources
106 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
107 return false;
110 // ================================================
111 // now check all the written information
112 // ================================================
114 // close the output part of the temporary stream
115 // the output part must present since we already wrote to the stream
116 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
117 return false;
119 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
120 if ( xTempInStream == null )
121 return false;
124 // open input stream
125 XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, xTempInStream );
126 if ( xResultStorage == null )
128 m_aTestHelper.Error( "Can't open storage based on input stream!" );
129 return false;
132 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, true, ElementModes.READ, aRelations ) )
133 return false;
135 // open existing substorage
136 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
137 "SubStorage1",
138 ElementModes.READ );
139 if ( xResultSubStorage == null )
141 m_aTestHelper.Error( "Can't open existing substorage!" );
142 return false;
145 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage,
146 false,
147 ElementModes.READ,
148 aRelations ) )
149 return false;
151 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, aRelations ) )
152 return false;
154 return true;
156 catch( Exception e )
158 m_aTestHelper.Error( "Exception: " + e );
159 return false;