Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i35095.java
blobdd5779a517526f0f90d876afa21486384f9b4c88
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_i35095 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i35095( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i35095: " );
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 byte pBytes[] = new byte[36000];
54 for ( int nInd = 0; nInd < 36000; nInd++ )
55 pBytes[nInd] = (byte)( nInd % 128 );
57 String sPass = "12345";
59 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
60 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes, sPass ) )
61 return false;
63 // open a new substorage
64 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
65 "SubStorage1",
66 ElementModes.WRITE );
67 if ( xTempSubStorage == null )
69 m_aTestHelper.Error( "Can't create substorage!" );
70 return false;
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) )
75 return false;
77 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
78 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
79 "MediaType3",
80 true,
81 ElementModes.WRITE ) )
82 return false;
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
86 "MediaType4",
87 false,
88 ElementModes.WRITE ) )
89 return false;
91 // commit substorage first
92 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
93 return false;
95 // commit the root storage so the contents must be stored now
96 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
97 return false;
99 // dispose used storage to free resources
100 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
101 return false;
103 // ================================================
104 // now check all the written information
105 // and the raw stream contents
106 // ================================================
108 // close the output part of the temporary stream
109 // the output part must present since we already wrote to the stream
110 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
111 return false;
113 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
114 if ( xTempInStream == null )
115 return false;
117 // open input stream
118 // since no mode is provided the result storage must be opened readonly
119 Object pOneArg[] = new Object[1];
120 pOneArg[0] = (Object) xTempInStream;
122 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
123 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
124 if ( xResultStorage == null )
126 m_aTestHelper.Error( "Can't open storage based on input stream!" );
127 return false;
130 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
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.compareRawMethodsOnEncrStream( xResultStorage, "SubStream1" ) )
147 return false;
149 if ( !m_aTestHelper.compareRawMethodsOnEncrStream( xResultSubStorage, "SubStream2" ) )
150 return false;
152 // dispose used storages to free resources
153 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
154 return false;
156 return true;
158 catch( Exception e )
160 m_aTestHelper.Error( "Exception: " + e );
161 return false;