Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i29321.java
bloba56e545bac185c84742e6f57b5f480c48dd35eaf
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 )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i29321: " );
32 public boolean test()
34 try
36 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
37 if ( xTempFileStream == null )
38 return false;
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!" );
50 return false;
53 // open a new substorage
54 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
55 "SubStorage1",
56 ElementModes.WRITE );
57 if ( xTempSubStorage == null )
59 m_aTestHelper.Error( "Can't create substorage!" );
60 return false;
63 // open a new substorage
64 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
65 "SubSubStorage1",
66 ElementModes.WRITE );
67 if ( xTempSubSubStorage == null )
69 m_aTestHelper.Error( "Can't create substorage!" );
70 return false;
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 ) )
77 return false;
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 ) )
81 return false;
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 ) )
85 return false;
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
89 "MediaType4",
90 true,
91 ElementModes.WRITE ) )
92 return false;
94 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
95 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
96 "MediaType5",
97 false,
98 ElementModes.WRITE ) )
99 return false;
101 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
103 "MediaType6",
104 false,
105 ElementModes.WRITE ) )
106 return false;
108 // ================================================
109 // commit the storages twice to test the bug scenario
110 // ================================================
112 // commit lowlevel substorage first
113 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
114 return false;
116 // commit substorage
117 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
118 return false;
120 // commit substorage to let the renaming take place
121 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
122 return false;
124 // commit lowlevel substorage first
125 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
126 return false;
128 // commit substorage
129 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
130 return false;
132 // commit substorage to let the renaming take place
133 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
134 return false;
136 // ================================================
137 // check the storages and streams without closing
138 // ================================================
140 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType6", false, ElementModes.WRITE ) )
141 return false;
143 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType5", false, ElementModes.WRITE ) )
144 return false;
146 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType4", true, ElementModes.WRITE ) )
147 return false;
149 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType3", true, pBytes1 ) )
150 return false;
152 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType2", true, pBytes1 ) )
153 return false;
155 if ( !m_aTestHelper.checkStream( xTempStorage, "Stream1", "MediaType1", true, pBytes1 ) )
156 return false;
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
161 return true;
163 catch( Exception e )
165 m_aTestHelper.Error( "Exception: " + e );
166 return false;