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
)
44 m_xStorageFactory
= xStorageFactory
;
45 m_aTestHelper
= new TestHelper( aLogWriter
, "Test18: " );
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!" );
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!" );
70 // open a new substorage
71 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
74 if ( xTempSubStorage
== null )
76 m_aTestHelper
.Error( "Can't create substorage!" );
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
) )
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
) )
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
) )
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
) )
98 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
99 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
102 ElementModes
.WRITE
) )
105 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
106 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
109 ElementModes
.WRITE
) )
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!" );
125 // copy xTempStorage to xTempFileStorage
126 // xTempFileStorage will be automatically committed
127 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
130 // dispose used storages to free resources
131 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
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!" );
148 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.WRITE
) )
151 // open existing substorage
152 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
155 if ( xResultSubStorage
== null )
157 m_aTestHelper
.Error( "Can't open existing substorage!" );
161 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.READ
) )
164 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "image/jpeg", false, pBytes1
) )
167 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream2", "image/png", false, pBytes1
) )
170 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream3", "image/gif", false, pBytes1
) )
173 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream4", "MediaType1", true, pBytes1
) )
176 // dispose used storages to free resources
177 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
184 m_aTestHelper
.Error( "Exception: " + e
);