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 import com.sun.star.io.XInputStream; 33 34 import com.sun.star.embed.*; 35 36 import share.LogWriter; 37 import complex.storages.TestHelper; 38 import complex.storages.StorageTest; 39 40 public class RegressionTest_i84234 implements StorageTest { 41 42 XMultiServiceFactory m_xMSF; 43 XSingleServiceFactory m_xStorageFactory; 44 TestHelper m_aTestHelper; 45 RegressionTest_i84234( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )46 public RegressionTest_i84234( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 47 { 48 m_xMSF = xMSF; 49 m_xStorageFactory = xStorageFactory; 50 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i84234: " ); 51 } 52 test()53 public boolean test() 54 { 55 try 56 { 57 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 58 if ( xTempFileStream == null ) 59 return false; 60 61 // create storage based on the temporary stream 62 Object pArgs[] = new Object[2]; 63 pArgs[0] = (Object) xTempFileStream; 64 pArgs[1] = new Integer( ElementModes.WRITE ); 65 66 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 67 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 68 if ( xTempStorage == null ) 69 { 70 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 71 return false; 72 } 73 74 // open a new substorage 75 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 76 "SubStorage1", 77 ElementModes.WRITE ); 78 if ( xTempSubStorage == null ) 79 { 80 m_aTestHelper.Error( "Can't create substorage!" ); 81 return false; 82 } 83 84 byte pBytes1[] = { 1, 1, 1, 1, 1 }; 85 86 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 87 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) ) 88 return false; 89 90 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 91 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) ) 92 return false; 93 94 95 // ================================================ 96 // commit the storages and dispose them 97 // ================================================ 98 99 // commit substorage 100 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 101 return false; 102 103 // dispose substorage 104 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 105 return false; 106 107 // commit storage 108 if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 109 return false; 110 111 // dispose storage 112 if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 113 return false; 114 115 // ================================================ 116 // reopen the storages in readwrite mode and check Compressed flag 117 // ================================================ 118 119 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 120 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 121 if ( xTempStorage == null ) 122 { 123 m_aTestHelper.Error( "Can't create temporary storage representation!" ); 124 return false; 125 } 126 127 // open a new substorage 128 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 129 "SubStorage1", 130 ElementModes.WRITE ); 131 if ( xTempSubStorage == null ) 132 { 133 m_aTestHelper.Error( "Can't create substorage!" ); 134 return false; 135 } 136 137 if ( !m_aTestHelper.checkStream( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) ) 138 return false; 139 140 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) ) 141 return false; 142 143 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock 144 // any resource, later the garbage collector will release the object and it must die by refcount 145 146 return true; 147 } 148 catch( Exception e ) 149 { 150 m_aTestHelper.Error( "Exception: " + e ); 151 return false; 152 } 153 } 154 } 155 156