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