merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test18.java
bloba79e2d3c2b9c3fb7df560d0e5b5cda9471bd6297
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 Test18 implements StorageTest {
19 XMultiServiceFactory m_xMSF;
20 XSingleServiceFactory m_xStorageFactory;
21 TestHelper m_aTestHelper;
23 public Test18( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test18: " );
30 public boolean test()
32 try
34 // test the default value of Compressed property
35 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
36 if ( sTempFileURL == null || sTempFileURL == "" )
38 m_aTestHelper.Error( "No valid temporary file was created!" );
39 return false;
42 // create temporary storage based on arbitrary medium
43 // after such a storage is closed it is lost
44 Object oTempStorage = m_xStorageFactory.createInstance();
45 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
46 if ( xTempStorage == null )
48 m_aTestHelper.Error( "Can't create temporary storage representation!" );
49 return false;
52 // open a new substorage
53 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
54 "SubStorage1",
55 ElementModes.WRITE );
56 if ( xTempSubStorage == null )
58 m_aTestHelper.Error( "Can't create substorage!" );
59 return false;
62 byte pBytes1[] = { 1, 1, 1, 1, 1 };
64 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
65 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream1", "image/jpeg", pBytes1 ) )
66 return false;
68 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
69 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream2", "image/png", pBytes1 ) )
70 return false;
72 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
73 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream3", "image/gif", pBytes1 ) )
74 return false;
76 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
77 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream4", "MediaType1", pBytes1 ) )
78 return false;
80 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
81 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
82 "MediaType3",
83 true,
84 ElementModes.WRITE ) )
85 return false;
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
89 "MediaType4",
90 false,
91 ElementModes.WRITE ) )
92 return false;
94 // create temporary storage based on a previously created temporary file
95 Object pArgs[] = new Object[2];
96 pArgs[0] = (Object) sTempFileURL;
97 pArgs[1] = new Integer( ElementModes.WRITE );
99 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
100 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
101 if ( xTempFileStorage == null )
103 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
104 return false;
107 // copy xTempStorage to xTempFileStorage
108 // xTempFileStorage will be automatically commited
109 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
110 return false;
112 // dispose used storages to free resources
113 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
114 return false;
116 // ================================================
117 // now check all the written and copied information
118 // ================================================
120 // the temporary file must not be locked any more after storage disposing
121 pArgs[1] = new Integer( ElementModes.WRITE );
122 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
123 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
124 if ( xResultStorage == null )
126 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
127 return false;
130 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) )
131 return false;
133 // open existing substorage
134 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
135 "SubStorage1",
136 ElementModes.READ );
137 if ( xResultSubStorage == null )
139 m_aTestHelper.Error( "Can't open existing substorage!" );
140 return false;
143 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
144 return false;
146 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "image/jpeg", false, pBytes1 ) )
147 return false;
149 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream2", "image/png", false, pBytes1 ) )
150 return false;
152 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream3", "image/gif", false, pBytes1 ) )
153 return false;
155 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream4", "MediaType1", true, pBytes1 ) )
156 return false;
158 // dispose used storages to free resources
159 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
160 return false;
162 return true;
164 catch( Exception e )
166 m_aTestHelper.Error( "Exception: " + e );
167 return false;