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
;
29 int nMaxTestLen
= 60000;
31 public RegressionTest_125919( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
34 m_xStorageFactory
= xStorageFactory
;
35 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_125919: " );
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!" );
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!" );
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!" );
86 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream" + 0, "MediaType1", true, pBytes0
) )
88 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream" + 18, "MediaType2", true, pBytes18
) )
90 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream" + 36, "MediaType3", true, pBytes36
) )
93 if ( nAvailableBytes
> 0 && nAvailableBytes
% 100 == 0 )
94 System
.out
.println( " " + nAvailableBytes
);
96 if ( nAvailableBytes
> 0 && nAvailableBytes
% 2 == 1 )
97 System
.out
.print( "#" );
103 System
.out
.println( "" );
104 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
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 )
119 System
.out
.println( "" );
120 m_aTestHelper
.Error( "Unexpected exception: " + e
+ "\nnAvailableBytes = " + nAvailableBytes
);
129 m_aTestHelper
.Error( "Exception: " + e
);