merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test16.java
blob1b573dc126a1f226d0eb728dc0bc1c7ed2fe8cc5
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 Test16 implements StorageTest {
19 XMultiServiceFactory m_xMSF;
20 XSingleServiceFactory m_xStorageFactory;
21 TestHelper m_aTestHelper;
23 public Test16( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test16: " );
30 public boolean test()
32 try
34 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
35 if ( sTempFileURL == null || sTempFileURL == "" )
37 m_aTestHelper.Error( "No valid temporary file was created!" );
38 return false;
41 // create temporary storage based on arbitrary medium
42 // after such a storage is closed it is lost
43 Object oTempStorage = m_xStorageFactory.createInstance();
44 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
45 if ( xTempStorage == null )
47 m_aTestHelper.Error( "Can't create temporary storage representation!" );
48 return false;
51 // open a new substorage
52 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
53 "SubStorage\u0442\u0435\u0441\u04421",
54 ElementModes.WRITE );
55 if ( xTempSubStorage == null )
57 m_aTestHelper.Error( "Can't create substorage!" );
58 return false;
61 byte pBytes1[] = { 1, 1, 1, 1, 1 };
63 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
64 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) )
65 return false;
67 byte pBytes2[] = { 2, 2, 2, 2, 2 };
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) )
71 return false;
73 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
74 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
75 "MediaType3",
76 true,
77 ElementModes.WRITE ) )
78 return false;
80 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
81 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
82 "MediaType4",
83 false,
84 ElementModes.WRITE ) )
85 return false;
87 // create temporary storage based on a previously created temporary file
88 Object pArgs[] = new Object[2];
89 pArgs[0] = (Object) sTempFileURL;
90 pArgs[1] = new Integer( ElementModes.WRITE );
92 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
93 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
94 if ( xTempFileStorage == null )
96 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
97 return false;
100 // copy xTempStorage to xTempFileStorage
101 // xTempFileStorage will be automatically commited
102 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
103 return false;
105 // dispose used storages to free resources
106 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
107 return false;
109 // ================================================
110 // now check all the written and copied information
111 // ================================================
113 // the temporary file must not be locked any more after storage disposing
114 pArgs[1] = new Integer( ElementModes.WRITE );
115 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
116 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
117 if ( xResultStorage == null )
119 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
120 return false;
123 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) )
124 return false;
126 // open existing substorage
127 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
128 "SubStorage\u0442\u0435\u0441\u04421",
129 ElementModes.READ );
130 if ( xResultSubStorage == null )
132 m_aTestHelper.Error( "Can't open existing substorage!" );
133 return false;
136 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
137 return false;
139 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) )
140 return false;
142 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) )
143 return false;
145 // dispose used storages to free resources
146 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
147 return false;
149 return true;
151 catch( Exception e )
153 m_aTestHelper.Error( "Exception: " + e );
154 return false;