2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex
.storages
;
23 import java
.io
.FileInputStream
;
24 import java
.util
.zip
.ZipInputStream
;
25 import java
.util
.zip
.ZipEntry
;
27 import com
.sun
.star
.uno
.XInterface
;
28 import com
.sun
.star
.lang
.XMultiServiceFactory
;
29 import com
.sun
.star
.lang
.XSingleServiceFactory
;
31 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.io
.XStream
;
35 import com
.sun
.star
.io
.XInputStream
;
37 import com
.sun
.star
.embed
.*;
39 import share
.LogWriter
;
40 import complex
.storages
.TestHelper
;
41 import complex
.storages
.StorageTest
;
43 public class RegressionTest_i61909
implements StorageTest
{
45 XMultiServiceFactory m_xMSF
;
46 XSingleServiceFactory m_xStorageFactory
;
47 TestHelper m_aTestHelper
;
49 public RegressionTest_i61909( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
52 m_xStorageFactory
= xStorageFactory
;
53 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i61909: " );
60 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
61 if ( sTempFileURL
== null || sTempFileURL
== "" )
63 m_aTestHelper
.Error( "No valid temporary file was created!" );
67 // create storage based on the temporary stream
68 Object pArgs
[] = new Object
[2];
69 pArgs
[0] = (Object
) sTempFileURL
;
70 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
72 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
73 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
74 if ( xTempStorage
== null )
76 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
80 byte pBytes
[] = new byte[36000];
81 for ( int nInd
= 0; nInd
< 36000; nInd
++ )
82 pBytes
[nInd
] = (byte)( nInd
% 128 );
84 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
85 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes
) )
88 // open a new substorage
89 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
92 if ( xTempSubStorage
== null )
94 m_aTestHelper
.Error( "Can't create substorage!" );
98 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
99 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", true, pBytes
) )
102 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
103 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
106 ElementModes
.WRITE
) )
109 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
110 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
113 ElementModes
.WRITE
) )
116 // commit substorage first
117 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
120 // commit the root storage so the contents must be stored now
121 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
124 // dispose used storage to free resources
125 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
129 // now reopen the storage, and insert a new stream
132 Object oStep2TempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
133 XStorage xStep2TempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStep2TempStorage
);
134 if ( xStep2TempStorage
== null )
136 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
140 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
141 if ( !m_aTestHelper
.WriteBytesToSubstream( xStep2TempStorage
, "SubStream3", "MediaType5", true, pBytes
) )
144 // commit the root storage so the contents must be stored now
145 if ( !m_aTestHelper
.commitStorage( xStep2TempStorage
) )
148 // dispose used storage to free resources
149 if ( !m_aTestHelper
.disposeStorage( xStep2TempStorage
) )
153 // now access the stream using ZipInputStream
156 URI aUri
= new URI( sTempFileURL
);
157 File aFile
= new File( aUri
);
158 FileInputStream aFileStream
= new FileInputStream( aFile
);
159 ZipInputStream aZipStream
= new ZipInputStream( aFileStream
);
163 m_aTestHelper
.Message( "Available entries:" );
164 while ( ( aEntry
= aZipStream
.getNextEntry() ) != null )
167 m_aTestHelper
.Message( aEntry
.getName() );
172 m_aTestHelper
.Error( "Wrong number of entries: " + nNumber
+ ", Expected: 6" );
180 m_aTestHelper
.Error( "Exception: " + e
);