tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / package / qa / storages / Test14.java
blob04d4a87874afa83a6ff07c0b1ea6f9c5d3b213bc
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;
29 import com.sun.star.embed.*;
31 import share.LogWriter;
32 import complex.storages.TestHelper;
33 import complex.storages.StorageTest;
35 public class Test14 implements StorageTest {
37 XMultiServiceFactory m_xMSF;
38 XSingleServiceFactory m_xStorageFactory;
39 TestHelper m_aTestHelper;
41 public Test14( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
43 m_xMSF = xMSF;
44 m_xStorageFactory = xStorageFactory;
45 m_aTestHelper = new TestHelper( aLogWriter, "Test14: " );
48 public boolean test()
50 String aStreamPrefix = "";
51 for ( int nInd = 0; nInd < 4; ++nInd, aStreamPrefix += "SubStorage" + nInd )
52 if ( !testForPath( aStreamPrefix ) )
53 return false;
55 return true;
58 public boolean testForPath( String aStreamPrefix )
60 try
62 String aSubStream1Path = aStreamPrefix + "SubStream1";
63 String aSubStream2Path = aStreamPrefix + "SubStream2";
64 String aSubStream3Path = aStreamPrefix + "SubStream3";
66 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
67 if ( sTempFileURL == null || sTempFileURL == "" )
69 m_aTestHelper.Error( "No valid temporary file was created!" );
70 return false;
73 // create temporary storage based on a previously created temporary file
74 Object pArgs[] = new Object[2];
75 pArgs[0] = (Object) sTempFileURL;
76 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
78 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
79 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
80 if ( xTempFileStorage == null )
82 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
83 return false;
86 byte pBytes1[] = { 1, 1, 1, 1, 1 };
87 String sPass1 = "12345";
89 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
90 // and commit
91 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, sPass1, true ) )
92 return false;
94 byte pBytes2[] = { 2, 2, 2, 2, 2 };
95 String sPass2 = "54321";
97 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
98 // and commit
99 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, sPass2, true ) )
100 return false;
102 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
103 // and don't commit
104 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, sPass2, false ) )
105 return false;
107 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
108 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
109 "MediaType3",
110 true,
111 ElementModes.WRITE ) )
112 return false;
114 // commit the root storage so the contents must be stored now
115 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
116 return false;
118 // dispose used storages to free resources
119 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
120 return false;
123 // now reopen the storage,
124 // check all the written and copied information
125 // and change it
128 // the temporary file must not be locked any more after storage disposing
129 oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
130 xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
131 if ( xTempFileStorage == null )
133 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
134 return false;
137 if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) )
138 return false;
140 if ( !m_aTestHelper.checkEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", pBytes1, sPass1 ) )
141 return false;
143 if ( !m_aTestHelper.checkEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", pBytes2, sPass2 ) )
144 return false;
146 if ( !m_aTestHelper.cantOpenEncrStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ, sPass2 ) )
147 return false;
149 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
150 // and commit
151 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, sPass1, true ) )
152 return false;
154 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
155 // and don't commit
156 if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, sPass2, false ) )
157 return false;
159 // commit the root storage so the contents must be stored now
160 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
161 return false;
163 // dispose used storages to free resources
164 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
165 return false;
168 // now reopen the storage,
169 // check all the written information
172 // the temporary file must not be locked any more after storage disposing
173 pArgs[1] = Integer.valueOf( ElementModes.READ );
174 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
175 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
176 if ( xResultStorage == null )
178 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
179 return false;
182 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
183 return false;
185 if ( !m_aTestHelper.checkEncrStreamH( xResultStorage, aSubStream1Path, "MediaType3", pBytes2, sPass1 ) )
186 return false;
188 // the following stream was not committed last time, so the last change must be lost
189 if ( !m_aTestHelper.checkEncrStreamH( xResultStorage, aSubStream2Path, "MediaType2", pBytes2, sPass2 ) )
190 return false;
192 // dispose used storages to free resources
193 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
194 return false;
196 return true;
198 catch( Exception e )
200 m_aTestHelper.Error( "Exception: " + e );
201 return false;