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 .
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
.embed
.*;
26 public class Test07
implements StorageTest
{
28 XMultiServiceFactory m_xMSF
;
29 XSingleServiceFactory m_xStorageFactory
;
30 TestHelper m_aTestHelper
;
32 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
35 m_xStorageFactory
= xStorageFactory
;
36 m_aTestHelper
= new TestHelper( "Test07: " );
43 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
44 if ( sTempFileURL
== null || sTempFileURL
.equals("") )
46 m_aTestHelper
.Error( "No valid temporary file was created!" );
50 // create temporary storage based on arbitrary medium
51 // after such a storage is closed it is lost
52 Object oTempStorage
= m_xStorageFactory
.createInstance();
53 XStorage xTempStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
54 if ( xTempStorage
== null )
56 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
60 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
61 byte pPass1
[] = { 1, 2, 3, 4, 5 };
63 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
64 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
, pPass1
) )
67 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
68 byte pPass2
[] = { 5, 4, 3, 2, 1 };
70 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
71 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes2
, pPass2
) )
74 // create temporary storage based on a previously created temporary file
75 Object pArgs
[] = new Object
[2];
76 pArgs
[0] = sTempFileURL
;
77 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
79 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
80 XStorage xTempFileStorage
= UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
81 if ( xTempFileStorage
== null )
83 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
87 // copy xTempStorage to xTempFileStorage
88 // xTempFileStorage will be automatically committed
89 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
92 // dispose used storages to free resources
93 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
97 // now check all the written and copied information
100 // the temporary file must not be locked any more after storage disposing
101 pArgs
[1] = Integer
.valueOf( ElementModes
.READWRITE
);
102 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
103 XStorage xResultStorage
= UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
104 if ( xResultStorage
== null )
106 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
110 Object o2CopyStorage
= m_xStorageFactory
.createInstance();
111 XStorage x2CopyStorage
= UnoRuntime
.queryInterface( XStorage
.class, o2CopyStorage
);
112 if ( x2CopyStorage
== null )
114 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
118 if ( !m_aTestHelper
.copyStorage( xResultStorage
, x2CopyStorage
) )
121 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes1
, pPass1
) )
124 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes2
, pPass2
) )
127 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream1", "MediaType1", pBytes1
, pPass1
) )
130 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream2", "MediaType2", pBytes2
, pPass2
) )
133 // dispose used storages to free resources
134 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
141 m_aTestHelper
.Error( "Exception: " + e
);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */