Bump version to 5.0-14
[LibreOffice.git] / package / qa / ofopxmlstorages / Test02.java
bloba39e78ca472f61a1a7adbedad69b464f0c7b9df0
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 Test02 implements StorageTest {
40 XMultiServiceFactory m_xMSF;
41 XSingleServiceFactory m_xStorageFactory;
42 TestHelper m_aTestHelper;
44 public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
46 m_xMSF = xMSF;
47 m_xStorageFactory = xStorageFactory;
48 m_aTestHelper = new TestHelper( aLogWriter, "Test02: " );
51 public boolean test()
53 try
55 StringPair[][] aRelations =
56 { { new StringPair( "Id", "Num1" ) },
57 { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) },
58 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
59 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
60 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
61 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
62 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
66 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
67 if ( xTempFileStream == null )
68 return false;
70 // create storage based on the temporary stream
71 XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
72 xTempFileStream,
73 ElementModes.WRITE );
74 if ( xTempStorage == null )
76 m_aTestHelper.Error( "Can't create temporary storage representation!" );
77 return false;
80 // open a new substorage
81 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
82 "SubStorage1",
83 ElementModes.WRITE );
84 if ( xTempSubStorage == null )
86 m_aTestHelper.Error( "Can't create substorage!" );
87 return false;
90 byte pBytes1[] = { 1, 1, 1, 1, 1 };
92 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
93 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
94 "SubStream1",
95 "MediaType1",
96 true,
97 pBytes1,
98 aRelations ) )
99 return false;
101 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
103 true,
104 ElementModes.WRITE,
105 aRelations ) )
106 return false;
108 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
109 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
110 false,
111 ElementModes.WRITE,
112 aRelations ) )
113 return false;
115 // commit substorage first
116 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
117 return false;
119 // commit the root storage so the contents must be stored now
120 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
121 return false;
123 // dispose used storage to free resources
124 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
125 return false;
129 // now check all the written information
132 // close the output part of the temporary stream
133 // the output part must present since we already wrote to the stream
134 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
135 return false;
137 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
138 if ( xTempInStream == null )
139 return false;
142 // open input stream
143 XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, xTempInStream );
144 if ( xResultStorage == null )
146 m_aTestHelper.Error( "Can't open storage based on input stream!" );
147 return false;
150 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, true, ElementModes.READ, aRelations ) )
151 return false;
153 // open existing substorage
154 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
155 "SubStorage1",
156 ElementModes.READ );
157 if ( xResultSubStorage == null )
159 m_aTestHelper.Error( "Can't open existing substorage!" );
160 return false;
163 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage,
164 false,
165 ElementModes.READ,
166 aRelations ) )
167 return false;
169 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, aRelations ) )
170 return false;
172 return true;
174 catch( Exception e )
176 m_aTestHelper.Error( "Exception: " + e );
177 return false;