Bump version to 5.0-14
[LibreOffice.git] / package / qa / ofopxmlstorages / Test07.java
blob54f9a80b2c2fb86408c57cb1b01877ed80c63632
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.lang.XMultiServiceFactory;
22 import com.sun.star.lang.XSingleServiceFactory;
24 import com.sun.star.bridge.XUnoUrlResolver;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
28 import com.sun.star.container.XNameAccess;
29 import com.sun.star.io.XStream;
31 import com.sun.star.embed.*;
32 import com.sun.star.beans.StringPair;
34 import share.LogWriter;
35 import complex.ofopxmlstorages.TestHelper;
36 import complex.ofopxmlstorages.StorageTest;
38 public class Test07 implements StorageTest {
40 XMultiServiceFactory m_xMSF;
41 XSingleServiceFactory m_xStorageFactory;
42 TestHelper m_aTestHelper;
44 public Test07( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
46 m_xMSF = xMSF;
47 m_xStorageFactory = xStorageFactory;
48 m_aTestHelper = new TestHelper( aLogWriter, "Test07: " );
51 public boolean test()
53 StringPair[][] aRelations1 =
54 { { new StringPair( "Id", "Num1" ) },
55 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
56 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
57 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
58 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
59 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
60 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
63 StringPair[][] aRelations2 =
64 { { new StringPair( "Id", "Num1" ) },
65 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
66 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
67 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
68 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
69 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
70 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
73 try
75 // create temporary storage based on arbitrary medium
76 // after such a storage is closed it is lost
77 XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory );
78 if ( xTempStorage == null )
80 m_aTestHelper.Error( "Can't create temporary storage representation!" );
81 return false;
84 byte pBytes1[] = { 1, 1, 1, 1, 1 };
86 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
87 if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage,
88 "SubStream1",
89 "MediaType1",
90 true,
91 pBytes1,
92 aRelations1 ) )
93 return false;
96 // open a new substorage
97 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
98 "SubStorage1",
99 ElementModes.WRITE );
100 if ( xTempSubStorage == null )
102 m_aTestHelper.Error( "Can't create substorage!" );
103 return false;
106 byte pBytes2[] = { 2, 2, 2, 2, 2 };
108 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
109 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
110 "SubStream2",
111 "MediaType2",
112 true,
113 pBytes2,
114 aRelations2 ) )
115 return false;
117 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
118 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
119 true,
120 ElementModes.WRITE,
121 aRelations2 ) )
122 return false;
124 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
125 false,
126 ElementModes.WRITE,
127 aRelations2 ) )
128 return false;
131 // check cloning at current state
134 // the new storage still was not committed so the clone must be empty
135 XStorage xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" );
137 if ( xClonedSubStorage == null )
139 m_aTestHelper.Error( "The result of clone is empty!" );
140 return false;
143 XNameAccess xClonedNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xClonedSubStorage );
144 if ( xClonedNameAccess == null )
146 m_aTestHelper.Error( "XNameAccess is not implemented by the clone!" );
147 return false;
150 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage,
151 true,
152 ElementModes.WRITE,
153 new StringPair[0][0] ) )
154 return false;
156 if ( xClonedNameAccess.hasElements() )
158 m_aTestHelper.Error( "The new substorage still was not committed so it must be empty!" );
159 return false;
162 if ( !m_aTestHelper.disposeStorage( xClonedSubStorage ) )
163 return false;
165 xClonedSubStorage = null;
166 xClonedNameAccess = null;
168 // the new stream was opened, written and closed, that means flashed
169 // so the clone must contain all the information
170 XStream xClonedSubStream = m_aTestHelper.cloneSubStream( xTempStorage, "SubStream1" );
171 if ( !m_aTestHelper.InternalCheckStream( xClonedSubStream,
172 "SubStream1",
173 "MediaType1",
174 pBytes1,
175 aRelations1 ) )
176 return false;
178 if ( !m_aTestHelper.disposeStream( xClonedSubStream, "SubStream1" ) )
179 return false;
182 // commit substorage and check cloning
185 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
186 return false;
188 xClonedSubStorage = m_aTestHelper.cloneSubStorage( m_xMSF, m_xStorageFactory, xTempStorage, "SubStorage1" );
189 if ( xClonedSubStorage == null )
191 m_aTestHelper.Error( "The result of clone is empty!" );
192 return false;
195 if ( !m_aTestHelper.checkStorageProperties( xClonedSubStorage,
196 true,
197 ElementModes.WRITE,
198 aRelations2 ) )
199 return false;
201 if ( !m_aTestHelper.checkStream( xClonedSubStorage,
202 "SubStream2",
203 "MediaType2",
204 pBytes2,
205 aRelations2 ) )
206 return false;
208 XStorage xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage );
209 if ( xCloneOfRoot == null )
211 m_aTestHelper.Error( "The result of root clone is empty!" );
212 return false;
215 XNameAccess xCloneOfRootNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xCloneOfRoot );
216 if ( xCloneOfRootNA == null )
218 m_aTestHelper.Error( "XNameAccess is not implemented by the root clone!" );
219 return false;
222 if ( xCloneOfRootNA.hasElements() )
224 m_aTestHelper.Error( "The root storage still was not committed so it's clone must be empty!" );
225 return false;
228 if ( !m_aTestHelper.disposeStorage( xCloneOfRoot ) )
229 return false;
231 xCloneOfRoot = null;
234 // commit root storage and check cloning
237 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
238 return false;
240 xCloneOfRoot = m_aTestHelper.cloneStorage( m_xMSF, m_xStorageFactory, xTempStorage );
241 if ( xCloneOfRoot == null )
243 m_aTestHelper.Error( "The result of root clone is empty!" );
244 return false;
247 XStorage xSubStorageOfClone = xCloneOfRoot.openStorageElement( "SubStorage1", ElementModes.READ );
248 if ( xSubStorageOfClone == null )
250 m_aTestHelper.Error( "The result of root clone is wrong!" );
251 return false;
254 if ( !m_aTestHelper.checkStorageProperties( xSubStorageOfClone,
255 false,
256 ElementModes.READ,
257 aRelations2 ) )
258 return false;
260 if ( !m_aTestHelper.checkStream( xSubStorageOfClone,
261 "SubStream2",
262 "MediaType2",
263 pBytes2,
264 aRelations2 ) )
265 return false;
267 return true;
269 catch( Exception e )
271 m_aTestHelper.Error( "Exception: " + e );
272 return false;