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 Test07
implements StorageTest
{
37 XMultiServiceFactory m_xMSF
;
38 XSingleServiceFactory m_xStorageFactory
;
39 TestHelper m_aTestHelper
;
41 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
44 m_xStorageFactory
= xStorageFactory
;
45 m_aTestHelper
= new TestHelper( aLogWriter
, "Test07: " );
52 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
53 if ( sTempFileURL
== null || sTempFileURL
== "" )
55 m_aTestHelper
.Error( "No valid temporary file was created!" );
59 // create temporary storage based on arbitrary medium
60 // after such a storage is closed it is lost
61 Object oTempStorage
= m_xStorageFactory
.createInstance();
62 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
63 if ( xTempStorage
== null )
65 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
69 byte pBigBytes
[] = new byte[33000];
70 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
71 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
73 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
74 String sPass1
= "12345";
76 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
77 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
, sPass1
) )
80 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
81 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
, sPass1
) )
84 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
85 String sPass2
= "54321";
87 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
88 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "BigSubStream2", "MediaType2", false, pBigBytes
, sPass2
) )
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes2
, sPass2
) )
95 // create temporary storage based on a previously created temporary file
96 Object pArgs
[] = new Object
[2];
97 pArgs
[0] = (Object
) sTempFileURL
;
98 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
100 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
101 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
102 if ( xTempFileStorage
== null )
104 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
108 // copy xTempStorage to xTempFileStorage
109 // xTempFileStorage will be automatically committed
110 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
113 // dispose used storages to free resources
114 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
118 // now check all the written and copied information
121 // the temporary file must not be locked any more after storage disposing
122 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
123 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
124 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
125 if ( xResultStorage
== null )
127 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
131 Object o2CopyStorage
= m_xStorageFactory
.createInstance();
132 XStorage x2CopyStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, o2CopyStorage
);
133 if ( x2CopyStorage
== null )
135 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
139 if ( !m_aTestHelper
.copyStorage( xResultStorage
, x2CopyStorage
) )
142 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes1
, sPass1
) )
145 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "BigSubStream1", "MediaType1", pBigBytes
, sPass1
) )
148 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
151 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
154 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream1", "MediaType1", pBytes1
, sPass1
) )
157 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "BigSubStream1", "MediaType1", pBigBytes
, sPass1
) )
160 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
163 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
166 // dispose used storages to free resources
167 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
174 m_aTestHelper
.Error( "Exception: " + e
);