merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test02.java
blob2da897a850f84ccbc8a2693e35c3a74f6ca8de5f
1 package complex.storages;
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.*;
15 import share.LogWriter;
16 import complex.storages.TestHelper;
17 import complex.storages.StorageTest;
19 public class Test02 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "Test02: " );
32 public boolean test()
34 try
36 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
37 if ( xTempFileStream == null )
38 return false;
40 // create storage based on the temporary stream
41 Object pArgs[] = new Object[2];
42 pArgs[0] = (Object) xTempFileStream;
43 pArgs[1] = new Integer( ElementModes.WRITE );
45 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
46 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
47 if ( xTempStorage == null )
49 m_aTestHelper.Error( "Can't create temporary storage representation!" );
50 return false;
53 // open a new substorage
54 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
55 "SubStorage1",
56 ElementModes.WRITE );
57 if ( xTempSubStorage == null )
59 m_aTestHelper.Error( "Can't create substorage!" );
60 return false;
63 byte pBigBytes[] = new byte[33000];
64 for ( int nInd = 0; nInd < 33000; nInd++ )
65 pBigBytes[nInd] = (byte)( nInd % 128 );
67 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
68 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
69 return false;
71 byte pBytes1[] = { 1, 1, 1, 1, 1 };
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
75 return false;
77 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
78 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
79 "MediaType2",
80 true,
81 ElementModes.WRITE ) )
82 return false;
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
86 "MediaType3",
87 false,
88 ElementModes.WRITE ) )
89 return false;
91 // commit substorage first
92 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
93 return false;
95 // commit the root storage so the contents must be stored now
96 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
97 return false;
99 // dispose used storage to free resources
100 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
101 return false;
104 // ================================================
105 // now check all the written information
106 // ================================================
108 // close the output part of the temporary stream
109 // the output part must present since we already wrote to the stream
110 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
111 return false;
113 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
114 if ( xTempInStream == null )
115 return false;
118 // open input stream
119 // since no mode is provided the result storage must be opened readonly
120 Object pOneArg[] = new Object[1];
121 pOneArg[0] = (Object) xTempInStream;
123 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
124 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
125 if ( xResultStorage == null )
127 m_aTestHelper.Error( "Can't open storage based on input stream!" );
128 return false;
131 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType2", true, ElementModes.READ ) )
132 return false;
134 // open existing substorage
135 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
136 "SubStorage1",
137 ElementModes.READ );
138 if ( xResultSubStorage == null )
140 m_aTestHelper.Error( "Can't open existing substorage!" );
141 return false;
144 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType3", false, ElementModes.READ ) )
145 return false;
147 if ( !m_aTestHelper.checkStream( xResultSubStorage, "BigSubStream1", "MediaType1", true, pBigBytes ) )
148 return false;
150 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
151 return false;
153 return true;
155 catch( Exception e )
157 m_aTestHelper.Error( "Exception: " + e );
158 return false;