bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i84234.java
blob7bd8073c64f9b451758994d6f3ba600ea666096e
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_i84234 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i84234( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i84234: " );
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 // open a new substorage
72 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
73 "SubStorage1",
74 ElementModes.WRITE );
75 if ( xTempSubStorage == null )
77 m_aTestHelper.Error( "Can't create substorage!" );
78 return false;
81 byte pBytes1[] = { 1, 1, 1, 1, 1 };
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) )
85 return false;
87 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
88 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) )
89 return false;
93 // commit the storages and dispose them
96 // commit substorage
97 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
98 return false;
100 // dispose substorage
101 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
102 return false;
104 // commit storage
105 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
106 return false;
108 // dispose storage
109 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
110 return false;
113 // reopen the storages in readwrite mode and check Compressed flag
116 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
117 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
118 if ( xTempStorage == null )
120 m_aTestHelper.Error( "Can't create temporary storage representation!" );
121 return false;
124 // open a new substorage
125 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
126 "SubStorage1",
127 ElementModes.WRITE );
128 if ( xTempSubStorage == null )
130 m_aTestHelper.Error( "Can't create substorage!" );
131 return false;
134 if ( !m_aTestHelper.checkStream( xTempStorage, "SubStream1", "text/xml", false, pBytes1 ) )
135 return false;
137 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream2", "text/xml", false, pBytes1 ) )
138 return false;
140 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
141 // any resource, later the garbage collector will release the object and it must die by refcount
143 return true;
145 catch( Exception e )
147 m_aTestHelper.Error( "Exception: " + e );
148 return false;