nss: upgrade to release 3.73
[LibreOffice.git] / package / qa / storages / RegressionTest_i35095.java
blob0c979466c33e06320d5626190ffdb034256c05ed
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 com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
25 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
28 import com.sun.star.io.XStream;
29 import com.sun.star.io.XInputStream;
31 import com.sun.star.embed.*;
33 import share.LogWriter;
34 import complex.storages.TestHelper;
35 import complex.storages.StorageTest;
37 public class RegressionTest_i35095 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i35095( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i35095: " );
50 public boolean test()
52 try
54 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
55 if ( xTempFileStream == null )
56 return false;
58 // create storage based on the temporary stream
59 Object pArgs[] = new Object[2];
60 pArgs[0] = (Object) xTempFileStream;
61 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
63 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
64 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
65 if ( xTempStorage == null )
67 m_aTestHelper.Error( "Can't create temporary storage representation!" );
68 return false;
71 byte pBytes[] = new byte[36000];
72 for ( int nInd = 0; nInd < 36000; nInd++ )
73 pBytes[nInd] = (byte)( nInd % 128 );
75 String sPass = "12345";
77 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
78 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes, sPass ) )
79 return false;
81 // open a new substorage
82 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
83 "SubStorage1",
84 ElementModes.WRITE );
85 if ( xTempSubStorage == null )
87 m_aTestHelper.Error( "Can't create substorage!" );
88 return false;
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) )
93 return false;
95 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
96 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
97 "MediaType3",
98 true,
99 ElementModes.WRITE ) )
100 return false;
102 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
103 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
104 "MediaType4",
105 false,
106 ElementModes.WRITE ) )
107 return false;
109 // commit substorage first
110 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
111 return false;
113 // commit the root storage so the contents must be stored now
114 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
115 return false;
117 // dispose used storage to free resources
118 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
119 return false;
122 // now check all the written information
123 // and the raw stream contents
126 // close the output part of the temporary stream
127 // the output part must present since we already wrote to the stream
128 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
129 return false;
131 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
132 if ( xTempInStream == null )
133 return false;
135 // open input stream
136 // since no mode is provided the result storage must be opened readonly
137 Object pOneArg[] = new Object[1];
138 pOneArg[0] = (Object) xTempInStream;
140 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
141 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
142 if ( xResultStorage == null )
144 m_aTestHelper.Error( "Can't open storage based on input stream!" );
145 return false;
148 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
149 return false;
151 // open existing substorage
152 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
153 "SubStorage1",
154 ElementModes.READ );
155 if ( xResultSubStorage == null )
157 m_aTestHelper.Error( "Can't open existing substorage!" );
158 return false;
161 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
162 return false;
164 if ( !m_aTestHelper.compareRawMethodsOnEncrStream( xResultStorage, "SubStream1" ) )
165 return false;
167 if ( !m_aTestHelper.compareRawMethodsOnEncrStream( xResultSubStorage, "SubStream2" ) )
168 return false;
170 // dispose used storages to free resources
171 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
172 return false;
174 return true;
176 catch( Exception e )
178 m_aTestHelper.Error( "Exception: " + e );
179 return false;