1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package org.apache.harmony.luni.tests.java.io; 19 20import java.io.File; 21import java.io.IOException; 22import java.io.Serializable; 23import java.lang.reflect.InvocationHandler; 24import java.lang.reflect.Method; 25import java.lang.reflect.Proxy; 26import java.net.URI; 27import java.net.URISyntaxException; 28import java.security.cert.Certificate; 29import java.text.DateFormat; 30import java.text.MessageFormat; 31import java.text.NumberFormat; 32import java.util.*; 33 34 35 36import tests.support.Support_Configuration; 37import tests.support.Support_Proxy_I1; 38 39@SuppressWarnings( { "serial", "unused" }) 40public class SerializationStressTest4 extends SerializationStressTest { 41 // ----------------------------------------------------------------------------------- 42 private static class GuardImplementation implements java.security.Guard, 43 java.io.Serializable { 44 public GuardImplementation() { 45 } 46 47 public void checkGuard(Object o) { 48 } 49 } 50 51 public SerializationStressTest4(String name) { 52 super(name); 53 } 54 55 public void test_writeObject_EventObject() { 56 // Test for method void 57 // java.io.ObjectOutputStream.writeObject(java.util.EventObject) 58 59 Object objToSave = null; 60 Object objLoaded = null; 61 62 try { 63 objToSave = new java.util.EventObject("Source"); 64 if (DEBUG) 65 System.out.println("Obj = " + objToSave); 66 objLoaded = dumpAndReload(objToSave); 67 68 // Has to have worked 69 boolean equals; 70 equals = true; 71 // The the only data in EventObject that 72 // differentiates between instantiations is transient 73 assertTrue(MSG_TEST_FAILED + objToSave, equals); 74 } catch (IOException e) { 75 fail("IOException serializing " + objToSave + " : " 76 + e.getMessage()); 77 } catch (ClassNotFoundException e) { 78 fail("ClassNotFoundException reading Object type : " 79 + e.getMessage()); 80 } catch (Error err) { 81 System.out.println("Error when obj = " + objToSave); 82 // err.printStackTrace(); 83 throw err; 84 } 85 } 86 87 public void test_writeObject_Collections_EmptySet() { 88 // Test for method void 89 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet) 90 91 Object objToSave = null; 92 Object objLoaded = null; 93 94 try { 95 objToSave = java.util.Collections.EMPTY_SET; 96 if (DEBUG) 97 System.out.println("Obj = " + objToSave); 98 objLoaded = dumpAndReload(objToSave); 99 100 // Has to have worked 101 boolean equals; 102 equals = objToSave.equals(objLoaded); 103 if (equals) 104 equals = ((Set) objLoaded).size() == 0; 105 assertTrue(MSG_TEST_FAILED + objToSave, equals); 106 } catch (IOException e) { 107 fail("IOException serializing " + objToSave + " : " 108 + e.getMessage()); 109 } catch (ClassNotFoundException e) { 110 fail("ClassNotFoundException reading Object type : " 111 + e.getMessage()); 112 } catch (Error err) { 113 System.out.println("Error when obj = " + objToSave); 114 // err.printStackTrace(); 115 throw err; 116 } 117 118 } 119 120 public void test_writeObject_Collections_EmptyMap() { 121 // Test for method void 122 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptySet) 123 124 Object objToSave = null; 125 Object objLoaded = null; 126 127 try { 128 objToSave = java.util.Collections.EMPTY_MAP; 129 if (DEBUG) 130 System.out.println("Obj = " + objToSave); 131 objLoaded = dumpAndReload(objToSave); 132 133 // Has to have worked 134 boolean equals; 135 equals = objToSave.equals(objLoaded); 136 if (equals) 137 equals = ((Map) objLoaded).size() == 0; 138 assertTrue(MSG_TEST_FAILED + objToSave, equals); 139 } catch (IOException e) { 140 fail("IOException serializing " + objToSave + " : " 141 + e.getMessage()); 142 } catch (ClassNotFoundException e) { 143 fail("ClassNotFoundException reading Object type : " 144 + e.getMessage()); 145 } catch (Error err) { 146 System.out.println("Error when obj = " + objToSave); 147 // err.printStackTrace(); 148 throw err; 149 } 150 151 } 152 153 public void test_writeObject_Character() { 154 // Test for method void 155 // java.io.ObjectOutputStream.writeObject(java.lang.Character) 156 157 Object objToSave = null; 158 Object objLoaded = null; 159 160 try { 161 objToSave = new java.lang.Character('c'); 162 if (DEBUG) 163 System.out.println("Obj = " + objToSave); 164 objLoaded = dumpAndReload(objToSave); 165 166 // Has to have worked 167 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 168 } catch (IOException e) { 169 fail("IOException serializing " + objToSave + " : " 170 + e.getMessage()); 171 } catch (ClassNotFoundException e) { 172 fail("ClassNotFoundException reading Object type : " 173 + e.getMessage()); 174 } catch (Error err) { 175 System.out.println("Error when obj = " + objToSave); 176 // err.printStackTrace(); 177 throw err; 178 } 179 180 } 181 182 public void test_writeObject_Collections_UnmodifiableCollection() { 183 // Test for method void 184 // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableCollection) 185 186 Object objToSave = null; 187 Object objLoaded = null; 188 189 try { 190 objToSave = Collections.unmodifiableCollection(SET); 191 if (DEBUG) 192 System.out.println("Obj = " + objToSave); 193 objLoaded = dumpAndReload(objToSave); 194 195 // Has to have worked 196 boolean equals; 197 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 198 .size(); 199 if (equals) { 200 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 201 .iterator(), iter2 = ((java.util.Collection) objLoaded) 202 .iterator(); 203 while (iter1.hasNext()) 204 equals = equals && iter1.next().equals(iter2.next()); 205 } 206 assertTrue(MSG_TEST_FAILED + objToSave, equals); 207 } catch (IOException e) { 208 fail("IOException serializing " + objToSave + " : " 209 + e.getMessage()); 210 } catch (ClassNotFoundException e) { 211 fail("ClassNotFoundException reading Object type : " 212 + e.getMessage()); 213 } catch (Error err) { 214 System.out.println("Error when obj = " + objToSave); 215 // err.printStackTrace(); 216 throw err; 217 } 218 219 } 220 221 public void test_writeObject_Format() { 222 // Test for method void 223 // java.io.ObjectOutputStream.writeObject(java.text.Format) 224 225 Object objToSave = null; 226 Object objLoaded = null; 227 228 try { 229 objToSave = null; 230 objToSave = new java.text.Format() { 231 String save = "default"; 232 233 public StringBuffer format(Object p1, StringBuffer p2, 234 java.text.FieldPosition p3) { 235 return new StringBuffer(); 236 } 237 238 public Object parseObject(String p1, java.text.ParsePosition p2) { 239 if (p1 != null) 240 save = p1; 241 return save; 242 } 243 244 public boolean equals(Object obj) { 245 if (!(obj instanceof java.text.Format)) 246 return false; 247 return save.equals(((java.text.Format) obj).parseObject( 248 null, null)); 249 } 250 }; 251 252 ((java.text.Format) objToSave).parseObject("Test", null); 253 if (DEBUG) 254 System.out.println("Obj = " + objToSave); 255 objLoaded = dumpAndReload(objToSave); 256 257 // Has to have worked 258 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 259 } catch (IOException e) { 260 fail("IOException serializing " + objToSave + " : " 261 + e.getMessage()); 262 } catch (ClassNotFoundException e) { 263 fail("ClassNotFoundException reading Object type : " 264 + e.getMessage()); 265 } catch (Error err) { 266 System.out.println("Error when obj = " + objToSave); 267 // err.printStackTrace(); 268 throw err; 269 } 270 } 271 272 public void test_writeObject_BigDecimal() { 273 // Test for method void 274 // java.io.ObjectOutputStream.writeObject(java.math.BigDecimal) 275 276 Object objToSave = null; 277 Object objLoaded = null; 278 279 try { 280 objToSave = new java.math.BigDecimal("1.2345"); 281 if (DEBUG) 282 System.out.println("Obj = " + objToSave); 283 objLoaded = dumpAndReload(objToSave); 284 285 // Has to have worked 286 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 287 } catch (IOException e) { 288 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 289 } catch (ClassNotFoundException e) { 290 fail("ClassNotFoundException reading Object type: " 291 + e.getMessage()); 292 } catch (Error err) { 293 System.out.println("Error when obj = " + objToSave); 294 // err.printStackTrace(); 295 throw err; 296 } 297 298 } 299 300 public void test_writeObject_SecureRandomSpi() { 301 // Test for method void 302 // java.io.ObjectOutputStream.writeObject(java.security.SecureRandomSpi) 303 304 Object objToSave = null; 305 Object objLoaded = null; 306 307 try { 308 objToSave = null; 309 objToSave = new java.security.SecureRandomSpi() { 310 protected byte[] engineGenerateSeed(int p1) { 311 return new byte[0]; 312 } 313 314 protected void engineNextBytes(byte[] p1) { 315 } 316 317 protected void engineSetSeed(byte[] p1) { 318 } 319 320 public boolean equals(Object obj) { 321 return true; 322 } 323 }; 324 if (DEBUG) 325 System.out.println("Obj = " + objToSave); 326 objLoaded = dumpAndReload(objToSave); 327 328 // Has to have worked 329 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 330 } catch (IOException e) { 331 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 332 } catch (ClassNotFoundException e) { 333 fail("ClassNotFoundException reading Object type: " 334 + e.getMessage()); 335 } catch (Error err) { 336 System.out.println("Error when obj = " + objToSave); 337 // err.printStackTrace(); 338 throw err; 339 } 340 } 341 342 public void test_writeObject_Short() { 343 // Test for method void 344 // java.io.ObjectOutputStream.writeObject(java.lang.Short) 345 346 Object objToSave = null; 347 Object objLoaded = null; 348 349 try { 350 objToSave = new java.lang.Short((short) 107); 351 if (DEBUG) 352 System.out.println("Obj = " + objToSave); 353 objLoaded = dumpAndReload(objToSave); 354 355 // Has to have worked 356 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 357 } catch (IOException e) { 358 fail("IOException serializing " + objToSave + " : " 359 + e.getMessage()); 360 } catch (ClassNotFoundException e) { 361 fail("ClassNotFoundException reading Object type : " 362 + e.getMessage()); 363 } catch (Error err) { 364 System.out.println("Error when obj = " + objToSave); 365 // err.printStackTrace(); 366 throw err; 367 } 368 369 } 370 371 public void test_writeObject_Byte() { 372 // Test for method void 373 // java.io.ObjectOutputStream.writeObject(java.lang.Byte) 374 375 Object objToSave = null; 376 Object objLoaded = null; 377 378 try { 379 objToSave = new java.lang.Byte((byte) 107); 380 if (DEBUG) 381 System.out.println("Obj = " + objToSave); 382 objLoaded = dumpAndReload(objToSave); 383 384 // Has to have worked 385 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 386 } catch (IOException e) { 387 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 388 } catch (ClassNotFoundException e) { 389 fail("ClassNotFoundException reading Object type: " 390 + e.getMessage()); 391 } catch (Error err) { 392 System.out.println("Error when obj = " + objToSave); 393 // err.printStackTrace(); 394 throw err; 395 } 396 397 } 398 399 @SuppressWarnings("unchecked") 400 public void test_writeObject_String_CaseInsensitiveComparator() { 401 // Test for method void 402 // java.io.ObjectOutputStream.writeObject(java.lang.String.CaseInsensitiveComparator) 403 404 Object objToSave = null; 405 Object objLoaded = null; 406 407 try { 408 objToSave = java.lang.String.CASE_INSENSITIVE_ORDER; 409 if (DEBUG) 410 System.out.println("Obj = " + objToSave); 411 objLoaded = dumpAndReload(objToSave); 412 413 // Has to have worked 414 boolean equals; 415 equals = ((Comparator) objToSave).compare("apple", "Banana") == ((Comparator) objLoaded) 416 .compare("apple", "Banana"); 417 assertTrue(MSG_TEST_FAILED + objToSave, equals); 418 } catch (IOException e) { 419 fail("IOException serializing " + objToSave + " : " 420 + e.getMessage()); 421 } catch (ClassNotFoundException e) { 422 fail("ClassNotFoundException reading Object type : " 423 + e.getMessage()); 424 } catch (Error err) { 425 System.out.println("Error when obj = " + objToSave); 426 // err.printStackTrace(); 427 throw err; 428 } 429 430 } 431 432 public void test_writeObject_Calendar() { 433 // Test for method void 434 // java.io.ObjectOutputStream.writeObject(java.util.Calendar) 435 436 Object objToSave = null; 437 Object objLoaded = null; 438 439 try { 440 objToSave = new java.util.Calendar(TimeZone.getTimeZone("EST"), 441 Locale.CANADA) { 442 public void add(int p1, int p2) { 443 } 444 445 protected void computeFields() { 446 } 447 448 protected void computeTime() { 449 } 450 451 public int getGreatestMinimum(int p1) { 452 return 0; 453 } 454 455 public int getLeastMaximum(int p1) { 456 return 0; 457 } 458 459 public int getMaximum(int p1) { 460 return 0; 461 } 462 463 public int getMinimum(int p1) { 464 return 0; 465 } 466 467 public void roll(int p1, boolean p2) { 468 } 469 }; 470 if (DEBUG) 471 System.out.println("Obj = " + objToSave); 472 objLoaded = dumpAndReload(objToSave); 473 474 // Has to have worked 475 assertTrue(MSG_TEST_FAILED + "Calendar", objToSave 476 .equals(objLoaded)); 477 } catch (IOException e) { 478 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 479 } catch (ClassNotFoundException e) { 480 fail("ClassNotFoundException reading Object type: " 481 + e.getMessage()); 482 } catch (Error err) { 483 System.out.println("Error when obj = " + objToSave); 484 // err.printStackTrace(); 485 throw err; 486 } 487 488 } 489 490 public void test_writeObject_StringBuffer() { 491 // Test for method void 492 // java.io.ObjectOutputStream.writeObject(java.lang.StringBuffer) 493 494 Object objToSave = null; 495 Object objLoaded = null; 496 497 try { 498 objToSave = new java.lang.StringBuffer("This is a test."); 499 if (DEBUG) 500 System.out.println("Obj = " + objToSave); 501 objLoaded = dumpAndReload(objToSave); 502 503 // Has to have worked 504 boolean equals; 505 equals = ((java.lang.StringBuffer) objToSave).toString().equals( 506 ((java.lang.StringBuffer) objLoaded).toString()); 507 assertTrue(MSG_TEST_FAILED + objToSave, equals); 508 } catch (IOException e) { 509 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 510 } catch (ClassNotFoundException e) { 511 fail("ClassNotFoundException reading Object type: " 512 + e.getMessage()); 513 } catch (Error err) { 514 System.out.println("Error when obj = " + objToSave); 515 // err.printStackTrace(); 516 throw err; 517 } 518 519 } 520 521 public void test_writeObject_File() { 522 // Test for method void 523 // java.io.ObjectOutputStream.writeObject(java.io.File) 524 525 Object objToSave = null; 526 Object objLoaded = null; 527 528 try { 529 objToSave = new File("afile.txt"); 530 if (DEBUG) 531 System.out.println("Obj = " + objToSave); 532 objLoaded = dumpAndReload(objToSave); 533 534 // Has to have worked 535 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 536 } catch (IOException e) { 537 fail("IOException serializing " + objToSave + " : " 538 + e.getMessage()); 539 } catch (ClassNotFoundException e) { 540 fail("ClassNotFoundException reading Object type : " 541 + e.getMessage()); 542 } catch (Error err) { 543 System.out.println("Error when obj = " + objToSave); 544 // err.printStackTrace(); 545 throw err; 546 } 547 548 } 549 550 public void test_writeObject_BitSet() { 551 // Test for method void 552 // java.io.ObjectOutputStream.writeObject(java.util.BitSet) 553 554 Object objToSave = null; 555 Object objLoaded = null; 556 557 try { 558 objToSave = new java.util.BitSet(); 559 ((java.util.BitSet) objToSave).set(3); 560 ((java.util.BitSet) objToSave).set(5); 561 ((java.util.BitSet) objToSave).set(61, 89); 562 if (DEBUG) 563 System.out.println("Obj = " + objToSave); 564 objLoaded = dumpAndReload(objToSave); 565 566 // Has to have worked 567 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 568 } catch (IOException e) { 569 fail("IOException serializing " + objToSave + " : " 570 + e.getMessage()); 571 } catch (ClassNotFoundException e) { 572 fail("ClassNotFoundException reading Object type : " 573 + e.getMessage()); 574 } catch (Error err) { 575 System.out.println("Error when obj = " + objToSave); 576 // err.printStackTrace(); 577 throw err; 578 } 579 580 } 581 582 public void test_writeObject_DateFormat() { 583 // Test for method void 584 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat) 585 586 Object objToSave = null; 587 Object objLoaded = null; 588 589 try { 590 objToSave = null; 591 objToSave = new java.text.DateFormat() { 592 // Thu Feb 01 01:01:01 EST 2001 593 java.util.Date save = new java.util.Date(981007261000L); 594 595 public StringBuffer format(Date p1, StringBuffer p2, 596 java.text.FieldPosition p3) { 597 if (p1 != null) 598 save = p1; 599 return new StringBuffer(Long.toString(save.getTime())); 600 } 601 602 public Date parse(String p1, java.text.ParsePosition p2) { 603 return save; 604 } 605 606 public String toString() { 607 return save.toString(); 608 } 609 610 public boolean equals(Object obj) { 611 if (!(obj instanceof java.text.DateFormat)) 612 return false; 613 return save.equals(((java.text.DateFormat) obj).parse(null, 614 null)); 615 } 616 }; 617 if (DEBUG) 618 System.out.println("Obj = " + objToSave); 619 objLoaded = dumpAndReload(objToSave); 620 621 // Has to have worked 622 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 623 } catch (IOException e) { 624 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 625 } catch (ClassNotFoundException e) { 626 fail("ClassNotFoundException reading Object type: " 627 + e.getMessage()); 628 } catch (Error err) { 629 System.out.println("Error when obj = " + objToSave); 630 // err.printStackTrace(); 631 throw err; 632 } 633 634 } 635 636 public void test_writeObject_Collections_CopiesList() { 637 // Test for method void 638 // java.io.ObjectOutputStream.writeObject(java.util.Collections.CopiesList) 639 640 Object objToSave = null; 641 Object objLoaded = null; 642 643 try { 644 objToSave = java.util.Collections.nCopies(2, new Integer(2)); 645 if (DEBUG) 646 System.out.println("Obj = " + objToSave); 647 objLoaded = dumpAndReload(objToSave); 648 649 // Has to have worked 650 boolean equals; 651 equals = ((List) objToSave).get(0) 652 .equals(((List) objLoaded).get(0)); 653 if (equals) 654 equals = ((List) objToSave).get(1).equals( 655 ((List) objLoaded).get(1)); 656 assertTrue(MSG_TEST_FAILED + objToSave, equals); 657 } catch (IOException e) { 658 fail("IOException serializing " + objToSave + " : " 659 + e.getMessage()); 660 } catch (ClassNotFoundException e) { 661 fail("ClassNotFoundException reading Object type : " 662 + e.getMessage()); 663 } catch (Error err) { 664 System.out.println("Error when obj = " + objToSave); 665 // err.printStackTrace(); 666 throw err; 667 } 668 669 } 670 671 public void test_writeObject_Properties() { 672 // Test for method void 673 // java.io.ObjectOutputStream.writeObject(java.util.Properties) 674 675 Object objToSave = null; 676 Object objLoaded = null; 677 678 try { 679 objToSave = new java.util.Properties(); 680 ((java.util.Properties) objToSave).put("key1", "value1"); 681 ((java.util.Properties) objToSave).put("key2", "value2"); 682 if (DEBUG) 683 System.out.println("Obj = " + objToSave); 684 objLoaded = dumpAndReload(objToSave); 685 686 // Has to have worked 687 boolean equals; 688 Enumeration enum1 = ((java.util.Properties) objToSave).elements(), enum2 = ((java.util.Properties) objLoaded) 689 .elements(); 690 691 equals = true; 692 while (enum1.hasMoreElements() && equals) { 693 if (enum2.hasMoreElements()) 694 equals = enum1.nextElement().equals(enum2.nextElement()); 695 else 696 equals = false; 697 } 698 699 if (equals) 700 equals = !enum2.hasMoreElements(); 701 assertTrue(MSG_TEST_FAILED + objToSave, equals); 702 } catch (IOException e) { 703 fail("IOException serializing " + objToSave + " : " 704 + e.getMessage()); 705 } catch (ClassNotFoundException e) { 706 fail("ClassNotFoundException reading Object type : " 707 + e.getMessage()); 708 } catch (Error err) { 709 System.out.println("Error when obj = " + objToSave); 710 // err.printStackTrace(); 711 throw err; 712 } 713 714 } 715 716 public void test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() { 717 // Test for method void 718 // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet) 719 720 Object objToSave = null; 721 Object objLoaded = null; 722 723 try { 724 objToSave = java.util.Collections.unmodifiableMap(MAP).entrySet(); 725 if (DEBUG) 726 System.out.println("Obj = " + objToSave); 727 objLoaded = dumpAndReload(objToSave); 728 729 // Has to have worked 730 boolean equals; 731 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 732 .size(); 733 if (equals) { 734 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 735 .iterator(), iter2 = ((java.util.Collection) objLoaded) 736 .iterator(); 737 while (iter1.hasNext()) 738 equals = equals && iter1.next().equals(iter2.next()); 739 } 740 assertTrue(MSG_TEST_FAILED + objToSave, equals); 741 } catch (IOException e) { 742 fail("IOException serializing " + objToSave + " : " 743 + e.getMessage()); 744 } catch (ClassNotFoundException e) { 745 fail("ClassNotFoundException reading Object type : " 746 + e.getMessage()); 747 } catch (Error err) { 748 System.out.println("Error when obj = " + objToSave); 749 // err.printStackTrace(); 750 throw err; 751 } 752 753 } 754 755 public void test_writeObject_NumberFormat() { 756 // Test for method void 757 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat) 758 759 Object objToSave = null; 760 Object objLoaded = null; 761 762 try { 763 objToSave = null; 764 objToSave = new java.text.NumberFormat() { 765 long save = 107; 766 767 public StringBuffer format(double p1, StringBuffer p2, 768 java.text.FieldPosition p3) { 769 return new StringBuffer(); 770 } 771 772 public StringBuffer format(long p1, StringBuffer p2, 773 java.text.FieldPosition p3) { 774 if (p1 != 0) 775 save = p1; 776 return new StringBuffer(Long.toString(save)); 777 } 778 779 public Number parse(String p1, java.text.ParsePosition p2) { 780 return new Long(save); 781 } 782 783 public boolean equals(Object obj) { 784 if (!(obj instanceof java.text.NumberFormat)) 785 return false; 786 return save == ((Long) ((java.text.NumberFormat) obj) 787 .parse(null, null)).longValue(); 788 } 789 }; 790 791 ((java.text.NumberFormat) objToSave).format(63L, null, null); 792 if (DEBUG) 793 System.out.println("Obj = " + objToSave); 794 objLoaded = dumpAndReload(objToSave); 795 796 // Has to have worked 797 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 798 } catch (IOException e) { 799 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 800 } catch (ClassNotFoundException e) { 801 fail("ClassNotFoundException reading Object type: " 802 + e.getMessage()); 803 } catch (Error err) { 804 System.out.println("Error when obj = " + objToSave); 805 // err.printStackTrace(); 806 throw err; 807 } 808 809 } 810 811 public void test_writeObject_TimeZone() { 812 // Test for method void 813 // java.io.ObjectOutputStream.writeObject(java.util.TimeZone) 814 815 Object objToSave = null; 816 Object objLoaded = null; 817 818 try { 819 objToSave = null; 820 objToSave = new java.util.TimeZone() { 821 int save = 0; 822 823 public int getOffset(int p1, int p2, int p3, int p4, int p5, 824 int p6) { 825 return 0; 826 } 827 828 public int getRawOffset() { 829 return save; 830 } 831 832 public boolean inDaylightTime(java.util.Date p1) { 833 return false; 834 } 835 836 public void setRawOffset(int p1) { 837 save = p1; 838 } 839 840 public boolean useDaylightTime() { 841 return false; 842 } 843 844 public boolean equals(Object obj) { 845 if (obj instanceof TimeZone) 846 return save == ((TimeZone) obj).getRawOffset(); 847 return false; 848 } 849 }; 850 851 ((java.util.TimeZone) objToSave).setRawOffset(48); 852 if (DEBUG) 853 System.out.println("Obj = " + objToSave); 854 objLoaded = dumpAndReload(objToSave); 855 856 // Has to have worked 857 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 858 } catch (IOException e) { 859 fail("IOException serializing " + objToSave + " : " 860 + e.getMessage()); 861 } catch (ClassNotFoundException e) { 862 fail("ClassNotFoundException reading Object type : " 863 + e.getMessage()); 864 } catch (Error err) { 865 System.out.println("Error when obj = " + objToSave); 866 // err.printStackTrace(); 867 throw err; 868 } 869 870 } 871 872 public void test_writeObject_Double() { 873 // Test for method void 874 // java.io.ObjectOutputStream.writeObject(java.lang.Double) 875 876 Object objToSave = null; 877 Object objLoaded = null; 878 879 try { 880 objToSave = new java.lang.Double(1.23); 881 if (DEBUG) 882 System.out.println("Obj = " + objToSave); 883 objLoaded = dumpAndReload(objToSave); 884 885 // Has to have worked 886 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 887 } catch (IOException e) { 888 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 889 } catch (ClassNotFoundException e) { 890 fail("ClassNotFoundException reading Object type: " 891 + e.getMessage()); 892 } catch (Error err) { 893 System.out.println("Error when obj = " + objToSave); 894 // err.printStackTrace(); 895 throw err; 896 } 897 898 } 899 900 public void test_writeObject_Number() { 901 // Test for method void 902 // java.io.ObjectOutputStream.writeObject(java.lang.Number) 903 904 Object objToSave = null; 905 Object objLoaded = null; 906 907 try { 908 objToSave = null; 909 objToSave = new Number() { 910 int numCalls = 0; 911 912 public double doubleValue() { 913 return ++numCalls; 914 } 915 916 public float floatValue() { 917 return ++numCalls; 918 } 919 920 public int intValue() { 921 return numCalls; 922 } 923 924 public long longValue() { 925 return ++numCalls; 926 } 927 928 public boolean equals(Object obj) { 929 if (!(obj instanceof java.lang.Number)) 930 return false; 931 return intValue() == ((Number) obj).intValue(); 932 } 933 }; 934 ((java.lang.Number) objToSave).doubleValue(); 935 ((java.lang.Number) objToSave).floatValue(); 936 if (DEBUG) 937 System.out.println("Obj = " + objToSave); 938 objLoaded = dumpAndReload(objToSave); 939 940 // Has to have worked 941 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 942 } catch (IOException e) { 943 fail("IOException serializing " + objToSave + " : " 944 + e.getMessage()); 945 } catch (ClassNotFoundException e) { 946 fail("ClassNotFoundException reading Object type : " 947 + e.getMessage()); 948 } catch (Error err) { 949 System.out.println("Error when obj = " + objToSave); 950 // err.printStackTrace(); 951 throw err; 952 } 953 954 } 955 956 public void test_writeObject_Collections_ReverseComparator() { 957 // Test for method void 958 // java.io.ObjectOutputStream.writeObject(java.util.Collections.ReverseComparator) 959 960 Object objToSave = null; 961 Object objLoaded = null; 962 963 try { 964 objToSave = java.util.Collections.reverseOrder(); 965 if (DEBUG) 966 System.out.println("Obj = " + objToSave); 967 objLoaded = dumpAndReload(objToSave); 968 969 // Has to have worked 970 boolean equals; 971 equals = ((Comparator) objToSave).compare("Hello", "Jello") == ((Comparator) objLoaded) 972 .compare("Hello", "Jello"); 973 assertTrue(MSG_TEST_FAILED + objToSave, equals); 974 } catch (IOException e) { 975 fail("IOException serializing " + objToSave + " : " 976 + e.getMessage()); 977 } catch (ClassNotFoundException e) { 978 fail("ClassNotFoundException reading Object type : " 979 + e.getMessage()); 980 } catch (Error err) { 981 System.out.println("Error when obj = " + objToSave); 982 // err.printStackTrace(); 983 throw err; 984 } 985 986 } 987 988 public void test_writeObject_DateFormatSymbols() { 989 // Test for method void 990 // java.io.ObjectOutputStream.writeObject(java.text.DateFormatSymbols) 991 992 Object objToSave = null; 993 Object objLoaded = null; 994 995 try { 996 objToSave = new java.text.DateFormatSymbols(Locale.CHINESE); 997 ((java.text.DateFormatSymbols) objToSave) 998 .setZoneStrings(new String[][] { { "a", "b", "c", "d" }, 999 { "e", "f", "g", "h" } }); 1000 if (DEBUG) 1001 System.out.println("Obj = " + objToSave); 1002 objLoaded = dumpAndReload(objToSave); 1003 1004 // Has to have worked 1005 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1006 } catch (IOException e) { 1007 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1008 } catch (ClassNotFoundException e) { 1009 fail("ClassNotFoundException reading Object type: " 1010 + e.getMessage()); 1011 } catch (Error err) { 1012 System.out.println("Error when obj = " + objToSave); 1013 // err.printStackTrace(); 1014 throw err; 1015 } 1016 1017 } 1018 1019 public void test_writeObject_Collections_EmptyList() { 1020 // Test for method void 1021 // java.io.ObjectOutputStream.writeObject(java.util.Collections.EmptyList) 1022 1023 Object objToSave = null; 1024 Object objLoaded = null; 1025 1026 try { 1027 objToSave = java.util.Collections.EMPTY_LIST; 1028 if (DEBUG) 1029 System.out.println("Obj = " + objToSave); 1030 objLoaded = dumpAndReload(objToSave); 1031 1032 // Has to have worked 1033 boolean equals; 1034 equals = objToSave.equals(objLoaded); 1035 if (equals) 1036 equals = ((List) objLoaded).size() == 0; 1037 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1038 } catch (IOException e) { 1039 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1040 } catch (ClassNotFoundException e) { 1041 fail("ClassNotFoundException reading Object type: " 1042 + e.getMessage()); 1043 } catch (Error err) { 1044 System.out.println("Error when obj = " + objToSave); 1045 // err.printStackTrace(); 1046 throw err; 1047 } 1048 1049 } 1050 1051 public void test_writeObject_Boolean() { 1052 // Test for method void 1053 // java.io.ObjectOutputStream.writeObject(java.lang.Boolean) 1054 1055 Object objToSave = null; 1056 Object objLoaded = null; 1057 1058 try { 1059 objToSave = new java.lang.Boolean(true); 1060 if (DEBUG) 1061 System.out.println("Obj = " + objToSave); 1062 objLoaded = dumpAndReload(objToSave); 1063 1064 // Has to have worked 1065 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1066 } catch (IOException e) { 1067 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1068 } catch (ClassNotFoundException e) { 1069 fail("ClassNotFoundException reading Object type: " 1070 + e.getMessage()); 1071 } catch (Error err) { 1072 System.out.println("Error when obj = " + objToSave); 1073 // err.printStackTrace(); 1074 throw err; 1075 } 1076 1077 } 1078 1079 public void test_writeObject_Collections_SingletonSet() { 1080 // Test for method void 1081 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1082 1083 Object objToSave = null; 1084 Object objLoaded = null; 1085 1086 try { 1087 objToSave = java.util.Collections.singleton(new Byte((byte) 107)); 1088 if (DEBUG) 1089 System.out.println("Obj = " + objToSave); 1090 objLoaded = dumpAndReload(objToSave); 1091 1092 // Has to have worked 1093 boolean equals; 1094 java.util.Iterator iter = ((Set) objLoaded).iterator(); 1095 equals = iter.hasNext(); 1096 if (equals) 1097 equals = iter.next().equals(new Byte((byte) 107)); 1098 if (equals) 1099 equals = !iter.hasNext(); 1100 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1101 } catch (IOException e) { 1102 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1103 } catch (ClassNotFoundException e) { 1104 fail("ClassNotFoundException reading Object type: " 1105 + e.getMessage()); 1106 } catch (Error err) { 1107 System.out.println("Error when obj = " + objToSave); 1108 // err.printStackTrace(); 1109 throw err; 1110 } 1111 1112 } 1113 1114 public void test_writeObject_Collections_SingletonList() { 1115 // Test for method void 1116 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1117 1118 Object objToSave = null; 1119 Object objLoaded = null; 1120 1121 try { 1122 objToSave = java.util.Collections 1123 .singletonList(new Byte((byte) 107)); 1124 if (DEBUG) 1125 System.out.println("Obj = " + objToSave); 1126 objLoaded = dumpAndReload(objToSave); 1127 1128 // Has to have worked 1129 boolean equals; 1130 java.util.Iterator iter = ((List) objLoaded).iterator(); 1131 equals = objLoaded.equals(objToSave) && iter.hasNext() 1132 && iter.next().equals(new Byte((byte) 107)) 1133 && !iter.hasNext(); 1134 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1135 } catch (IOException e) { 1136 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1137 } catch (ClassNotFoundException e) { 1138 fail("ClassNotFoundException reading Object type: " 1139 + e.getMessage()); 1140 } catch (Error err) { 1141 System.out.println("Error when obj = " + objToSave); 1142 // err.printStackTrace(); 1143 throw err; 1144 } 1145 1146 } 1147 1148 public void test_writeObject_Collections_SingletonMap() { 1149 // Test for method void 1150 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SingletonSet) 1151 1152 Object objToSave = null; 1153 Object objLoaded = null; 1154 1155 try { 1156 objToSave = java.util.Collections.singletonMap("key", new Byte( 1157 (byte) 107)); 1158 if (DEBUG) 1159 System.out.println("Obj = " + objToSave); 1160 objLoaded = dumpAndReload(objToSave); 1161 1162 // Has to have worked 1163 boolean equals; 1164 java.util.Iterator iter = ((Map) objLoaded).entrySet().iterator(); 1165 equals = objLoaded.equals(objToSave) && iter.hasNext(); 1166 Map.Entry entry = (Map.Entry) iter.next(); 1167 equals = equals && entry.getKey().equals("key") 1168 && entry.getValue().equals(new Byte((byte) 107)) 1169 && !iter.hasNext(); 1170 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1171 } catch (IOException e) { 1172 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1173 } catch (ClassNotFoundException e) { 1174 fail("ClassNotFoundException reading Object type: " 1175 + e.getMessage()); 1176 } catch (Error err) { 1177 System.out.println("Error when obj = " + objToSave); 1178 // err.printStackTrace(); 1179 throw err; 1180 } 1181 1182 } 1183 1184 public void test_writeObject_SecureRandom() { 1185 // Test for method void 1186 // java.io.ObjectOutputStream.writeObject(java.security.SecureRandom) 1187 1188 Object objToSave = null; 1189 Object objLoaded = null; 1190 1191 try { 1192 objToSave = new java.security.SecureRandom(); 1193 if (DEBUG) 1194 System.out.println("Obj = " + objToSave); 1195 objLoaded = dumpAndReload(objToSave); 1196 1197 // Has to have worked 1198 boolean equals; 1199 equals = true; // assume fine because of the nature of the class, 1200 // it is difficult to determine if they are the same 1201 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1202 } catch (IOException e) { 1203 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1204 } catch (ClassNotFoundException e) { 1205 fail("ClassNotFoundException reading Object type: " 1206 + e.getMessage()); 1207 } catch (Error err) { 1208 System.out.println("Error when obj = " + objToSave); 1209 // err.printStackTrace(); 1210 throw err; 1211 } 1212 1213 } 1214 1215 public void test_writeObject_InetAddress() { 1216 // Test for method void 1217 // java.io.ObjectOutputStream.writeObject(java.net.InetAddress) 1218 1219 Object objToSave = null; 1220 Object objLoaded = null; 1221 1222 try { 1223 objToSave = java.net.InetAddress.getByName("127.0.0.1"); 1224 if (DEBUG) 1225 System.out.println("Obj = " + objToSave); 1226 objLoaded = dumpAndReload(objToSave); 1227 1228 // Has to have worked 1229 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1230 } catch (IOException e) { 1231 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1232 } catch (ClassNotFoundException e) { 1233 fail("ClassNotFoundException reading Object type: " 1234 + e.getMessage()); 1235 } catch (Error err) { 1236 System.out.println("Error when obj = " + objToSave); 1237 // err.printStackTrace(); 1238 throw err; 1239 } 1240 1241 } 1242 1243 public void test_writeObject_Inet6Address() { 1244 // Test for method void 1245 // java.io.ObjectOutputStream.writeObject(java.net.Inet6Address) 1246 1247 Object objToSave = null; 1248 Object objLoaded = null; 1249 1250 try { 1251 objToSave = java.net.Inet6Address.getByName("fe80::20d:60ff:fe24:7410"); 1252 if (DEBUG) 1253 System.out.println("Obj = " + objToSave); 1254 objLoaded = dumpAndReload(objToSave); 1255 1256 // Has to have worked 1257 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1258 1259 } catch (IOException e) { 1260 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1261 } catch (ClassNotFoundException e) { 1262 fail("ClassNotFoundException reading Object type: " 1263 + e.getMessage()); 1264 } catch (Error err) { 1265 System.out.println("Error when obj = " + objToSave); 1266 // err.printStackTrace(); 1267 throw err; 1268 } 1269 1270 } 1271 1272 public void test_writeObject_Date() { 1273 // Test for method void 1274 // java.io.ObjectOutputStream.writeObject(java.util.Date) 1275 1276 Object objToSave = null; 1277 Object objLoaded = null; 1278 1279 try { 1280 // Thu Feb 01 01:01:01 EST 2001 1281 objToSave = new java.util.Date(981007261000L); 1282 if (DEBUG) 1283 System.out.println("Obj = " + objToSave); 1284 objLoaded = dumpAndReload(objToSave); 1285 1286 // Has to have worked 1287 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1288 } catch (IOException e) { 1289 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1290 } catch (ClassNotFoundException e) { 1291 fail("ClassNotFoundException reading Object type: " 1292 + e.getMessage()); 1293 } catch (Error err) { 1294 System.out.println("Error when obj = " + objToSave); 1295 // err.printStackTrace(); 1296 throw err; 1297 } 1298 1299 } 1300 1301 public void test_writeObject_Float() { 1302 // Test for method void 1303 // java.io.ObjectOutputStream.writeObject(java.lang.Float) 1304 1305 Object objToSave = null; 1306 Object objLoaded = null; 1307 1308 try { 1309 objToSave = new java.lang.Float(1.23f); 1310 if (DEBUG) 1311 System.out.println("Obj = " + objToSave); 1312 objLoaded = dumpAndReload(objToSave); 1313 1314 // Has to have worked 1315 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1316 } catch (IOException e) { 1317 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1318 } catch (ClassNotFoundException e) { 1319 fail("ClassNotFoundException reading Object type: " 1320 + e.getMessage()); 1321 } catch (Error err) { 1322 System.out.println("Error when obj = " + objToSave); 1323 // err.printStackTrace(); 1324 throw err; 1325 } 1326 1327 } 1328 1329 public void test_writeObject_Stack() { 1330 // Test for method void 1331 // java.io.ObjectOutputStream.writeObject(java.util.Stack) 1332 1333 Object objToSave = null; 1334 Object objLoaded = null; 1335 1336 try { 1337 objToSave = new java.util.Stack(); 1338 ((Stack) objToSave).push("String 1"); 1339 ((Stack) objToSave).push("String 2"); 1340 if (DEBUG) 1341 System.out.println("Obj = " + objToSave); 1342 objLoaded = dumpAndReload(objToSave); 1343 1344 // Has to have worked 1345 boolean equals; 1346 equals = true; 1347 while (!((java.util.Stack) objToSave).empty() && equals) { 1348 if (!((java.util.Stack) objLoaded).empty()) 1349 equals = ((java.util.Stack) objToSave).pop().equals( 1350 ((java.util.Stack) objLoaded).pop()); 1351 else 1352 equals = false; 1353 } 1354 1355 if (equals) 1356 equals = ((java.util.Stack) objLoaded).empty(); 1357 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1358 } catch (IOException e) { 1359 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1360 } catch (ClassNotFoundException e) { 1361 fail("ClassNotFoundException reading Object type: " 1362 + e.getMessage()); 1363 } catch (Error err) { 1364 System.out.println("Error when obj = " + objToSave); 1365 // err.printStackTrace(); 1366 throw err; 1367 } 1368 1369 } 1370 1371 public void test_writeObject_DecimalFormatSymbols() { 1372 // Test for method void 1373 // java.io.ObjectOutputStream.writeObject(java.text.DecimalFormatSymbols) 1374 1375 Object objToSave = null; 1376 Object objLoaded = null; 1377 1378 try { 1379 objToSave = new java.text.DecimalFormatSymbols(Locale.CHINESE); 1380 if (DEBUG) 1381 System.out.println("Obj = " + objToSave); 1382 objLoaded = dumpAndReload(objToSave); 1383 1384 // Has to have worked 1385 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1386 } catch (IOException e) { 1387 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1388 } catch (ClassNotFoundException e) { 1389 fail("ClassNotFoundException reading Object type: " 1390 + e.getMessage()); 1391 } catch (Error err) { 1392 System.out.println("Error when obj = " + objToSave); 1393 // err.printStackTrace(); 1394 throw err; 1395 } 1396 1397 } 1398 1399 public void test_writeObject_AttributedCharacterIterator_Attribute() { 1400 // Test for method void 1401 // java.io.ObjectOutputStream.writeObject(java.text.AttributedCharacterIterator.Attribute) 1402 1403 Object objToSave = null; 1404 Object objLoaded = null; 1405 1406 try { 1407 objToSave = java.text.AttributedCharacterIterator.Attribute.LANGUAGE; 1408 if (DEBUG) 1409 System.out.println("Obj = " + objToSave); 1410 objLoaded = dumpAndReload(objToSave); 1411 1412 // Has to have worked 1413 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1414 } catch (IOException e) { 1415 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1416 } catch (ClassNotFoundException e) { 1417 fail("ClassNotFoundException reading Object type: " 1418 + e.getMessage()); 1419 } catch (Error err) { 1420 System.out.println("Error when obj = " + objToSave); 1421 // err.printStackTrace(); 1422 throw err; 1423 } 1424 } 1425 1426 public void test_writeObject_Long() { 1427 // Test for method void 1428 // java.io.ObjectOutputStream.writeObject(java.lang.Long) 1429 1430 Object objToSave = null; 1431 Object objLoaded = null; 1432 1433 try { 1434 objToSave = new java.lang.Long(107L); 1435 if (DEBUG) 1436 System.out.println("Obj = " + objToSave); 1437 objLoaded = dumpAndReload(objToSave); 1438 1439 // Has to have worked 1440 assertTrue(MSG_TEST_FAILED + objToSave, objToSave.equals(objLoaded)); 1441 } catch (IOException e) { 1442 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1443 } catch (ClassNotFoundException e) { 1444 fail("ClassNotFoundException reading Object type: " 1445 + e.getMessage()); 1446 } catch (Error err) { 1447 System.out.println("Error when obj = " + objToSave); 1448 // err.printStackTrace(); 1449 throw err; 1450 } 1451 1452 } 1453 1454 public void test_writeObject_Collections_SynchronizedCollection() { 1455 // Test for method void 1456 // java.io.ObjectOutputStream.writeObject(java.util.Collections.SynchronizedCollection) 1457 1458 Object objToSave = null; 1459 Object objLoaded = null; 1460 1461 try { 1462 objToSave = java.util.Collections.synchronizedCollection(SET); 1463 if (DEBUG) 1464 System.out.println("Obj = " + objToSave); 1465 objLoaded = dumpAndReload(objToSave); 1466 1467 // Has to have worked 1468 boolean equals; 1469 equals = ((java.util.Collection) objToSave).size() == ((java.util.Collection) objLoaded) 1470 .size(); 1471 if (equals) { 1472 java.util.Iterator iter1 = ((java.util.Collection) objToSave) 1473 .iterator(), iter2 = ((java.util.Collection) objLoaded) 1474 .iterator(); 1475 while (iter1.hasNext()) 1476 equals = equals && iter1.next().equals(iter2.next()); 1477 } 1478 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1479 } catch (IOException e) { 1480 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1481 } catch (ClassNotFoundException e) { 1482 fail("ClassNotFoundException reading Object type: " 1483 + e.getMessage()); 1484 } catch (Error err) { 1485 System.out.println("Error when obj = " + objToSave); 1486 // err.printStackTrace(); 1487 throw err; 1488 } 1489 1490 } 1491 1492 public void test_writeObject_Random() { 1493 // Test for method void 1494 // java.io.ObjectOutputStream.writeObject(java.util.Random) 1495 1496 Object objToSave = null; 1497 Object objLoaded = null; 1498 1499 try { 1500 objToSave = new java.util.Random(107L); 1501 if (DEBUG) 1502 System.out.println("Obj = " + objToSave); 1503 objLoaded = dumpAndReload(objToSave); 1504 1505 // Has to have worked 1506 boolean equals; 1507 equals = ((java.util.Random) objToSave).nextInt() == ((java.util.Random) objLoaded) 1508 .nextInt(); 1509 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1510 } catch (IOException e) { 1511 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1512 } catch (ClassNotFoundException e) { 1513 fail("ClassNotFoundException reading Object type: " 1514 + e.getMessage()); 1515 } catch (Error err) { 1516 System.out.println("Error when obj = " + objToSave); 1517 // err.printStackTrace(); 1518 throw err; 1519 } 1520 1521 } 1522 1523 public void test_writeObject_GuardedObject() { 1524 // Test for method void 1525 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 1526 1527 Object objToSave = null; 1528 Object objLoaded = null; 1529 1530 try { 1531 objToSave = new java.security.GuardedObject("Test Object", 1532 new GuardImplementation()); 1533 if (DEBUG) 1534 System.out.println("Obj = " + objToSave); 1535 objLoaded = dumpAndReload(objToSave); 1536 1537 // Has to have worked 1538 boolean equals; 1539 equals = ((java.security.GuardedObject) objToSave).getObject() 1540 .equals( 1541 ((java.security.GuardedObject) objLoaded) 1542 .getObject()); 1543 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1544 } catch (IOException e) { 1545 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1546 } catch (ClassNotFoundException e) { 1547 fail("ClassNotFoundException reading Object type: " 1548 + e.getMessage()); 1549 } catch (Error err) { 1550 System.out.println("Error when obj = " + objToSave); 1551 // err.printStackTrace(); 1552 throw err; 1553 } 1554 1555 } 1556 1557 // TODO : Reintroduce when we have a working security implementation 1558 // public void test_writeObject_KeyPair() { 1559 // // Test for method void 1560 // // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 1561 // 1562 // Object objToSave = null; 1563 // Object objLoaded = null; 1564 // 1565 // try { 1566 // objToSave = new java.security.KeyPair(null, null); 1567 // if (DEBUG) 1568 // System.out.println("Obj = " + objToSave); 1569 // objLoaded = dumpAndReload(objToSave); 1570 // 1571 // // Has to have worked 1572 // boolean equals; 1573 // equals = true; 1574 // assertTrue(MSG_TEST_FAILED + objToSave, equals); 1575 // } catch (IOException e) { 1576 // fail("IOException serializing " + objToSave + " : " 1577 // + e.getMessage()); 1578 // } catch (ClassNotFoundException e) { 1579 // fail("ClassNotFoundException reading Object type : " + e.getMessage()); 1580 // } catch (Error err) { 1581 // System.out.println("Error when obj = " + objToSave); 1582 // // err.printStackTrace(); 1583 // throw err; 1584 // } 1585 // } 1586 1587 static class MyInvocationHandler implements InvocationHandler, Serializable { 1588 public Object invoke(Object proxy, Method method, Object[] args) 1589 throws Throwable { 1590 if (method.getName().equals("equals")) 1591 return new Boolean(proxy == args[0]); 1592 if (method.getName().equals("array")) 1593 return new int[] { (int) ((long[]) args[0])[1], -1 }; 1594 if (method.getName().equals("string")) { 1595 if ("error".equals(args[0])) 1596 throw new ArrayStoreException(); 1597 if ("any".equals(args[0])) 1598 throw new IllegalAccessException(); 1599 } 1600 return null; 1601 } 1602 } 1603 1604 public void test_writeObject_Proxy() { 1605 // Test for method void 1606 // java.io.ObjectOutputStream.writeObject(java.security.GuardedObject) 1607 1608 Object objToSave = null; 1609 Object objLoaded = null; 1610 1611 try { 1612 objToSave = Proxy.getProxyClass(Support_Proxy_I1.class 1613 .getClassLoader(), new Class[] { Support_Proxy_I1.class }); 1614 if (DEBUG) 1615 System.out.println("Obj = " + objToSave); 1616 objLoaded = dumpAndReload(objToSave); 1617 1618 assertTrue(MSG_TEST_FAILED + "not a proxy class", Proxy 1619 .isProxyClass((Class) objLoaded)); 1620 Class[] interfaces = ((Class) objLoaded).getInterfaces(); 1621 assertTrue(MSG_TEST_FAILED + "wrong interfaces length", 1622 interfaces.length == 1); 1623 assertTrue(MSG_TEST_FAILED + "wrong interface", 1624 interfaces[0] == Support_Proxy_I1.class); 1625 1626 InvocationHandler handler = new MyInvocationHandler(); 1627 objToSave = Proxy.newProxyInstance(Support_Proxy_I1.class 1628 .getClassLoader(), new Class[] { Support_Proxy_I1.class }, 1629 handler); 1630 if (DEBUG) 1631 System.out.println("Obj = " + objToSave); 1632 objLoaded = dumpAndReload(objToSave); 1633 1634 boolean equals = Proxy.getInvocationHandler(objLoaded).getClass() == MyInvocationHandler.class; 1635 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1636 1637 } catch (IOException e) { 1638 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1639 } catch (ClassNotFoundException e) { 1640 fail("ClassNotFoundException reading Object type: " 1641 + e.getMessage()); 1642 } catch (Error err) { 1643 System.out.println("Error when obj = " + objToSave); 1644 // err.printStackTrace(); 1645 throw err; 1646 } 1647 } 1648 1649 public void test_writeObject_URI() { 1650 // Test for method void 1651 // java.io.ObjectOutputStream.writeObject(java.net.URI) 1652 1653 Object objToSave = null; 1654 Object objLoaded = null; 1655 1656 try { 1657 try { 1658 objToSave = new URI[] { 1659 // single arg constructor 1660 new URI( 1661 "http://user%60%20info@host/a%20path?qu%60%20ery#fr%5E%20ag"), 1662 // escaped octets for illegal chars 1663 new URI( 1664 "http://user%C3%9F%C2%A3info@host:80/a%E2%82%ACpath?qu%C2%A9%C2%AEery#fr%C3%A4%C3%A8g"), 1665 // escaped octets for unicode chars 1666 new URI( 1667 "ascheme://user\u00DF\u00A3info@host:0/a\u20ACpath?qu\u00A9\u00AEery#fr\u00E4\u00E8g"), 1668 // multiple arg constructors 1669 new URI("http", "user%60%20info", "host", 80, 1670 "/a%20path", "qu%60%20ery", "fr%5E%20ag"), 1671 // escaped octets for illegal 1672 new URI("http", "user%C3%9F%C2%A3info", "host", -1, 1673 "/a%E2%82%ACpath", "qu%C2%A9%C2%AEery", 1674 "fr%C3%A4%C3%A8g"), 1675 // escaped octets for unicode 1676 new URI("ascheme", "user\u00DF\u00A3info", "host", 80, 1677 "/a\u20ACpath", "qu\u00A9\u00AEery", 1678 "fr\u00E4\u00E8g"), 1679 new URI("http", "user` info", "host", 81, "/a path", 1680 "qu` ery", "fr^ ag"), // illegal chars 1681 new URI("http", "user%info", "host", 0, "/a%path", 1682 "que%ry", "f%rag"), 1683 // % as illegal char, not escaped octet urls with 1684 // undefined components 1685 new URI("mailto", "user@domain.com", null), 1686 // no host, path, query or fragment 1687 new URI("../adirectory/file.html#"), 1688 // relative path with empty fragment; 1689 new URI("news", "comp.infosystems.www.servers.unix", 1690 null), 1691 new URI(null, null, null, "fragment"), 1692 // only fragment 1693 new URI("telnet://server.org"), // only host 1694 new URI("http://reg:istry?query"), 1695 // malformed hostname, therefore registry-based, 1696 // with query 1697 new URI("file:///c:/temp/calculate.pl?") 1698 // empty authority, non empty path, empty query 1699 }; 1700 } catch (URISyntaxException e) { 1701 fail("Unexpected Exception:" + e); 1702 } 1703 if (DEBUG) 1704 System.out.println("Obj = " + objToSave); 1705 objLoaded = dumpAndReload(objToSave); 1706 1707 // Has to have worked 1708 assertTrue(MSG_TEST_FAILED + objToSave, Arrays.equals( 1709 (URI[]) objToSave, (URI[]) objLoaded)); 1710 } catch (IOException e) { 1711 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1712 } catch (ClassNotFoundException e) { 1713 fail("ClassNotFoundException reading Object type: " 1714 + e.getMessage()); 1715 } catch (Error err) { 1716 System.out.println("Error when obj = " + objToSave); 1717 // err.printStackTrace(); 1718 throw err; 1719 } 1720 } 1721 1722 public void test_writeObject_URISyntaxException() { 1723 // Test for method void 1724 // java.io.ObjectOutputStream.writeObject(java.net.URISyntaxException) 1725 1726 URISyntaxException objToSave = null; 1727 URISyntaxException objLoaded = null; 1728 1729 try { 1730 objToSave = new URISyntaxException("str", "problem", 4); 1731 if (DEBUG) 1732 System.out.println("Obj = " + objToSave); 1733 objLoaded = (URISyntaxException) dumpAndReload(objToSave); 1734 1735 boolean equals = objToSave.getMessage().equals( 1736 objLoaded.getMessage()) 1737 && objToSave.getInput().equals(objLoaded.getInput()) 1738 && objToSave.getIndex() == objLoaded.getIndex() 1739 && objToSave.getReason().equals(objLoaded.getReason()); 1740 1741 // Has to have worked 1742 assertTrue(MSG_TEST_FAILED + objToSave, equals); 1743 } catch (IOException e) { 1744 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1745 } catch (ClassNotFoundException e) { 1746 fail("ClassNotFoundException reading Object type: " 1747 + e.getMessage()); 1748 } catch (Error err) { 1749 System.out.println("Error when obj = " + objToSave); 1750 // err.printStackTrace(); 1751 throw err; 1752 } 1753 1754 } 1755 1756 public void test_writeObject_Currency() { 1757 // Test for method void 1758 // java.io.ObjectOutputStream.writeObject(java.util.Currency) 1759 1760 Object objToSave = null; 1761 Object objLoaded = null; 1762 1763 try { 1764 objToSave = java.util.Currency.getInstance("AMD"); 1765 if (DEBUG) 1766 System.out.println("Obj = " + objToSave); 1767 objLoaded = dumpAndReload(objToSave); 1768 1769 // Has to have worked 1770 // we need same instance for the same currency code 1771 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objToSave); 1772 } catch (IOException e) { 1773 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1774 } catch (ClassNotFoundException e) { 1775 fail("ClassNotFoundException reading Object type: " 1776 + e.getMessage()); 1777 } catch (Error err) { 1778 System.out.println("Error when obj = " + objToSave); 1779 // err.printStackTrace(); 1780 throw err; 1781 } 1782 } 1783 1784 public void test_writeObject_DateFormat_Field() { 1785 // Test for method void 1786 // java.io.ObjectOutputStream.writeObject(java.text.DateFormat.Field) 1787 1788 DateFormat.Field[] objToSave = null; 1789 DateFormat.Field[] objLoaded = null; 1790 1791 try { 1792 objToSave = new DateFormat.Field[] { DateFormat.Field.AM_PM, 1793 DateFormat.Field.DAY_OF_MONTH, DateFormat.Field.ERA, 1794 DateFormat.Field.HOUR0, DateFormat.Field.HOUR1, 1795 DateFormat.Field.HOUR_OF_DAY0, 1796 DateFormat.Field.HOUR_OF_DAY1, DateFormat.Field.TIME_ZONE, 1797 DateFormat.Field.YEAR, 1798 DateFormat.Field.DAY_OF_WEEK_IN_MONTH }; 1799 if (DEBUG) 1800 System.out.println("Obj = " + objToSave); 1801 1802 objLoaded = (DateFormat.Field[]) dumpAndReload(objToSave); 1803 1804 // Has to have worked 1805 // we need same instances for the same field names 1806 for (int i = 0; i < objToSave.length; i++) { 1807 assertTrue(MSG_TEST_FAILED + objToSave[i], 1808 objToSave[i] == objLoaded[i]); 1809 } 1810 } catch (IOException e) { 1811 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1812 } catch (ClassNotFoundException e) { 1813 fail("ClassNotFoundException reading Object type: " 1814 + e.getMessage()); 1815 } catch (Error err) { 1816 System.out.println("Error when obj = " + objToSave); 1817 // err.printStackTrace(); 1818 throw err; 1819 } 1820 } 1821 1822 public void test_writeObject_NumberFormat_Field() { 1823 // Test for method void 1824 // java.io.ObjectOutputStream.writeObject(java.text.NumberFormat.Field) 1825 1826 NumberFormat.Field[] objToSave = null; 1827 NumberFormat.Field[] objLoaded = null; 1828 1829 try { 1830 objToSave = new NumberFormat.Field[] { NumberFormat.Field.CURRENCY, 1831 NumberFormat.Field.DECIMAL_SEPARATOR, 1832 NumberFormat.Field.EXPONENT, 1833 NumberFormat.Field.EXPONENT_SIGN, 1834 NumberFormat.Field.EXPONENT_SYMBOL, 1835 NumberFormat.Field.FRACTION, 1836 NumberFormat.Field.GROUPING_SEPARATOR, 1837 NumberFormat.Field.INTEGER, NumberFormat.Field.PERCENT, 1838 NumberFormat.Field.PERMILLE, NumberFormat.Field.SIGN }; 1839 if (DEBUG) 1840 System.out.println("Obj = " + objToSave); 1841 1842 objLoaded = (NumberFormat.Field[]) dumpAndReload(objToSave); 1843 1844 // Has to have worked 1845 // we need same instances for the same field names 1846 for (int i = 0; i < objToSave.length; i++) { 1847 assertTrue(MSG_TEST_FAILED + objToSave[i], 1848 objToSave[i] == objLoaded[i]); 1849 } 1850 } catch (IOException e) { 1851 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1852 } catch (ClassNotFoundException e) { 1853 fail("ClassNotFoundException reading Object type: " 1854 + e.getMessage()); 1855 } catch (Error err) { 1856 System.out.println("Error when obj = " + objToSave); 1857 // err.printStackTrace(); 1858 throw err; 1859 } 1860 } 1861 1862 public void test_writeObject_MessageFormat_Field() { 1863 // Test for method void 1864 // java.io.ObjectOutputStream.writeObject(java.text.MessageFormat.Field) 1865 1866 Object objToSave = null; 1867 Object objLoaded = null; 1868 1869 try { 1870 objToSave = MessageFormat.Field.ARGUMENT; 1871 if (DEBUG) 1872 System.out.println("Obj = " + objToSave); 1873 1874 objLoaded = dumpAndReload(objToSave); 1875 1876 // Has to have worked 1877 // we need same instance for the same field name 1878 assertTrue(MSG_TEST_FAILED + objToSave, objToSave == objLoaded); 1879 } catch (IOException e) { 1880 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1881 } catch (ClassNotFoundException e) { 1882 fail("ClassNotFoundException reading Object type: " 1883 + e.getMessage()); 1884 } catch (Error err) { 1885 System.out.println("Error when obj = " + objToSave); 1886 // err.printStackTrace(); 1887 throw err; 1888 } 1889 } 1890 1891 public void test_writeObject_LinkedHashMap() { 1892 // Test for method void 1893 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1894 1895 Object objToSave = null; 1896 Object objLoaded; 1897 1898 try { 1899 objToSave = LINKEDMAP; 1900 if (DEBUG) 1901 System.out.println("Obj = " + objToSave); 1902 objLoaded = dumpAndReload(objToSave); 1903 // Has to have worked 1904 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDMAP.equals(objLoaded)); 1905 1906 Map mapLoaded = (Map) objLoaded; 1907 Iterator loadedIterator = mapLoaded.keySet().iterator(); 1908 Iterator iterator = LINKEDMAP.keySet().iterator(); 1909 while (loadedIterator.hasNext()) { 1910 assertTrue("invalid iterator order", loadedIterator.next() 1911 .equals(iterator.next())); 1912 } 1913 assertTrue("invalid iterator size", !iterator.hasNext()); 1914 1915 loadedIterator = mapLoaded.entrySet().iterator(); 1916 iterator = LINKEDMAP.entrySet().iterator(); 1917 while (loadedIterator.hasNext()) { 1918 assertTrue("invalid entry set iterator order", loadedIterator 1919 .next().equals(iterator.next())); 1920 } 1921 assertTrue("invalid entry set iterator size", !iterator.hasNext()); 1922 1923 } catch (IOException e) { 1924 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1925 } catch (ClassNotFoundException e) { 1926 fail("ClassNotFoundException reading Object type: " 1927 + e.getMessage()); 1928 } catch (Error err) { 1929 System.out.println("Error when obj = " + objToSave); 1930 // err.printStackTrace(); 1931 throw err; 1932 } 1933 } 1934 1935 public void test_writeObject_LinkedHashSet() { 1936 // Test for method void 1937 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1938 1939 Object objToSave = null; 1940 Object objLoaded; 1941 1942 try { 1943 objToSave = LINKEDSET; 1944 if (DEBUG) 1945 System.out.println("Obj = " + objToSave); 1946 objLoaded = dumpAndReload(objToSave); 1947 // Has to have worked 1948 assertTrue(MSG_TEST_FAILED + objToSave, LINKEDSET.equals(objLoaded)); 1949 1950 } catch (IOException e) { 1951 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1952 } catch (ClassNotFoundException e) { 1953 fail("ClassNotFoundException reading Object type: " 1954 + e.getMessage()); 1955 } catch (Error err) { 1956 System.out.println("Error when obj = " + objToSave); 1957 // err.printStackTrace(); 1958 throw err; 1959 } 1960 } 1961 1962 public void test_writeObject_IdentityHashMap() { 1963 // Test for method void 1964 // java.io.ObjectOutputStream.writeObject(java.lang.Object) 1965 1966 IdentityHashMap objToSave = null; 1967 IdentityHashMap objLoaded; 1968 1969 try { 1970 objToSave = IDENTITYMAP; 1971 if (DEBUG) 1972 System.out.println("Obj = " + objToSave); 1973 objLoaded = (IdentityHashMap) dumpAndReload(objToSave); 1974 // Has to have worked 1975 1976 // a serialized identity hash map will not be equal to its original 1977 // because it is an "identity" mapping, 1978 // so we simply check for the usual meaning of equality 1979 1980 assertEquals( 1981 "Loaded IdentityHashMap is not of the same size as the saved one.", 1982 objToSave.size(), objLoaded.size()); 1983 HashMap duplicateSaved = new HashMap(); 1984 duplicateSaved.putAll(objToSave); 1985 HashMap duplicateLoaded = new HashMap(); 1986 duplicateLoaded.putAll(objLoaded); 1987 assertTrue(MSG_TEST_FAILED + duplicateSaved, duplicateSaved 1988 .equals(duplicateLoaded)); 1989 } catch (IOException e) { 1990 fail("Exception serializing " + objToSave + " : " + e.getMessage()); 1991 } catch (ClassNotFoundException e) { 1992 fail("ClassNotFoundException reading Object type: " 1993 + e.getMessage()); 1994 } catch (Error err) { 1995 System.out.println("Error when obj = " + objToSave); 1996 // err.printStackTrace(); 1997 throw err; 1998 } 1999 } 2000} 2001