fix toolbar import
[ooovba.git] / package / qa / storages / RegressionTest_i61909.java
blobe2ff45fbc1c1f20c5074611ffcf4b88379730b53
1 package complex.storages;
3 import java.net.URI;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.util.zip.ZipInputStream;
7 import java.util.zip.ZipEntry;
9 import com.sun.star.uno.XInterface;
10 import com.sun.star.lang.XMultiServiceFactory;
11 import com.sun.star.lang.XSingleServiceFactory;
13 import com.sun.star.bridge.XUnoUrlResolver;
14 import com.sun.star.uno.UnoRuntime;
15 import com.sun.star.uno.XInterface;
16 import com.sun.star.io.XStream;
17 import com.sun.star.io.XInputStream;
19 import com.sun.star.embed.*;
21 import share.LogWriter;
22 import complex.storages.TestHelper;
23 import complex.storages.StorageTest;
25 public class RegressionTest_i61909 implements StorageTest {
27 XMultiServiceFactory m_xMSF;
28 XSingleServiceFactory m_xStorageFactory;
29 TestHelper m_aTestHelper;
31 public RegressionTest_i61909( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
33 m_xMSF = xMSF;
34 m_xStorageFactory = xStorageFactory;
35 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i61909: " );
38 public boolean test()
40 try
42 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
43 if ( sTempFileURL == null || sTempFileURL == "" )
45 m_aTestHelper.Error( "No valid temporary file was created!" );
46 return false;
49 // create storage based on the temporary stream
50 Object pArgs[] = new Object[2];
51 pArgs[0] = (Object) sTempFileURL;
52 pArgs[1] = new Integer( ElementModes.WRITE );
54 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
55 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
56 if ( xTempStorage == null )
58 m_aTestHelper.Error( "Can't create temporary storage representation!" );
59 return false;
62 byte pBytes[] = new byte[36000];
63 for ( int nInd = 0; nInd < 36000; nInd++ )
64 pBytes[nInd] = (byte)( nInd % 128 );
66 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
67 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes ) )
68 return false;
70 // open a new substorage
71 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
72 "SubStorage1",
73 ElementModes.WRITE );
74 if ( xTempSubStorage == null )
76 m_aTestHelper.Error( "Can't create substorage!" );
77 return false;
80 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
81 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "MediaType2", true, pBytes ) )
82 return false;
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
86 "MediaType3",
87 true,
88 ElementModes.WRITE ) )
89 return false;
91 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
92 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
93 "MediaType4",
94 false,
95 ElementModes.WRITE ) )
96 return false;
98 // commit substorage first
99 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
100 return false;
102 // commit the root storage so the contents must be stored now
103 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
104 return false;
106 // dispose used storage to free resources
107 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
108 return false;
110 // ================================================
111 // now reopen the storage, and insert a new stream
112 // ================================================
114 Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
115 XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage );
116 if ( xStep2TempStorage == null )
118 m_aTestHelper.Error( "Can't create temporary storage representation!" );
119 return false;
122 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
123 if ( !m_aTestHelper.WriteBytesToSubstream( xStep2TempStorage, "SubStream3", "MediaType5", true, pBytes ) )
124 return false;
126 // commit the root storage so the contents must be stored now
127 if ( !m_aTestHelper.commitStorage( xStep2TempStorage ) )
128 return false;
130 // dispose used storage to free resources
131 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
132 return false;
134 // ================================================
135 // now access the stream using ZipInputStream
136 // ================================================
138 URI aUri = new URI( sTempFileURL );
139 File aFile = new File( aUri );
140 FileInputStream aFileStream = new FileInputStream( aFile );
141 ZipInputStream aZipStream = new ZipInputStream( aFileStream );
143 ZipEntry aEntry;
144 int nNumber = 0;
145 m_aTestHelper.Message( "Available entries:" );
146 while ( ( aEntry = aZipStream.getNextEntry() ) != null )
148 nNumber++;
149 m_aTestHelper.Message( aEntry.getName() );
152 if ( nNumber != 6 )
154 m_aTestHelper.Error( "Wrong number of entries: " + nNumber + ", Expected: 6" );
155 return false;
158 return true;
160 catch( Exception e )
162 m_aTestHelper.Error( "Exception: " + e );
163 return false;