Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i46848.java
blob339b35f9ed83d7e27f118cda6351078fe6f0394d
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 RegressionTest_i46848 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i46848( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i46848: " );
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 pBytes1[] = { 1, 1, 1, 1, 1 };
65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
66 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
67 return false;
69 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
70 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
71 "MediaType2",
72 true,
73 ElementModes.WRITE ) )
74 return false;
76 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
77 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
78 "MediaType3",
79 false,
80 ElementModes.WRITE ) )
81 return false;
83 // commit substorage first
84 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
85 return false;
87 // commit the root storage so the contents must be stored now
88 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
89 return false;
91 // dispose substorage
92 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
93 return false;
95 // dispose the temporary storage
96 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
97 return false;
99 // ================================================
100 // create a new storage based on the stream and change the mediatype of the substorage
101 // as described in the bug description
102 // ================================================
104 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
105 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
106 if ( xTempStorage == null )
108 m_aTestHelper.Error( "Can't create temporary storage representation!" );
109 return false;
112 // open the substorage
113 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
114 "SubStorage1",
115 ElementModes.WRITE );
116 if ( xTempSubStorage == null )
118 m_aTestHelper.Error( "Can't create substorage!" );
119 return false;
122 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
123 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
124 "ChangedMediaType3",
125 false,
126 ElementModes.WRITE ) )
127 return false;
129 // commit substorage first
130 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
131 return false;
133 // commit the root storage so the contents must be stored now
134 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
135 return false;
137 // dispose substorage
138 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
139 return false;
141 // dispose the temporary storage
142 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
143 return false;
145 // ================================================
146 // create a new readonly storage based on the stream and check the contents
147 // ================================================
149 pArgs[1] = new Integer( ElementModes.READ );
150 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
151 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
152 if ( xTempStorage == null )
154 m_aTestHelper.Error( "Can't create temporary storage representation!" );
155 return false;
158 // open the substorage
159 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
160 "SubStorage1",
161 ElementModes.READ );
162 if ( xTempSubStorage == null )
164 m_aTestHelper.Error( "Can't create substorage!" );
165 return false;
168 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
169 return false;
171 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "ChangedMediaType3", false, ElementModes.READ ) )
172 return false;
174 // the MediaType and the contents must be up to date
175 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
176 return false;
178 // dispose used storage to free resources
179 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
180 return false;
182 return true;
184 catch( Exception e )
186 m_aTestHelper.Error( "Exception: " + e );
187 return false;