fix toolbar import
[ooovba.git] / package / qa / storages / Test13.java
blob443744dc1cea283bc7aa11076a3a60129339a710
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;
11 import com.sun.star.embed.*;
13 import share.LogWriter;
14 import complex.storages.TestHelper;
15 import complex.storages.StorageTest;
17 public class Test13 implements StorageTest {
19 XMultiServiceFactory m_xMSF;
20 XSingleServiceFactory m_xStorageFactory;
21 TestHelper m_aTestHelper;
23 public Test13( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test13: " );
30 public boolean test()
32 String aStreamPrefix = "";
33 for ( int nInd = 0; nInd < 4; ++nInd, aStreamPrefix += "SubStorage" + nInd )
34 if ( !testForPath( aStreamPrefix ) )
35 return false;
37 return true;
40 public boolean testForPath( String aStreamPrefix )
42 try
44 String aSubStream1Path = aStreamPrefix + "SubStream1";
45 String aSubStream2Path = aStreamPrefix + "SubStream2";
46 String aSubStream3Path = aStreamPrefix + "SubStream3";
48 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
49 if ( sTempFileURL == null || sTempFileURL == "" )
51 m_aTestHelper.Error( "No valid temporary file was created!" );
52 return false;
55 // create temporary storage based on a previously created temporary file
56 Object pArgs[] = new Object[2];
57 pArgs[0] = (Object) sTempFileURL;
58 pArgs[1] = new Integer( ElementModes.WRITE );
60 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
61 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
62 if ( xTempFileStorage == null )
64 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
65 return false;
68 byte pBytes1[] = { 1, 1, 1, 1, 1 };
70 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
71 // and commit
72 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, true ) )
73 return false;
75 byte pBytes2[] = { 2, 2, 2, 2, 2 };
77 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
78 // and commit
79 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, true ) )
80 return false;
82 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
83 // and don't commit
84 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, false ) )
85 return false;
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
89 "MediaType3",
90 true,
91 ElementModes.WRITE ) )
92 return false;
94 // commit the root storage so the contents must be stored now
95 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
96 return false;
98 // dispose used storages to free resources
99 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
100 return false;
102 // ================================================
103 // now reopen the storage,
104 // check all the written and copied information
105 // and change it
106 // ================================================
108 // the temporary file must not be locked any more after storage disposing
109 oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
110 xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
111 if ( xTempFileStorage == null )
113 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
114 return false;
117 if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) )
118 return false;
120 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1 ) )
121 return false;
123 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2 ) )
124 return false;
126 if ( !m_aTestHelper.cantOpenStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ ) )
127 return false;
129 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
130 // and commit
131 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, true ) )
132 return false;
134 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
135 // and don't commit
136 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, false ) )
137 return false;
139 // commit the root storage so the contents must be stored now
140 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
141 return false;
143 // dispose used storages to free resources
144 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
145 return false;
147 // ================================================
148 // now reopen the storage,
149 // check all the written information
150 // ================================================
152 // the temporary file must not be locked any more after storage disposing
153 pArgs[1] = new Integer( ElementModes.READ );
154 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
155 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
156 if ( xResultStorage == null )
158 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
159 return false;
162 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
163 return false;
165 if ( !m_aTestHelper.checkStreamH( xResultStorage, aSubStream1Path, "MediaType3", true, pBytes2 ) )
166 return false;
168 // the following stream was not commited last time, so the last change must be lost
169 if ( !m_aTestHelper.checkStreamH( xResultStorage, aSubStream2Path, "MediaType2", false, pBytes2 ) )
170 return false;
172 // dispose used storages to free resources
173 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
174 return false;
176 return true;
178 catch( Exception e )
180 m_aTestHelper.Error( "Exception: " + e );
181 return false;