bump product version to 4.1.6.2
[LibreOffice.git] / package / qa / storages / RegressionTest_i29321.java
blobc871ef33200a054dfde9ae4974d5aee5084c7bce
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_i29321 implements StorageTest {
39 XMultiServiceFactory m_xMSF;
40 XSingleServiceFactory m_xStorageFactory;
41 TestHelper m_aTestHelper;
43 public RegressionTest_i29321( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i29321: " );
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] = new Integer( 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 // open a new substorage
82 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
83 "SubSubStorage1",
84 ElementModes.WRITE );
85 if ( xTempSubSubStorage == null )
87 m_aTestHelper.Error( "Can't create substorage!" );
88 return false;
91 byte pBytes1[] = { 1, 1, 1, 1, 1 };
93 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
94 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "Stream1", "MediaType1", true, pBytes1 ) )
95 return false;
97 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
98 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType2", true, pBytes1 ) )
99 return false;
101 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
102 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType3", true, pBytes1 ) )
103 return false;
105 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
106 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
107 "MediaType4",
108 true,
109 ElementModes.WRITE ) )
110 return false;
112 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
113 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
114 "MediaType5",
115 false,
116 ElementModes.WRITE ) )
117 return false;
119 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
120 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
121 "MediaType6",
122 false,
123 ElementModes.WRITE ) )
124 return false;
126 // ================================================
127 // commit the storages twice to test the bug scenario
128 // ================================================
130 // commit lowlevel substorage first
131 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
132 return false;
134 // commit substorage
135 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
136 return false;
138 // commit substorage to let the renaming take place
139 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
140 return false;
142 // commit lowlevel substorage first
143 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
144 return false;
146 // commit substorage
147 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
148 return false;
150 // commit substorage to let the renaming take place
151 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
152 return false;
154 // ================================================
155 // check the storages and streams without closing
156 // ================================================
158 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType6", false, ElementModes.WRITE ) )
159 return false;
161 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType5", false, ElementModes.WRITE ) )
162 return false;
164 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType4", true, ElementModes.WRITE ) )
165 return false;
167 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType3", true, pBytes1 ) )
168 return false;
170 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType2", true, pBytes1 ) )
171 return false;
173 if ( !m_aTestHelper.checkStream( xTempStorage, "Stream1", "MediaType1", true, pBytes1 ) )
174 return false;
176 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
177 // any resource, later the garbage collector will release the object and it must die by refcount
179 return true;
181 catch( Exception e )
183 m_aTestHelper.Error( "Exception: " + e );
184 return false;