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 .
20 import com
.sun
.star
.lang
.XMultiServiceFactory
;
21 import com
.sun
.star
.lang
.XSingleServiceFactory
;
23 import com
.sun
.star
.uno
.UnoRuntime
;
24 import com
.sun
.star
.io
.XStream
;
25 import com
.sun
.star
.io
.XInputStream
;
27 import com
.sun
.star
.embed
.*;
29 public class Test02
implements StorageTest
{
31 XMultiServiceFactory m_xMSF
;
32 XSingleServiceFactory m_xStorageFactory
;
33 TestHelper m_aTestHelper
;
35 public Test02( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
38 m_xStorageFactory
= xStorageFactory
;
39 m_aTestHelper
= new TestHelper( "Test02: " );
46 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
47 if ( xTempFileStream
== null )
50 // create storage based on the temporary stream
51 Object pArgs
[] = new Object
[2];
52 pArgs
[0] = xTempFileStream
;
53 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
55 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
56 XStorage xTempStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
57 if ( xTempStorage
== null )
59 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
63 // open a new substorage
64 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
67 if ( xTempSubStorage
== null )
69 m_aTestHelper
.Error( "Can't create substorage!" );
73 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
79 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
80 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
83 ElementModes
.WRITE
) )
86 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
87 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
90 ElementModes
.WRITE
) )
93 // commit substorage first
94 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
97 // commit the root storage so the contents must be stored now
98 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
101 // dispose used storage to free resources
102 // the substorage dispose will be triggered by this call
103 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
108 // now check all the written information
111 // close the output part of the temporary stream
112 // the output part must present since we already wrote to the stream
113 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
116 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
117 if ( xTempInStream
== null )
122 // since no mode is provided the result storage must be opened readonly
123 Object pOneArg
[] = new Object
[1];
124 pOneArg
[0] = xTempInStream
;
126 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
127 XStorage xResultStorage
= UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
128 if ( xResultStorage
== null )
130 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
134 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType2", true, ElementModes
.READ
) )
137 // open existing substorage
138 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
141 if ( xResultSubStorage
== null )
143 m_aTestHelper
.Error( "Can't open existing substorage!" );
147 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType3", false, ElementModes
.READ
) )
150 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", pBytes1
) )
157 m_aTestHelper
.Error( "Exception: " + e
);