xref: /trunk/main/package/qa/storages/RegressionTest_125919.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 package complex.storages;
2 
3 import java.lang.Integer;
4 
5 import com.sun.star.uno.XInterface;
6 import com.sun.star.lang.XMultiServiceFactory;
7 import com.sun.star.lang.XSingleServiceFactory;
8 
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;
14 
15 import com.sun.star.embed.*;
16 
17 import share.LogWriter;
18 import complex.storages.TestHelper;
19 import complex.storages.StorageTest;
20 import complex.storages.BorderedStream;
21 
22 public class RegressionTest_125919 implements StorageTest {
23 
24     XMultiServiceFactory m_xMSF;
25     XSingleServiceFactory m_xStorageFactory;
26     TestHelper m_aTestHelper;
27 
28     int nMinTestLen = 0;
29     int nMaxTestLen = 60000;
30 
31     public RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
32     {
33         m_xMSF = xMSF;
34         m_xStorageFactory = xStorageFactory;
35         m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_125919: " );
36     }
37 
38     public boolean test()
39     {
40         try
41         {
42             byte[] pBytes0 = new byte[0];
43             byte[] pBytes18 = new byte[18000];
44             byte[] pBytes36 = new byte[36000];
45 
46             for ( int nInitInd = 0; nInitInd < 36000; nInitInd++ )
47             {
48                 pBytes36[nInitInd] = ( new Integer( nInitInd >> ( ( nInitInd % 2 ) * 8 ) ) ).byteValue();
49                 if ( nInitInd < 18000 )
50                     pBytes18[nInitInd] = ( new Integer( 256  - pBytes36[nInitInd] ) ).byteValue();
51             }
52 
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++ )
56             {
57                 Object oBStream = new BorderedStream( nAvailableBytes );
58                 XStream xBorderedStream = (XStream)UnoRuntime.queryInterface( XStream.class, oBStream );
59                 if ( xBorderedStream == null )
60                 {
61                     m_aTestHelper.Error( "Can't create bordered stream!" );
62                     return false;
63                 }
64 
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 );
69 
70                 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
71                 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
72                 if ( xTempStorage == null )
73                 {
74                     m_aTestHelper.Error( "Can't create temporary storage representation!" );
75                     return false;
76                 }
77 
78                 XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xTempStorage );
79                 if ( xTransact == null )
80                 {
81                     m_aTestHelper.Error( "This test is designed for storages in transacted mode!" );
82                     return false;
83                 }
84 
85 
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;
92 
93                 if ( nAvailableBytes > 0 && nAvailableBytes % 100 == 0 )
94                     System.out.println( " " + nAvailableBytes );
95 
96                 if ( nAvailableBytes > 0 && nAvailableBytes % 2 == 1 )
97                     System.out.print( "#" );
98 
99                 try
100                 {
101                     xTransact.commit();
102 
103                     System.out.println( "" );
104                     if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
105                         return false;
106 
107                     // SUCCESS
108                     return true;
109                 }
110                 catch( UseBackupException aExc )
111                 {
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;
116                 }
117                 catch( Exception e )
118                 {
119                     System.out.println( "" );
120                     m_aTestHelper.Error( "Unexpected exception: " + e + "\nnAvailableBytes = " + nAvailableBytes );
121                     return false;
122                 }
123             }
124 
125             return false;
126         }
127         catch( Exception e )
128         {
129             m_aTestHelper.Error( "Exception: " + e );
130             return false;
131         }
132     }
133 }
134 
135