1*a740f2aaSAndrew Rist /************************************************************** 2*a740f2aaSAndrew Rist * 3*a740f2aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a740f2aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a740f2aaSAndrew Rist * distributed with this work for additional information 6*a740f2aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a740f2aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a740f2aaSAndrew Rist * "License"); you may not use this file except in compliance 9*a740f2aaSAndrew Rist * with the License. You may obtain a copy of the License at 10*a740f2aaSAndrew Rist * 11*a740f2aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a740f2aaSAndrew Rist * 13*a740f2aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a740f2aaSAndrew Rist * software distributed under the License is distributed on an 15*a740f2aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a740f2aaSAndrew Rist * KIND, either express or implied. See the License for the 17*a740f2aaSAndrew Rist * specific language governing permissions and limitations 18*a740f2aaSAndrew Rist * under the License. 19*a740f2aaSAndrew Rist * 20*a740f2aaSAndrew Rist *************************************************************/ 21*a740f2aaSAndrew Rist 22cdf0e10cSrcweir package complex.storages; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import java.lang.Integer; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.XInterface; 27cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 28cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 32cdf0e10cSrcweir import com.sun.star.uno.XInterface; 33cdf0e10cSrcweir import com.sun.star.io.XStream; 34cdf0e10cSrcweir import com.sun.star.io.XInputStream; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import com.sun.star.embed.*; 37cdf0e10cSrcweir 38cdf0e10cSrcweir import share.LogWriter; 39cdf0e10cSrcweir import complex.storages.TestHelper; 40cdf0e10cSrcweir import complex.storages.StorageTest; 41cdf0e10cSrcweir import complex.storages.BorderedStream; 42cdf0e10cSrcweir 43cdf0e10cSrcweir public class RegressionTest_125919 implements StorageTest { 44cdf0e10cSrcweir 45cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 46cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 47cdf0e10cSrcweir TestHelper m_aTestHelper; 48cdf0e10cSrcweir 49cdf0e10cSrcweir int nMinTestLen = 0; 50cdf0e10cSrcweir int nMaxTestLen = 60000; 51cdf0e10cSrcweir RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )52cdf0e10cSrcweir public RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir m_xMSF = xMSF; 55cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 56cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_125919: " ); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir test()59cdf0e10cSrcweir public boolean test() 60cdf0e10cSrcweir { 61cdf0e10cSrcweir try 62cdf0e10cSrcweir { 63cdf0e10cSrcweir byte[] pBytes0 = new byte[0]; 64cdf0e10cSrcweir byte[] pBytes18 = new byte[18000]; 65cdf0e10cSrcweir byte[] pBytes36 = new byte[36000]; 66cdf0e10cSrcweir 67cdf0e10cSrcweir for ( int nInitInd = 0; nInitInd < 36000; nInitInd++ ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir pBytes36[nInitInd] = ( new Integer( nInitInd >> ( ( nInitInd % 2 ) * 8 ) ) ).byteValue(); 70cdf0e10cSrcweir if ( nInitInd < 18000 ) 71cdf0e10cSrcweir pBytes18[nInitInd] = ( new Integer( 256 - pBytes36[nInitInd] ) ).byteValue(); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir System.out.println( "This test can take up to some hours. The file size currently is about 50000." ); 75cdf0e10cSrcweir System.out.println( "Progress: " ); 76cdf0e10cSrcweir for ( int nAvailableBytes = nMinTestLen; nAvailableBytes < nMaxTestLen; nAvailableBytes++ ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir Object oBStream = new BorderedStream( nAvailableBytes ); 79cdf0e10cSrcweir XStream xBorderedStream = (XStream)UnoRuntime.queryInterface( XStream.class, oBStream ); 80cdf0e10cSrcweir if ( xBorderedStream == null ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir m_aTestHelper.Error( "Can't create bordered stream!" ); 83cdf0e10cSrcweir return false; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir // create storage based on the temporary stream 87cdf0e10cSrcweir Object pArgs[] = new Object[2]; 88cdf0e10cSrcweir pArgs[0] = (Object) xBorderedStream; 89cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.WRITE ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 92cdf0e10cSrcweir XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 93cdf0e10cSrcweir if ( xTempStorage == null ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 96cdf0e10cSrcweir return false; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xTempStorage ); 100cdf0e10cSrcweir if ( xTransact == null ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir m_aTestHelper.Error( "This test is designed for storages in transacted mode!" ); 103cdf0e10cSrcweir return false; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 0, "MediaType1", true, pBytes0 ) ) 108cdf0e10cSrcweir return false; 109cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 18, "MediaType2", true, pBytes18 ) ) 110cdf0e10cSrcweir return false; 111cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 36, "MediaType3", true, pBytes36 ) ) 112cdf0e10cSrcweir return false; 113cdf0e10cSrcweir 114cdf0e10cSrcweir if ( nAvailableBytes > 0 && nAvailableBytes % 100 == 0 ) 115cdf0e10cSrcweir System.out.println( " " + nAvailableBytes ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if ( nAvailableBytes > 0 && nAvailableBytes % 2 == 1 ) 118cdf0e10cSrcweir System.out.print( "#" ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir try 121cdf0e10cSrcweir { 122cdf0e10cSrcweir xTransact.commit(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir System.out.println( "" ); 125cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 126cdf0e10cSrcweir return false; 127cdf0e10cSrcweir 128cdf0e10cSrcweir // SUCCESS 129cdf0e10cSrcweir return true; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir catch( UseBackupException aExc ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // when there is not enough place in the target location and the target file is empty 134cdf0e10cSrcweir // the direct writing will fail and must throw this exception with empty URL 135cdf0e10cSrcweir if ( aExc.TemporaryFileURL.length() != 0 ) 136cdf0e10cSrcweir return false; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir catch( Exception e ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir System.out.println( "" ); 141cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected exception: " + e + "\nnAvailableBytes = " + nAvailableBytes ); 142cdf0e10cSrcweir return false; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir return false; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir catch( Exception e ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 151cdf0e10cSrcweir return false; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156