tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / package / qa / ofopxmlstorages / Test04.java
blob7bc793a6030a6a51cf8c456cf3e61e470914adcd
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.ofopxmlstorages;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
24 import com.sun.star.lang.DisposedException;
26 import com.sun.star.bridge.XUnoUrlResolver;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
30 import com.sun.star.container.XNameAccess;
32 import com.sun.star.embed.*;
33 import com.sun.star.beans.StringPair;
35 import share.LogWriter;
36 import complex.ofopxmlstorages.TestHelper;
37 import complex.ofopxmlstorages.StorageTest;
39 public class Test04 implements StorageTest {
41 XMultiServiceFactory m_xMSF;
42 XSingleServiceFactory m_xStorageFactory;
43 TestHelper m_aTestHelper;
45 public Test04( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
47 m_xMSF = xMSF;
48 m_xStorageFactory = xStorageFactory;
49 m_aTestHelper = new TestHelper( aLogWriter, "Test04: " );
52 public boolean test()
54 StringPair[][] aRelations1 =
55 { { new StringPair( "Id", "Num1" ) },
56 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
57 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
58 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
59 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
60 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
61 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
64 StringPair[][] aRelations2 =
65 { { new StringPair( "Id", "Num1" ) },
66 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
67 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
68 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
69 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
70 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
71 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
74 try
76 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
77 if ( sTempFileURL == null || sTempFileURL == "" )
79 m_aTestHelper.Error( "No valid temporary file was created!" );
80 return false;
83 // create temporary storage based on arbitrary medium
84 // after such a storage is closed it is lost
85 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
86 if ( xTempStorage == null )
88 m_aTestHelper.Error( "Can't create temporary storage representation!" );
89 return false;
92 // open substorages and create streams there
94 // first substorage of the root storage
95 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
96 "SubStorage1",
97 ElementModes.WRITE );
98 if ( xTempSubStorage1 == null )
100 m_aTestHelper.Error( "Can't create substorage!" );
101 return false;
104 byte pBytes1[] = { 1, 1, 1, 1, 1 };
106 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
107 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1,
108 "SubStream1",
109 "MediaType1",
110 true,
111 pBytes1,
112 aRelations1 ) )
113 return false;
115 // second substorage of the root storage
116 XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
117 "SubStorage2",
118 ElementModes.WRITE );
119 if ( xTempSubStorage2 == null )
121 m_aTestHelper.Error( "Can't create substorage!" );
122 return false;
125 byte pBytes2[] = { 2, 2, 2, 2, 2 };
127 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
128 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage2,
129 "SubStream2",
130 "MediaType2",
131 false,
132 pBytes2,
133 aRelations2 ) )
134 return false;
136 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
137 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
138 true,
139 ElementModes.WRITE,
140 aRelations2 ) )
141 return false;
143 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
144 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1,
145 false,
146 ElementModes.WRITE,
147 aRelations2 ) )
148 return false;
150 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
151 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage2,
152 false,
153 ElementModes.WRITE,
154 aRelations2 ) )
155 return false;
157 // create temporary storage based on a previously created temporary file
158 XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
159 sTempFileURL,
160 ElementModes.WRITE );
161 if ( xTempFileStorage == null )
163 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
164 return false;
167 if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempFileStorage ) )
168 return false;
170 // if storage is not committed before disposing all the changes will be lost
171 if ( !m_aTestHelper.commitStorage( xTempSubStorage2 ) )
172 return false;
174 // a storage must be disposed before moving/removing otherwise the access will be denied
175 if ( !m_aTestHelper.disposeStorage( xTempSubStorage2 ) )
176 return false;
178 if ( !m_aTestHelper.moveElementTo( xTempStorage, "SubStorage2", xTempFileStorage ) )
179 return false;
181 // SubStorage2 must be removed and disposed now
184 xTempSubStorage2.isStreamElement( "SubStream2" );
185 m_aTestHelper.Error( "SubStorage2 must be disposed already!" );
186 return false;
188 catch( com.sun.star.lang.DisposedException de )
191 catch( Exception e )
193 m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e );
194 return false;
197 if ( !m_aTestHelper.copyElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) )
198 return false;
200 if ( !m_aTestHelper.renameElement( xTempFileStorage, "SubStream1", "SubStream1_copy" ) )
201 return false;
203 if ( !m_aTestHelper.moveElementTo( xTempSubStorage1, "SubStream1", xTempFileStorage ) )
204 return false;
206 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
207 return false;
209 // dispose used storages to free resources
210 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
211 return false;
214 // now check all the written and copied information
217 // the temporary file must not be locked any more after storage disposing
218 XStorage xResStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
219 sTempFileURL,
220 ElementModes.WRITE );
222 if ( xResStorage == null )
224 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
225 return false;
228 // open and check SubStorage1
229 XStorage xResSubStorage1 = m_aTestHelper.openSubStorage( xResStorage,
230 "SubStorage1",
231 ElementModes.READ );
232 if ( xResSubStorage1 == null )
234 m_aTestHelper.Error( "Can't open existing substorage!" );
235 return false;
238 if ( !m_aTestHelper.checkStorageProperties( xResSubStorage1,
239 false,
240 ElementModes.READ,
241 aRelations2 ) )
242 return false;
245 // open and check SubStorage2
246 XStorage xResSubStorage2 = m_aTestHelper.openSubStorage( xResStorage,
247 "SubStorage2",
248 ElementModes.READ );
249 if ( xResSubStorage2 == null )
251 m_aTestHelper.Error( "Can't open existing substorage!" );
252 return false;
255 if ( !m_aTestHelper.checkStorageProperties( xResSubStorage2,
256 false,
257 ElementModes.READ,
258 aRelations2 ) )
259 return false;
262 // check all the result streams
264 if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1", "MediaType1", pBytes1, aRelations1 ) )
265 return false;
267 if ( !m_aTestHelper.checkStream( xResStorage, "SubStream1_copy", "MediaType1", pBytes1, aRelations1 ) )
268 return false;
270 if ( !m_aTestHelper.checkStream( xResSubStorage1, "SubStream1", "MediaType1", pBytes1, aRelations1 ) )
271 return false;
273 if ( !m_aTestHelper.checkStream( xResSubStorage2, "SubStream2", "MediaType2", pBytes2, aRelations2 ) )
274 return false;
276 // the storage must be disposed before removing
277 if ( !m_aTestHelper.disposeStorage( xResSubStorage2 ) )
278 return false;
280 // remove element and check that it was removed completely
281 if ( !m_aTestHelper.removeElement( xResStorage, "SubStorage2" ) )
282 return false;
286 XNameAccess xResAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResStorage );
287 if ( xResAccess.hasByName( "SubStorage2" ) )
288 m_aTestHelper.Error( "SubStorage2 must be removed already!" );
290 catch( Exception e )
292 m_aTestHelper.Error( "Can't get access to root storage, exception: " + e );
293 return false;
298 xResSubStorage2.isStreamElement( "SubStream2" );
300 m_aTestHelper.Error( "SubStorage2 must be disposed already!" );
301 return false;
303 catch( com.sun.star.lang.DisposedException de )
306 catch( Exception e )
308 m_aTestHelper.Error( "Wrong exception in case of disposed storage, exception: " + e );
309 return false;
312 // dispose used storages to free resources
313 if ( !m_aTestHelper.disposeStorage( xResStorage ) )
314 return false;
316 return true;
318 catch( Exception e )
320 m_aTestHelper.Error( "Exception: " + e );
321 return false;