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
;
28 import com
.sun
.star
.io
.XStream
;
29 import com
.sun
.star
.io
.XInputStream
;
31 import com
.sun
.star
.embed
.*;
33 import share
.LogWriter
;
34 import complex
.storages
.TestHelper
;
35 import complex
.storages
.StorageTest
;
37 public class Test17
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public Test17( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "Test17: " );
54 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
55 if ( xTempFileStream
== null )
58 // create storage based on the temporary stream
59 Object pArgs
[] = new Object
[2];
60 pArgs
[0] = (Object
) xTempFileStream
;
61 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
63 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
64 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
65 if ( xTempStorage
== null )
67 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
72 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
73 String pNames
[] = { "SubStream1", "SubStream2", "SubStream3", "SubStream4", "SubStream5", "SubStream6", "SubStream7" };
75 for ( int nInd
= 0; nInd
< pNames
.length
; nInd
++ )
77 // open a new substorage
78 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
81 if ( xTempSubStorage
== null )
83 m_aTestHelper
.Error( "Can't create substorage!" );
87 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
88 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, pNames
[nInd
], "MediaType1", true, pBytes1
) )
91 // commit substorage first
92 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
95 // dispose used storage to free resources
96 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
100 // commit the root storage so the contents must be stored now
101 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
104 // dispose used storage to free resources
105 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
110 // now check all the written information
113 // close the output part of the temporary stream
114 // the output part must present since we already wrote to the stream
115 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
118 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
119 if ( xTempInStream
== null )
124 // since no mode is provided the result storage must be opened readonly
125 Object pOneArg
[] = new Object
[1];
126 pOneArg
[0] = (Object
) xTempInStream
;
128 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
129 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
130 if ( xResultStorage
== null )
132 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
136 // open existing substorage
137 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
140 if ( xResultSubStorage
== null )
142 m_aTestHelper
.Error( "Can't open existing substorage!" );
146 for ( int nInd
= 0; nInd
< pNames
.length
; nInd
++ )
147 if ( !m_aTestHelper
.checkStream( xResultSubStorage
, pNames
[nInd
], "MediaType1", true, pBytes1
) )
154 m_aTestHelper
.Error( "Exception: " + e
);