bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / Test18.java
blob3e0f246d1d3a4e5f718f6c0643355b5bd880075d
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 Test18 implements StorageTest {
37 XMultiServiceFactory m_xMSF;
38 XSingleServiceFactory m_xStorageFactory;
39 TestHelper m_aTestHelper;
41 public Test18( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
43 m_xMSF = xMSF;
44 m_xStorageFactory = xStorageFactory;
45 m_aTestHelper = new TestHelper( aLogWriter, "Test18: " );
48 public boolean test()
50 try
52 // test the default value of Compressed property
53 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
54 if ( sTempFileURL == null || sTempFileURL == "" )
56 m_aTestHelper.Error( "No valid temporary file was created!" );
57 return false;
60 // create temporary storage based on arbitrary medium
61 // after such a storage is closed it is lost
62 Object oTempStorage = m_xStorageFactory.createInstance();
63 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
64 if ( xTempStorage == null )
66 m_aTestHelper.Error( "Can't create temporary storage representation!" );
67 return false;
70 // open a new substorage
71 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
72 "SubStorage1",
73 ElementModes.WRITE );
74 if ( xTempSubStorage == null )
76 m_aTestHelper.Error( "Can't create substorage!" );
77 return false;
80 byte pBytes1[] = { 1, 1, 1, 1, 1 };
82 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
83 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream1", "image/jpeg", pBytes1 ) )
84 return false;
86 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
87 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream2", "image/png", pBytes1 ) )
88 return false;
90 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
91 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream3", "image/gif", pBytes1 ) )
92 return false;
94 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
95 if ( !m_aTestHelper.WriteBytesToSubstreamDefaultCompressed( xTempSubStorage, "SubStream4", "MediaType1", pBytes1 ) )
96 return false;
98 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
99 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
100 "MediaType3",
101 true,
102 ElementModes.WRITE ) )
103 return false;
105 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
106 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
107 "MediaType4",
108 false,
109 ElementModes.WRITE ) )
110 return false;
112 // create temporary storage based on a previously created temporary file
113 Object pArgs[] = new Object[2];
114 pArgs[0] = (Object) sTempFileURL;
115 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
117 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
118 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
119 if ( xTempFileStorage == null )
121 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
122 return false;
125 // copy xTempStorage to xTempFileStorage
126 // xTempFileStorage will be automatically committed
127 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
128 return false;
130 // dispose used storages to free resources
131 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
132 return false;
135 // now check all the written and copied information
138 // the temporary file must not be locked any more after storage disposing
139 pArgs[1] = Integer.valueOf( ElementModes.WRITE );
140 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
141 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
142 if ( xResultStorage == null )
144 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
145 return false;
148 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) )
149 return false;
151 // open existing substorage
152 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
153 "SubStorage1",
154 ElementModes.READ );
155 if ( xResultSubStorage == null )
157 m_aTestHelper.Error( "Can't open existing substorage!" );
158 return false;
161 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) )
162 return false;
164 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "image/jpeg", false, pBytes1 ) )
165 return false;
167 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream2", "image/png", false, pBytes1 ) )
168 return false;
170 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream3", "image/gif", false, pBytes1 ) )
171 return false;
173 if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream4", "MediaType1", true, pBytes1 ) )
174 return false;
176 // dispose used storages to free resources
177 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
178 return false;
180 return true;
182 catch( Exception e )
184 m_aTestHelper.Error( "Exception: " + e );
185 return false;