Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i84234.java
blobbe011000a7509d5fa6d0b887ed343753b6dc9e0e
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_i84234 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i84234( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i84234: " );
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( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) )
67 return false;
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) )
71 return false;
74 // ================================================
75 // commit the storages and dispose them
76 // ================================================
78 // commit substorage
79 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
80 return false;
82 // dispose substorage
83 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
84 return false;
86 // commit storage
87 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
88 return false;
90 // dispose storage
91 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
92 return false;
94 // ================================================
95 // reopen the storages in readwrite mode and check Compressed flag
96 // ================================================
98 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
99 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
100 if ( xTempStorage == null )
102 m_aTestHelper.Error( "Can't create temporary storage representation!" );
103 return false;
106 // open a new substorage
107 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
108 "SubStorage1",
109 ElementModes.WRITE );
110 if ( xTempSubStorage == null )
112 m_aTestHelper.Error( "Can't create substorage!" );
113 return false;
116 if ( !m_aTestHelper.checkStream( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) )
117 return false;
119 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) )
120 return false;
122 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
123 // any resource, later the garbage collector will release the object and it must die by refcount
125 return true;
127 catch( Exception e )
129 m_aTestHelper.Error( "Exception: " + e );
130 return false;