crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / package / qa / ofopxmlstorages / Test08.java
bloba2607141f940d01437c9b51b5a93c1da386d6b96
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;
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.*;
32 import com.sun.star.beans.StringPair;
34 import share.LogWriter;
35 import complex.ofopxmlstorages.TestHelper;
36 import complex.ofopxmlstorages.StorageTest;
38 public class Test08 implements StorageTest {
40 XMultiServiceFactory m_xMSF;
41 XSingleServiceFactory m_xStorageFactory;
42 TestHelper m_aTestHelper;
44 public Test08( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
46 m_xMSF = xMSF;
47 m_xStorageFactory = xStorageFactory;
48 m_aTestHelper = new TestHelper( aLogWriter, "Test08: " );
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 try
65 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
66 if ( xTempFileStream == null )
67 return false;
69 // create storage based on the temporary stream
70 XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
71 xTempFileStream,
72 ElementModes.WRITE );
73 if ( xTempStorage == null )
75 m_aTestHelper.Error( "Can't create temporary storage representation!" );
76 return false;
79 // open a new substorage
80 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
81 "SubStorage1",
82 ElementModes.WRITE );
83 if ( xTempSubStorage == null )
85 m_aTestHelper.Error( "Can't create substorage!" );
86 return false;
89 byte pBytes1[] = { 1, 1, 1, 1, 1 };
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
93 "SubStream1",
94 "MediaType1",
95 true,
96 pBytes1,
97 aRelations1 ) )
98 return false;
100 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
101 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
102 true,
103 ElementModes.WRITE,
104 aRelations1 ) )
105 return false;
107 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
108 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
109 false,
110 ElementModes.WRITE,
111 aRelations1 ) )
112 return false;
114 // commit substorage first
115 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
116 return false;
118 // commit the root storage so the contents must be stored now
119 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
120 return false;
122 // dispose substorage
123 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
124 return false;
127 // check substorage
130 if ( !checkSubStorages( xTempStorage, pBytes1, aRelations1 ) )
131 return false;
133 // dispose used storage to free resources
134 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
135 return false;
138 // now check all the written information with readwrite access
141 XStorage xResWriteStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
142 xTempFileStream,
143 ElementModes.WRITE );
144 if ( xResWriteStorage == null )
146 m_aTestHelper.Error( "Can't open storage based on input stream!" );
147 return false;
150 if ( !m_aTestHelper.checkStorageProperties( xResWriteStorage,
151 true,
152 ElementModes.WRITE,
153 aRelations1 ) )
154 return false;
156 if( !checkSubStorages( xResWriteStorage, pBytes1, aRelations1 ) )
157 return false;
159 // try to open for writing after opening for reading
160 XStorage xResWSubStorage = m_aTestHelper.openSubStorage( xResWriteStorage,
161 "SubStorage1",
162 ElementModes.WRITE );
163 if ( xResWSubStorage == null )
165 m_aTestHelper.Error( "Can't open substorage for writing after it was opened for reading!" );
166 return false;
169 if ( !m_aTestHelper.checkStorageProperties( xResWSubStorage,
170 false,
171 ElementModes.WRITE,
172 aRelations1 ) )
173 return false;
175 if ( !m_aTestHelper.checkStream( xResWSubStorage,
176 "SubStream1",
177 "MediaType1",
178 pBytes1,
179 aRelations1 ) )
180 return false;
182 // dispose used storage to free resources
183 if ( !m_aTestHelper.disposeStorage( xResWriteStorage ) )
184 return false;
188 // now check all the written information with readonly access
191 // close the output part of the temporary stream
192 // the output part must present since we already wrote to the stream
193 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
194 return false;
196 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
197 if ( xTempInStream == null )
198 return false;
200 // open input stream
201 // since no mode is provided the result storage must be opened readonly
202 XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory,
203 xTempInStream );
204 if ( xResultStorage == null )
206 m_aTestHelper.Error( "Can't open storage based on input stream!" );
207 return false;
210 if ( !m_aTestHelper.checkStorageProperties( xResultStorage,
211 true,
212 ElementModes.READ,
213 aRelations1 ) )
214 return false;
216 if( !checkSubStorages( xResultStorage, pBytes1, aRelations1 ) )
217 return false;
219 return true;
221 catch( Exception e )
223 m_aTestHelper.Error( "Exception: " + e );
224 return false;
228 private boolean checkSubStorages( XStorage xStorage, byte[] pBytes1, StringPair[][] aRelations )
230 XStorage xReadSubStorage1 = m_aTestHelper.openSubStorage( xStorage,
231 "SubStorage1",
232 ElementModes.READ );
234 XStorage xReadSubStorage2 = m_aTestHelper.openSubStorage( xStorage,
235 "SubStorage1",
236 ElementModes.READ );
238 if ( xReadSubStorage1 == null || xReadSubStorage2 == null )
240 m_aTestHelper.Error( "Can't open substorage for reading!" );
241 return false;
244 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage1,
245 false,
246 ElementModes.READ,
247 aRelations ) )
248 return false;
250 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage2,
251 false,
252 ElementModes.READ,
253 aRelations ) )
254 return false;
256 if ( !m_aTestHelper.checkStream( xReadSubStorage1,
257 "SubStream1",
258 "MediaType1",
259 pBytes1,
260 aRelations ) )
261 return false;
263 if ( !m_aTestHelper.checkStream( xReadSubStorage2,
264 "SubStream1",
265 "MediaType1",
266 pBytes1,
267 aRelations ) )
268 return false;
270 if ( !m_aTestHelper.disposeStorage( xReadSubStorage1 ) )
271 return false;
273 if ( !m_aTestHelper.disposeStorage( xReadSubStorage2 ) )
274 return false;
276 return true;