1 package complex
.storages
;
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
)
34 m_xStorageFactory
= xStorageFactory
;
35 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i61909: " );
42 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
43 if ( sTempFileURL
== null || sTempFileURL
== "" )
45 m_aTestHelper
.Error( "No valid temporary file was created!" );
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!" );
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
) )
70 // open a new substorage
71 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
74 if ( xTempSubStorage
== null )
76 m_aTestHelper
.Error( "Can't create substorage!" );
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
) )
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
88 ElementModes
.WRITE
) )
91 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
92 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
95 ElementModes
.WRITE
) )
98 // commit substorage first
99 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
102 // commit the root storage so the contents must be stored now
103 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
106 // dispose used storage to free resources
107 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
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!" );
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
) )
126 // commit the root storage so the contents must be stored now
127 if ( !m_aTestHelper
.commitStorage( xStep2TempStorage
) )
130 // dispose used storage to free resources
131 if ( !m_aTestHelper
.disposeStorage( xStep2TempStorage
) )
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
);
145 m_aTestHelper
.Message( "Available entries:" );
146 while ( ( aEntry
= aZipStream
.getNextEntry() ) != null )
149 m_aTestHelper
.Message( aEntry
.getName() );
154 m_aTestHelper
.Error( "Wrong number of entries: " + nNumber
+ ", Expected: 6" );
162 m_aTestHelper
.Error( "Exception: " + e
);