1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package complex.storages; 23 24 import com.sun.star.uno.XInterface; 25 import com.sun.star.lang.XMultiServiceFactory; 26 import com.sun.star.lang.XSingleServiceFactory; 27 28 import com.sun.star.bridge.XUnoUrlResolver; 29 import com.sun.star.uno.UnoRuntime; 30 import com.sun.star.uno.XInterface; 31 import com.sun.star.io.XStream; 32 33 import com.sun.star.embed.*; 34 35 import share.LogWriter; 36 import complex.storages.TestHelper; 37 import complex.storages.StorageTest; 38 39 public class RegressionTest_i55821 implements StorageTest { 40 41 XMultiServiceFactory m_xMSF; 42 XSingleServiceFactory m_xStorageFactory; 43 TestHelper m_aTestHelper; 44 RegressionTest_i55821( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )45 public RegressionTest_i55821( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 46 { 47 m_xMSF = xMSF; 48 m_xStorageFactory = xStorageFactory; 49 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i55821: " ); 50 } 51 test()52 public boolean test() 53 { 54 try 55 { 56 // ================================================ 57 // create a temporary stream and a storage based on it 58 // fill the storage with the data that will be used for testing 59 // ================================================ 60 61 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 62 if ( xTempFileStream == null ) 63 return false; 64 65 // create storage based on the temporary stream 66 Object pArgs[] = new Object[2]; 67 pArgs[0] = (Object) xTempFileStream; 68 pArgs[1] = new Integer( ElementModes.WRITE ); 69 70 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 71 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 72 if ( xTempStorage == null ) 73 { 74 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 75 return false; 76 } 77 78 String sPass = "12345"; 79 byte pBytes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; 80 81 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 82 // the stream will not be encrypted 83 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", false, pBytes, sPass ) ) 84 return false; 85 86 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 87 return false; 88 89 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) ) 90 return false; 91 92 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 93 return false; 94 95 // dispose used storages to free resources 96 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 97 return false; 98 99 // ================================================ 100 // reopen the target storage readonly, and check contents 101 // ================================================ 102 103 // the temporary file must not be locked any more after storage disposing 104 pArgs[1] = new Integer( ElementModes.READ ); 105 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 106 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); 107 if ( xResultStorage == null ) 108 { 109 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); 110 return false; 111 } 112 113 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes, sPass ) ) 114 return false; 115 116 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes, sPass ) ) 117 return false; 118 119 // dispose used storages to free resources 120 if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) 121 return false; 122 123 return true; 124 } 125 catch( Exception e ) 126 { 127 m_aTestHelper.Error( "Exception: " + e ); 128 return false; 129 } 130 } 131 } 132 133