1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.lang
.XSingleServiceFactory
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import com
.sun
.star
.io
.XStream
;
26 import com
.sun
.star
.io
.XInputStream
;
28 import com
.sun
.star
.embed
.*;
30 public class Test02
implements StorageTest
{
32 XMultiServiceFactory m_xMSF
;
33 XSingleServiceFactory m_xStorageFactory
;
34 TestHelper m_aTestHelper
;
36 public Test02( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
39 m_xStorageFactory
= xStorageFactory
;
40 m_aTestHelper
= new TestHelper( "Test02: " );
47 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
48 if ( xTempFileStream
== null )
51 // create storage based on the temporary stream
52 Object pArgs
[] = new Object
[2];
53 pArgs
[0] = xTempFileStream
;
54 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
56 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
57 XStorage xTempStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
58 if ( xTempStorage
== null )
60 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
64 // open a new substorage
65 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
68 if ( xTempSubStorage
== null )
70 m_aTestHelper
.Error( "Can't create substorage!" );
74 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
76 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
77 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
80 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
81 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
84 ElementModes
.WRITE
) )
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
91 ElementModes
.WRITE
) )
94 // commit substorage first
95 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
98 // commit the root storage so the contents must be stored now
99 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
102 // dispose used storage to free resources
103 // the substorage dispose will be triggered by this call
104 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
109 // now check all the written information
112 // close the output part of the temporary stream
113 // the output part must present since we already wrote to the stream
114 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
117 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
118 if ( xTempInStream
== null )
123 // since no mode is provided the result storage must be opened readonly
124 Object pOneArg
[] = new Object
[1];
125 pOneArg
[0] = xTempInStream
;
127 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
128 XStorage xResultStorage
= UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
129 if ( xResultStorage
== null )
131 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
135 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType2", true, ElementModes
.READ
) )
138 // open existing substorage
139 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
142 if ( xResultSubStorage
== null )
144 m_aTestHelper
.Error( "Can't open existing substorage!" );
148 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType3", false, ElementModes
.READ
) )
151 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, "SubStream1", "MediaType1", pBytes1
) )
158 m_aTestHelper
.Error( "Exception: " + e
);
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */