bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i61909.java
bloba73d8677f2b9e1cde86c61f20b21fa6d4360cf9b
1 /*
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;
21 import java.net.URI;
22 import java.io.File;
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 )
51 m_xMSF = xMSF;
52 m_xStorageFactory = xStorageFactory;
53 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i61909: " );
56 public boolean test()
58 try
60 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
61 if ( sTempFileURL == null || sTempFileURL == "" )
63 m_aTestHelper.Error( "No valid temporary file was created!" );
64 return false;
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!" );
77 return false;
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 ) )
86 return false;
88 // open a new substorage
89 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
90 "SubStorage1",
91 ElementModes.WRITE );
92 if ( xTempSubStorage == null )
94 m_aTestHelper.Error( "Can't create substorage!" );
95 return false;
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 ) )
100 return false;
102 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
103 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
104 "MediaType3",
105 true,
106 ElementModes.WRITE ) )
107 return false;
109 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
110 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
111 "MediaType4",
112 false,
113 ElementModes.WRITE ) )
114 return false;
116 // commit substorage first
117 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
118 return false;
120 // commit the root storage so the contents must be stored now
121 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
122 return false;
124 // dispose used storage to free resources
125 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
126 return false;
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!" );
137 return false;
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 ) )
142 return false;
144 // commit the root storage so the contents must be stored now
145 if ( !m_aTestHelper.commitStorage( xStep2TempStorage ) )
146 return false;
148 // dispose used storage to free resources
149 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
150 return false;
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 );
161 ZipEntry aEntry;
162 int nNumber = 0;
163 m_aTestHelper.Message( "Available entries:" );
164 while ( ( aEntry = aZipStream.getNextEntry() ) != null )
166 nNumber++;
167 m_aTestHelper.Message( aEntry.getName() );
170 if ( nNumber != 6 )
172 m_aTestHelper.Error( "Wrong number of entries: " + nNumber + ", Expected: 6" );
173 return false;
176 return true;
178 catch( Exception e )
180 m_aTestHelper.Error( "Exception: " + e );
181 return false;