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
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.lang
.XSingleServiceFactory
;
24 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.XInterface
;
28 import com
.sun
.star
.container
.XNameAccess
;
29 import com
.sun
.star
.io
.XStream
;
31 import com
.sun
.star
.embed
.*;
33 import share
.LogWriter
;
34 import complex
.storages
.TestHelper
;
35 import complex
.storages
.StorageTest
;
37 public class Test10
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public Test10( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "Test10: " );
54 // create temporary storage based on arbitrary medium
55 // after such a storage is closed it is lost
56 Object oTempStorage
= m_xStorageFactory
.createInstance();
57 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
58 if ( xTempStorage
== null )
60 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
64 byte pBigBytes
[] = new byte[33000];
65 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
66 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
68 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
70 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
71 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
74 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
75 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
) )
79 // open a new substorage
80 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
83 if ( xTempSubStorage
== null )
85 m_aTestHelper
.Error( "Can't create substorage!" );
89 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
91 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
92 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "MediaType2", true, pBytes2
) )
95 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
96 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
99 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
100 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
103 ElementModes
.WRITE
) )
106 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
109 ElementModes
.WRITE
) )
112 // ==============================
113 // check cloning at current state
114 // ==============================
116 // the new storage still was not commited so the clone must be empty
117 XStorage xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
119 if ( xClonedSubStorage
== null )
121 m_aTestHelper
.Error( "The result of clone is empty!" );
125 XNameAccess xClonedNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xClonedSubStorage
);
126 if ( xClonedNameAccess
== null )
128 m_aTestHelper
.Error( "XNameAccess is not implemented by the clone!" );
132 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "", true, ElementModes
.WRITE
) )
135 if ( xClonedNameAccess
.hasElements() )
137 m_aTestHelper
.Error( "The new substorage still was not commited so it must be empty!" );
141 if ( !m_aTestHelper
.disposeStorage( xClonedSubStorage
) )
144 xClonedSubStorage
= null;
145 xClonedNameAccess
= null;
147 // the new stream was opened, written and closed, that means flashed
148 // so the clone must contain all the information
149 XStream xClonedSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "SubStream1" );
150 if ( !m_aTestHelper
.InternalCheckStream( xClonedSubStream
, "SubStream1", "MediaType1", true, pBytes1
, true ) )
153 XStream xClonedBigSubStream
= m_aTestHelper
.cloneSubStream( xTempStorage
, "BigSubStream1" );
154 if ( !m_aTestHelper
.InternalCheckStream( xClonedBigSubStream
, "BigSubStream1", "MediaType1", true, pBigBytes
, true ) )
157 if ( !m_aTestHelper
.disposeStream( xClonedSubStream
, "SubStream1" ) )
160 if ( !m_aTestHelper
.disposeStream( xClonedBigSubStream
, "BigSubStream1" ) )
163 // ==============================
164 // commit substorage and check cloning
165 // ==============================
167 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
170 xClonedSubStorage
= m_aTestHelper
.cloneSubStorage( m_xStorageFactory
, xTempStorage
, "SubStorage1" );
171 if ( xClonedSubStorage
== null )
173 m_aTestHelper
.Error( "The result of clone is empty!" );
177 if ( !m_aTestHelper
.checkStorageProperties( xClonedSubStorage
, "MediaType4", true, ElementModes
.WRITE
) )
180 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
, "SubStream2", "MediaType2", true, pBytes2
) )
183 if ( !m_aTestHelper
.checkStream( xClonedSubStorage
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
186 XStorage xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xStorageFactory
, xTempStorage
);
187 if ( xCloneOfRoot
== null )
189 m_aTestHelper
.Error( "The result of root clone is empty!" );
193 XNameAccess xCloneOfRootNA
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xCloneOfRoot
);
194 if ( xCloneOfRootNA
== null )
196 m_aTestHelper
.Error( "XNameAccess is not implemented by the root clone!" );
200 if ( xCloneOfRootNA
.hasElements() )
202 m_aTestHelper
.Error( "The root storage still was not commited so it's clone must be empty!" );
206 if ( !m_aTestHelper
.disposeStorage( xCloneOfRoot
) )
211 // ==============================
212 // commit root storage and check cloning
213 // ==============================
215 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
218 xCloneOfRoot
= m_aTestHelper
.cloneStorage( m_xStorageFactory
, xTempStorage
);
219 if ( xCloneOfRoot
== null )
221 m_aTestHelper
.Error( "The result of root clone is empty!" );
225 XStorage xSubStorageOfClone
= xCloneOfRoot
.openStorageElement( "SubStorage1", ElementModes
.READ
);
226 if ( xSubStorageOfClone
== null )
228 m_aTestHelper
.Error( "The result of root clone is wrong!" );
232 if ( !m_aTestHelper
.checkStorageProperties( xSubStorageOfClone
, "MediaType4", false, ElementModes
.READ
) )
235 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
, "SubStream2", "MediaType2", true, pBytes2
) )
238 if ( !m_aTestHelper
.checkStream( xSubStorageOfClone
, "BigSubStream2", "MediaType2", true, pBigBytes
) )
245 m_aTestHelper
.Error( "Exception: " + e
);