1 package complex
.storages
;
3 import com
.sun
.star
.uno
.XInterface
;
4 import com
.sun
.star
.lang
.XMultiServiceFactory
;
5 import com
.sun
.star
.lang
.XSingleServiceFactory
;
7 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
8 import com
.sun
.star
.uno
.UnoRuntime
;
9 import com
.sun
.star
.uno
.XInterface
;
10 import com
.sun
.star
.io
.XStream
;
11 import com
.sun
.star
.io
.XInputStream
;
13 import com
.sun
.star
.embed
.*;
15 import share
.LogWriter
;
16 import complex
.storages
.TestHelper
;
17 import complex
.storages
.StorageTest
;
19 public class RegressionTest_i29321
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i29321( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i29321: " );
36 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
37 if ( xTempFileStream
== null )
40 // create storage based on the temporary stream
41 Object pArgs
[] = new Object
[2];
42 pArgs
[0] = (Object
) xTempFileStream
;
43 pArgs
[1] = new Integer( ElementModes
.WRITE
);
45 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
46 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
47 if ( xTempStorage
== null )
49 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
53 // open a new substorage
54 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
57 if ( xTempSubStorage
== null )
59 m_aTestHelper
.Error( "Can't create substorage!" );
63 // open a new substorage
64 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
67 if ( xTempSubSubStorage
== null )
69 m_aTestHelper
.Error( "Can't create substorage!" );
73 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "Stream1", "MediaType1", true, pBytes1
) )
79 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
80 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType2", true, pBytes1
) )
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType3", true, pBytes1
) )
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
91 ElementModes
.WRITE
) )
94 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
95 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
98 ElementModes
.WRITE
) )
101 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
105 ElementModes
.WRITE
) )
108 // ================================================
109 // commit the storages twice to test the bug scenario
110 // ================================================
112 // commit lowlevel substorage first
113 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
117 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
120 // commit substorage to let the renaming take place
121 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
124 // commit lowlevel substorage first
125 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
129 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
132 // commit substorage to let the renaming take place
133 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
136 // ================================================
137 // check the storages and streams without closing
138 // ================================================
140 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType6", false, ElementModes
.WRITE
) )
143 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType5", false, ElementModes
.WRITE
) )
146 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType4", true, ElementModes
.WRITE
) )
149 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType3", true, pBytes1
) )
152 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream1", "MediaType2", true, pBytes1
) )
155 if ( !m_aTestHelper
.checkStream( xTempStorage
, "Stream1", "MediaType1", true, pBytes1
) )
158 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
159 // any resource, later the garbage collector will release the object and it must die by refcount
165 m_aTestHelper
.Error( "Exception: " + e
);