fix toolbar import
[ooovba.git] / package / qa / storages / RegressionTest_125919.java
blob89f78bc1179a8d8b6eaf893aff65052b3acf8ff9
1 package complex.storages;
3 import java.lang.Integer;
5 import com.sun.star.uno.XInterface;
6 import com.sun.star.lang.XMultiServiceFactory;
7 import com.sun.star.lang.XSingleServiceFactory;
9 import com.sun.star.bridge.XUnoUrlResolver;
10 import com.sun.star.uno.UnoRuntime;
11 import com.sun.star.uno.XInterface;
12 import com.sun.star.io.XStream;
13 import com.sun.star.io.XInputStream;
15 import com.sun.star.embed.*;
17 import share.LogWriter;
18 import complex.storages.TestHelper;
19 import complex.storages.StorageTest;
20 import complex.storages.BorderedStream;
22 public class RegressionTest_125919 implements StorageTest {
24 XMultiServiceFactory m_xMSF;
25 XSingleServiceFactory m_xStorageFactory;
26 TestHelper m_aTestHelper;
28 int nMinTestLen = 0;
29 int nMaxTestLen = 60000;
31 public RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
33 m_xMSF = xMSF;
34 m_xStorageFactory = xStorageFactory;
35 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_125919: " );
38 public boolean test()
40 try
42 byte[] pBytes0 = new byte[0];
43 byte[] pBytes18 = new byte[18000];
44 byte[] pBytes36 = new byte[36000];
46 for ( int nInitInd = 0; nInitInd < 36000; nInitInd++ )
48 pBytes36[nInitInd] = ( new Integer( nInitInd >> ( ( nInitInd % 2 ) * 8 ) ) ).byteValue();
49 if ( nInitInd < 18000 )
50 pBytes18[nInitInd] = ( new Integer( 256 - pBytes36[nInitInd] ) ).byteValue();
53 System.out.println( "This test can take up to some hours. The file size currently is about 50000." );
54 System.out.println( "Progress: " );
55 for ( int nAvailableBytes = nMinTestLen; nAvailableBytes < nMaxTestLen; nAvailableBytes++ )
57 Object oBStream = new BorderedStream( nAvailableBytes );
58 XStream xBorderedStream = (XStream)UnoRuntime.queryInterface( XStream.class, oBStream );
59 if ( xBorderedStream == null )
61 m_aTestHelper.Error( "Can't create bordered stream!" );
62 return false;
65 // create storage based on the temporary stream
66 Object pArgs[] = new Object[2];
67 pArgs[0] = (Object) xBorderedStream;
68 pArgs[1] = new Integer( ElementModes.WRITE );
70 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
71 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
72 if ( xTempStorage == null )
74 m_aTestHelper.Error( "Can't create temporary storage representation!" );
75 return false;
78 XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xTempStorage );
79 if ( xTransact == null )
81 m_aTestHelper.Error( "This test is designed for storages in transacted mode!" );
82 return false;
86 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 0, "MediaType1", true, pBytes0 ) )
87 return false;
88 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 18, "MediaType2", true, pBytes18 ) )
89 return false;
90 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 36, "MediaType3", true, pBytes36 ) )
91 return false;
93 if ( nAvailableBytes > 0 && nAvailableBytes % 100 == 0 )
94 System.out.println( " " + nAvailableBytes );
96 if ( nAvailableBytes > 0 && nAvailableBytes % 2 == 1 )
97 System.out.print( "#" );
99 try
101 xTransact.commit();
103 System.out.println( "" );
104 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
105 return false;
107 // SUCCESS
108 return true;
110 catch( UseBackupException aExc )
112 // when there is not enough place in the target location and the target file is empty
113 // the direct writing will fail and must throw this exception with empty URL
114 if ( aExc.TemporaryFileURL.length() != 0 )
115 return false;
117 catch( Exception e )
119 System.out.println( "" );
120 m_aTestHelper.Error( "Unexpected exception: " + e + "\nnAvailableBytes = " + nAvailableBytes );
121 return false;
125 return false;
127 catch( Exception e )
129 m_aTestHelper.Error( "Exception: " + e );
130 return false;