xref: /trunk/main/odk/examples/java/Storage/TestHelper.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 package storagetesting;
2 
3 import com.sun.star.uno.UnoRuntime;
4 import com.sun.star.uno.XInterface;
5 import com.sun.star.uno.AnyConverter;
6 
7 import com.sun.star.lang.*;
8 import com.sun.star.embed.*;
9 import com.sun.star.packages.*;
10 import com.sun.star.io.*;
11 import com.sun.star.beans.*;
12 
13 public class TestHelper  {
14 
15     String m_sTestPrefix;
16 
17     public TestHelper( String sTestPrefix )
18     {
19         m_sTestPrefix = sTestPrefix;
20     }
21 
22     public boolean WriteBytesToStream( XStream xStream,
23                                         String sStreamName,
24                                         String sMediaType,
25                                         boolean bCompressed,
26                                         byte[] pBytes )
27     {
28         // get output stream of substream
29         XOutputStream xOutput = xStream.getOutputStream();
30         if ( xOutput == null )
31         {
32             Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" );
33             return false;
34         }
35 
36         // get XTrucate implementation from output stream
37         XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput );
38         if ( xTruncate == null )
39         {
40             Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" );
41             return false;
42         }
43 
44         // write requested byte sequence
45         try
46         {
47             xTruncate.truncate();
48             xOutput.writeBytes( pBytes );
49         }
50         catch( Exception e )
51         {
52             Error( "Can't write to stream '" + sStreamName + "', exception: " + e );
53             return false;
54         }
55 
56         // get access to the XPropertySet interface
57         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
58         if ( xPropSet == null )
59         {
60             Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
61             return false;
62         }
63 
64         // set properties to the stream
65         try
66         {
67             xPropSet.setPropertyValue( "MediaType", sMediaType );
68             xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) );
69         }
70         catch( Exception e )
71         {
72             Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e );
73             return false;
74         }
75 
76         // check size property of the stream
77         try
78         {
79             int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
80             if ( nSize != pBytes.length )
81             {
82                 Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" );
83                 return false;
84             }
85         }
86         catch( Exception e )
87         {
88             Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e );
89             return false;
90         }
91 
92         // free the stream resources, garbage collector may remove the object too late
93         XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream );
94         if ( xComponent == null )
95         {
96             Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
97             return false;
98         }
99         xComponent.dispose();
100 
101         return true;
102     }
103 
104 
105     public boolean WriteBytesToSubstream( XStorage xStorage,
106                                           String sStreamName,
107                                           String sMediaType,
108                                           boolean bCompressed,
109                                           byte[] pBytes )
110     {
111         // open substream element
112         XStream xSubStream = null;
113         try
114         {
115             Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE );
116             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
117             if ( xSubStream == null )
118             {
119                 Error( "Can't create substream '" + sStreamName + "'!" );
120                 return false;
121             }
122         }
123         catch( Exception e )
124         {
125             Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
126             return false;
127         }
128 
129         return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
130     }
131 
132     public boolean WriteBytesToEncrSubstream( XStorage xStorage,
133                                               String sStreamName,
134                                               String sMediaType,
135                                               boolean bCompressed,
136                                               byte[] pBytes,
137                                               byte[] pPass )
138     {
139         // open substream element
140         XStream xSubStream = null;
141         try
142         {
143             Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pPass );
144             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
145             if ( xSubStream == null )
146             {
147                 Error( "Can't create substream '" + sStreamName + "'!" );
148                 return false;
149             }
150         }
151         catch( Exception e )
152         {
153             Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
154             return false;
155         }
156 
157         return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
158     }
159 
160     public boolean WBToSubstrOfEncr( XStorage xStorage,
161                                               String sStreamName,
162                                               String sMediaType,
163                                               boolean bCompressed,
164                                               byte[] pBytes,
165                                               boolean bEncrypted )
166     {
167         // open substream element
168         XStream xSubStream = null;
169         try
170         {
171             Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE );
172             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
173             if ( xSubStream == null )
174             {
175                 Error( "Can't create substream '" + sStreamName + "'!" );
176                 return false;
177             }
178         }
179         catch( Exception e )
180         {
181             Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
182             return false;
183         }
184 
185         // get access to the XPropertySet interface
186         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream );
187         if ( xPropSet == null )
188         {
189             Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
190             return false;
191         }
192 
193         // set properties to the stream
194         try
195         {
196             xPropSet.setPropertyValue( "Encrypted", new Boolean( bEncrypted ) );
197         }
198         catch( Exception e )
199         {
200             Error( "Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e );
201             return false;
202         }
203 
204         return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes );
205     }
206 
207     public int ChangeStreamPass( XStorage xStorage,
208                                  String sStreamName,
209                                  byte[] pOldPass,
210                                  byte[] pNewPass )
211     {
212         // open substream element
213         XStream xSubStream = null;
214         try
215         {
216             Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pOldPass );
217             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
218             if ( xSubStream == null )
219             {
220                 Error( "Can't open substream '" + sStreamName + "'!" );
221                 return 0;
222             }
223         }
224         catch( Exception e )
225         {
226             Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" );
227             return 0;
228         }
229 
230 
231         // change the password for the stream
232         XEncryptionProtectedSource xStreamEncryption =
233                 (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream );
234 
235         if ( xStreamEncryption == null )
236         {
237             Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" );
238             return -1;
239         }
240 
241         try {
242             xStreamEncryption.setEncryptionKey( pNewPass );
243         }
244         catch( Exception e )
245         {
246             Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e );
247             return 0;
248         }
249 
250         // free the stream resources, garbage collector may remove the object too late
251         XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xSubStream );
252         if ( xComponent == null )
253         {
254             Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
255             return 0;
256         }
257         xComponent.dispose();
258 
259         return 1;
260     }
261 
262     public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )
263     {
264         boolean bOk = false;
265 
266         // get access to the XPropertySet interface
267         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
268         if ( xPropSet != null )
269         {
270             try
271             {
272                 // set "MediaType" property to the stream
273                 xPropSet.setPropertyValue( "MediaType", sMediaType );
274 
275                 // get "IsRoot" and "OpenMode" properties and control there values
276                 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
277                 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
278 
279                 bOk = true;
280                 if ( bPropIsRoot != bIsRoot )
281                 {
282                     Error( "'IsRoot' property contains wrong value!" );
283                     bOk = false;
284                 }
285 
286                 if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) )
287                   || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
288                 {
289                     Error( "'OpenMode' property contains wrong value!" );
290                     bOk = false;
291                 }
292             }
293             catch( Exception e )
294             {
295                 Error( "Can't control properties of substorage, exception: " + e );
296             }
297         }
298         else
299         {
300             Error( "Can't get XPropertySet implementation from storage!" );
301         }
302 
303         return bOk;
304     }
305 
306     public boolean checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )
307     {
308         boolean bOk = false;
309 
310         // get access to the XPropertySet interface
311         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
312         if ( xPropSet != null )
313         {
314             try
315             {
316                 // get "MediaType", "IsRoot" and "OpenMode" properties and control there values
317                 String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
318                 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
319                 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
320 
321                 bOk = true;
322                 if ( !sPropMediaType.equals( sMediaType ) )
323                 {
324                     Error( "'MediaType' property contains wrong value, expected '"
325                             + sMediaType + "', set '" + sPropMediaType + "' !" );
326                     bOk = false;
327                 }
328 
329                 if ( bPropIsRoot != bIsRoot )
330                 {
331                     Error( "'IsRoot' property contains wrong value!" );
332                     bOk = false;
333                 }
334 
335                 if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) )
336                   || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
337                 {
338                     Error( "'OpenMode' property contains wrong value!" );
339                     bOk = false;
340                 }
341             }
342             catch( Exception e )
343             {
344                 Error( "Can't get properties of substorage, exception: " + e );
345             }
346         }
347         else
348         {
349             Error( "Can't get XPropertySet implementation from storage!" );
350         }
351 
352         return bOk;
353     }
354 
355     public boolean InternalCheckStream( XStream xStream,
356                                         String sName,
357                                         String sMediaType,
358                                         byte[] pBytes )
359     {
360         // get input stream of substream
361         XInputStream xInput = xStream.getInputStream();
362         if ( xInput == null )
363         {
364             Error( "Can't get XInputStream implementation from substream '" + sName + "'!" );
365             return false;
366         }
367 
368         byte pContents[][] = new byte[1][]; // ???
369 
370         // read contents
371         try
372         {
373             xInput.readBytes( pContents, pBytes.length + 1 );
374         }
375         catch( Exception e )
376         {
377             Error( "Can't read from stream '" + sName + "', exception: " + e );
378             return false;
379         }
380 
381         // check size of stream data
382         if ( pContents.length == 0 )
383         {
384             Error( "SubStream '" + sName + "' reading produced disaster!"  );
385             return false;
386         }
387 
388         if ( pBytes.length != pContents[0].length )
389         {
390             Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" );
391             return false;
392         }
393 
394         // check stream data
395         for ( int ind = 0; ind < pBytes.length; ind++ )
396         {
397             if ( pBytes[ind] != pContents[0][ind] )
398             {
399                 Error( "SubStream '" + sName + "' contains wrong data!" );
400                 return false;
401             }
402         }
403 
404 
405         // check properties
406         boolean bOk = false;
407 
408         // get access to the XPropertySet interface
409         XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
410         if ( xPropSet != null )
411         {
412             try
413             {
414                 // get "MediaType" and "Size" properties and control there values
415                 String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
416                 int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
417 
418                 bOk = true;
419                 if ( !sPropMediaType.equals( sMediaType ) )
420                 {
421                     Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '"
422                             + sMediaType + "', set: '" + sPropMediaType + "'!" );
423                     bOk = false;
424                 }
425 
426                 if ( nPropSize != pBytes.length )
427                 {
428                     Error( "'Size' property contains wrong value for stream'" + sName + "'!" );
429                     bOk = false;
430                 }
431             }
432             catch( Exception e )
433             {
434                 Error( "Can't get properties of substream '" + sName + "', exception: " + e );
435             }
436         }
437         else
438         {
439             Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" );
440         }
441 
442         return bOk;
443     }
444 
445     public boolean checkStream( XStorage xParentStorage,
446                                 String sName,
447                                 String sMediaType,
448                                 byte[] pBytes )
449     {
450         // open substream element first
451         XStream xSubStream = null;
452         try
453         {
454             Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ );
455             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
456             if ( xSubStream == null )
457             {
458                 Error( "Can't open substream '" + sName + "'!" );
459                 return false;
460             }
461         }
462         catch( Exception e )
463         {
464             Error( "Can't open substream '" + sName + "', exception : " + e + "!" );
465             return false;
466         }
467 
468         return InternalCheckStream( xSubStream, sName, sMediaType, pBytes );
469     }
470 
471     public boolean checkEncrStream( XStorage xParentStorage,
472                                     String sName,
473                                     String sMediaType,
474                                     byte[] pBytes,
475                                     byte[] pPass )
476     {
477         // Important: a common password for any of parent storage should not be set or
478         //            should be different from pPass
479 
480         if ( pPass.length == 0 )
481         {
482             Error( "Wrong password is used in the test!" );
483             return false;
484         }
485 
486         try
487         {
488             Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ );
489             Error( "Encrypted stream '" + sName + "' was opened without password!" );
490             return false;
491         }
492         catch( WrongPasswordException wpe )
493         {}
494         catch( Exception e )
495         {
496             Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" );
497             return false;
498         }
499 
500         byte pWrongPass[] = { 1, 1 };
501         pWrongPass[0] += pPass[0];
502         try
503         {
504             Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pWrongPass );
505             Error( "Encrypted stream '" + sName + "' was opened with wrong password!" );
506             return false;
507         }
508         catch( WrongPasswordException wpe )
509         {}
510         catch( Exception e )
511         {
512             Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" );
513             return false;
514         }
515 
516         XStream xSubStream = null;
517         try
518         {
519             Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pPass );
520             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
521             if ( xSubStream == null )
522             {
523                 Error( "Can't open encrypted substream '" + sName + "'!" );
524                 return false;
525             }
526         }
527         catch( Exception e )
528         {
529             Error( "Can't open encrypted substream '" + sName + "', exception : " + e + "!" );
530             return false;
531         }
532 
533         return InternalCheckStream( xSubStream, sName, sMediaType, pBytes );
534     }
535 
536     public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage )
537     {
538         // copy xSourceStorage to xDestStorage
539         try
540         {
541             xSourceStorage.copyToStorage( xDestStorage );
542         }
543         catch( Exception e )
544         {
545             Error( "Storage copying failed, exception: " + e );
546             return false;
547         }
548 
549         return true;
550     }
551 
552     public boolean commitStorage( XStorage xStorage )
553     {
554         // XTransactedObject must be supported by storages
555         XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
556         if ( xTransact == null )
557         {
558             Error( "Storage doesn't implement transacted access!" );
559             return false;
560         }
561 
562         try
563         {
564             xTransact.commit();
565         }
566         catch( Exception e )
567         {
568             Error( "Storage commit failed, exception:" + e );
569             return false;
570         }
571 
572         return true;
573     }
574 
575     public boolean disposeStorage( XStorage xStorage )
576     {
577         // dispose the storage
578         XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage );
579         if ( xComponent == null )
580         {
581             Error( "Can't retrieve XComponent implementation from storage!" );
582             return false;
583         }
584 
585         try
586         {
587             xComponent.dispose();
588         }
589         catch( Exception e )
590         {
591             Error( "Storage disposing failed!" );
592             return false;
593         }
594 
595         return true;
596     }
597 
598     public XInputStream getInputStream( XStream xStream )
599     {
600         XInputStream xInTemp = null;
601         try
602         {
603             xInTemp = xStream.getInputStream();
604             if ( xInTemp == null )
605                 Error( "Can't get the input part of a stream!" );
606         }
607         catch ( Exception e )
608         {
609             Error( "Can't get the input part of a stream, exception :" + e );
610         }
611 
612         return xInTemp;
613     }
614 
615     public boolean closeOutput( XStream xStream )
616     {
617         XOutputStream xOutTemp = null;
618         try
619         {
620             xOutTemp = xStream.getOutputStream();
621             if ( xOutTemp == null )
622             {
623                 Error( "Can't get the output part of a stream!" );
624                 return false;
625             }
626         }
627         catch ( Exception e )
628         {
629             Error( "Can't get the output part of a stream, exception :" + e );
630             return false;
631         }
632 
633         try
634         {
635             xOutTemp.closeOutput();
636         }
637         catch ( Exception e )
638         {
639             Error( "Can't close output part of a stream, exception :" + e );
640             return false;
641         }
642 
643         return true;
644     }
645 
646     public XStorage openSubStorage( XStorage xStorage, String sName, int nMode )
647     {
648         // open existing substorage
649         try
650         {
651             Object oSubStorage = xStorage.openStorageElement( sName, nMode );
652             XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage );
653             return xSubStorage;
654         }
655         catch( Exception e )
656         {
657             Error( "Can't open substorage '" + sName + "', exception: " + e );
658         }
659 
660         return null;
661     }
662 
663     public XStream CreateTempFileStream( XMultiServiceFactory xMSF )
664     {
665         // try to get temporary file representation
666         XStream xTempFileStream = null;
667         try
668         {
669             Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
670             xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile );
671         }
672         catch( Exception e )
673         {}
674 
675         if ( xTempFileStream == null )
676             Error( "Can't create temporary file!" );
677 
678         return xTempFileStream;
679     }
680 
681     public String CreateTempFile( XMultiServiceFactory xMSF )
682     {
683         String sResult = null;
684 
685         // try to get temporary file representation
686         XPropertySet xTempFileProps = null;
687         try
688         {
689             Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
690             xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile );
691         }
692         catch( Exception e )
693         {}
694 
695         if ( xTempFileProps != null )
696         {
697             try
698             {
699                 xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) );
700                 sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) );
701             }
702             catch( Exception e )
703             {
704                 Error( "Can't control TempFile properties, exception: " + e );
705             }
706         }
707         else
708         {
709             Error( "Can't create temporary file representation!" );
710         }
711 
712         // close temporary file explicitly
713         try
714         {
715             XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps );
716             if ( xStream != null )
717             {
718                 XOutputStream xOut = xStream.getOutputStream();
719                 if ( xOut != null )
720                     xOut.closeOutput();
721 
722                 XInputStream xIn = xStream.getInputStream();
723                 if ( xIn != null )
724                     xIn.closeInput();
725             }
726             else
727                 Error( "Can't close TempFile!" );
728         }
729         catch( Exception e )
730         {
731             Error( "Can't close TempFile, exception: " + e );
732         }
733 
734         return sResult;
735     }
736 
737     public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest )
738     {
739         // copy element with name sName from xSource to xDest
740         try
741         {
742             xSource.copyElementTo( sName, xDest, sName );
743         }
744         catch( Exception e )
745         {
746             Error( "Element copying failed, exception: " + e );
747             return false;
748         }
749 
750         return true;
751     }
752 
753     public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest )
754     {
755         // move element with name sName from xSource to xDest
756         try
757         {
758             xSource.moveElementTo( sName, xDest, sName );
759         }
760         catch( Exception e )
761         {
762             Error( "Element moving failed, exception: " + e );
763             return false;
764         }
765 
766         return true;
767     }
768 
769     public boolean renameElement( XStorage xStorage, String sOldName, String sNewName )
770     {
771         // rename element with name sOldName to sNewName
772         try
773         {
774             xStorage.renameElement( sOldName, sNewName );
775         }
776         catch( Exception e )
777         {
778             Error( "Element renaming failed, exception: " + e );
779             return false;
780         }
781 
782         return true;
783     }
784 
785     public boolean removeElement( XStorage xStorage, String sName )
786     {
787         // remove element with name sName
788         try
789         {
790             xStorage.removeElement( sName );
791         }
792         catch( Exception e )
793         {
794             Error( "Element removing failed, exception: " + e );
795             return false;
796         }
797 
798         return true;
799     }
800 
801     public XStream OpenStream( XStorage xStorage,
802                                 String sStreamName,
803                                 int nMode )
804     {
805         // open substream element
806         XStream xSubStream = null;
807         try
808         {
809             Object oSubStream = xStorage.openStreamElement( sStreamName, nMode );
810             xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
811             if ( xSubStream == null )
812                 Error( "Can't create substream '" + sStreamName + "'!" );
813         }
814         catch( Exception e )
815         {
816             Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
817         }
818 
819         return xSubStream;
820     }
821 
822     public boolean cantOpenStorage( XStorage xStorage, String sName )
823     {
824         // try to open an opened substorage, open call must fail
825         try
826         {
827             Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.ELEMENT_READ );
828             Error( "The trying to reopen opened substorage '" + sName + "' must fail!" );
829         }
830         catch( Exception e )
831         {
832             return true;
833         }
834 
835         return false;
836     }
837 
838     public boolean cantOpenStream( XStorage xStorage, String sName, int nMode )
839     {
840         // try to open the substream with specified mode must fail
841         try
842         {
843             Object oDummyStream = xStorage.openStreamElement( sName, nMode );
844             Error( "The trying to open substoream '" + sName + "' must fail!" );
845         }
846         catch( Exception e )
847         {
848             return true;
849         }
850 
851         return false;
852     }
853 
854     public void Error( String sError )
855     {
856         System.out.println( m_sTestPrefix + "Error: " + sError );
857     }
858 
859     public void Message( String sError )
860     {
861         System.out.println( m_sTestPrefix + sError );
862     }
863 }
864 
865