bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_125919.java
blob3ad8b0e6ce4004d7ce2447cbc8c9312b8ce7b42e
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.lang.Integer;
23 import com.sun.star.uno.XInterface;
24 import com.sun.star.lang.XMultiServiceFactory;
25 import com.sun.star.lang.XSingleServiceFactory;
27 import com.sun.star.bridge.XUnoUrlResolver;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
30 import com.sun.star.io.XStream;
31 import com.sun.star.io.XInputStream;
33 import com.sun.star.embed.*;
35 import share.LogWriter;
36 import complex.storages.TestHelper;
37 import complex.storages.StorageTest;
38 import complex.storages.BorderedStream;
40 public class RegressionTest_125919 implements StorageTest {
42 XMultiServiceFactory m_xMSF;
43 XSingleServiceFactory m_xStorageFactory;
44 TestHelper m_aTestHelper;
46 int nMinTestLen = 0;
47 int nMaxTestLen = 60000;
49 public RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
51 m_xMSF = xMSF;
52 m_xStorageFactory = xStorageFactory;
53 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_125919: " );
56 public boolean test()
58 try
60 byte[] pBytes0 = new byte[0];
61 byte[] pBytes18 = new byte[18000];
62 byte[] pBytes36 = new byte[36000];
64 for ( int nInitInd = 0; nInitInd < 36000; nInitInd++ )
66 pBytes36[nInitInd] = ( Integer.valueOf( nInitInd >> ( ( nInitInd % 2 ) * 8 ) ) ).byteValue();
67 if ( nInitInd < 18000 )
68 pBytes18[nInitInd] = ( Integer.valueOf( 256 - pBytes36[nInitInd] ) ).byteValue();
71 System.out.println( "This test can take up to some hours. The file size currently is about 50000." );
72 System.out.println( "Progress: " );
73 for ( int nAvailableBytes = nMinTestLen; nAvailableBytes < nMaxTestLen; nAvailableBytes++ )
75 Object oBStream = new BorderedStream( nAvailableBytes );
76 XStream xBorderedStream = (XStream)UnoRuntime.queryInterface( XStream.class, oBStream );
77 if ( xBorderedStream == null )
79 m_aTestHelper.Error( "Can't create bordered stream!" );
80 return false;
83 // create storage based on the temporary stream
84 Object pArgs[] = new Object[2];
85 pArgs[0] = (Object) xBorderedStream;
86 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
88 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
89 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
90 if ( xTempStorage == null )
92 m_aTestHelper.Error( "Can't create temporary storage representation!" );
93 return false;
96 XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xTempStorage );
97 if ( xTransact == null )
99 m_aTestHelper.Error( "This test is designed for storages in transacted mode!" );
100 return false;
104 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 0, "MediaType1", true, pBytes0 ) )
105 return false;
106 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 18, "MediaType2", true, pBytes18 ) )
107 return false;
108 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 36, "MediaType3", true, pBytes36 ) )
109 return false;
111 if ( nAvailableBytes > 0 && nAvailableBytes % 100 == 0 )
112 System.out.println( " " + nAvailableBytes );
114 if ( nAvailableBytes > 0 && nAvailableBytes % 2 == 1 )
115 System.out.print( "#" );
119 xTransact.commit();
121 System.out.println( "" );
122 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
123 return false;
125 // SUCCESS
126 return true;
128 catch( UseBackupException aExc )
130 // when there is not enough place in the target location and the target file is empty
131 // the direct writing will fail and must throw this exception with empty URL
132 if ( aExc.TemporaryFileURL.length() != 0 )
133 return false;
135 catch( Exception e )
137 System.out.println( "" );
138 m_aTestHelper.Error( "Unexpected exception: " + e + "\nnAvailableBytes = " + nAvailableBytes );
139 return false;
143 return false;
145 catch( Exception e )
147 m_aTestHelper.Error( "Exception: " + e );
148 return false;