628 String bitPatterns[] = {
629 "ffffffff00000000ffffffff00000000ffffffff00000000",
630 "ffffffffffffffffffffffff000000000000000000000000",
631 "ffffffff0000000000000000000000000000000000000000",
632 "10000000ffffffffffffffffffffffffffffffffffffffff",
633 "100000000000000000000000000000000000000000000000",
634 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
635 "-ffffffff00000000ffffffff00000000ffffffff00000000",
636 "-ffffffffffffffffffffffff000000000000000000000000",
637 "-ffffffff0000000000000000000000000000000000000000",
638 "-10000000ffffffffffffffffffffffffffffffffffffffff",
639 "-100000000000000000000000000000000000000000000000",
640 "-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
641 };
642
643 for(int i = 0; i < bitPatterns.length; i++) {
644 BigInteger b1 = new BigInteger(bitPatterns[i], 16);
645 BigInteger b2 = null;
646
647 File f = new File("serialtest");
648 FileOutputStream fos = new FileOutputStream(f);
649 try {
650 ObjectOutputStream oos = new ObjectOutputStream(fos);
651 try {
652 oos.writeObject(b1);
653 oos.flush();
654 } finally {
655 oos.close();
656 }
657
658 FileInputStream fis = new FileInputStream(f);
659 try {
660 ObjectInputStream ois = new ObjectInputStream(fis);
661 try {
662 b2 = (BigInteger)ois.readObject();
663 } finally {
664 ois.close();
665 }
666 } finally {
667 fis.close();
668 }
669
670 if (!b1.equals(b2) ||
671 !b1.equals(b1.or(b2))) {
672 failCount++;
673 System.err.println("Serialized failed for hex " +
674 b1.toString(16));
675 }
676 } finally {
677 fos.close();
678 }
679 f.delete();
680 }
681
682 for(int i=0; i<10; i++) {
683 BigInteger b1 = fetchNumber(rnd.nextInt(100));
684 BigInteger b2 = null;
685 File f = new File("serialtest");
686 FileOutputStream fos = new FileOutputStream(f);
687 try {
688 ObjectOutputStream oos = new ObjectOutputStream(fos);
689 try {
690 oos.writeObject(b1);
691 oos.flush();
692 } finally {
693 oos.close();
694 }
695
696 FileInputStream fis = new FileInputStream(f);
697 try {
698 ObjectInputStream ois = new ObjectInputStream(fis);
699 try {
700 b2 = (BigInteger)ois.readObject();
701 } finally {
702 ois.close();
703 }
704 } finally {
705 fis.close();
706 }
707 } finally {
708 fos.close();
709 }
710
711 if (!b1.equals(b2) ||
712 !b1.equals(b1.or(b2)))
713 failCount++;
714 f.delete();
715 }
716
717 report("Serialize", failCount);
718 }
719
720 /**
721 * Main to interpret arguments and run several tests.
722 *
723 * Up to three arguments may be given to specify the size of BigIntegers
724 * used for call parameters 1, 2, and 3. The size is interpreted as
725 * the maximum number of decimal digits that the parameters will have.
726 *
727 */
728 public static void main(String[] args) throws Exception {
|
628 String bitPatterns[] = {
629 "ffffffff00000000ffffffff00000000ffffffff00000000",
630 "ffffffffffffffffffffffff000000000000000000000000",
631 "ffffffff0000000000000000000000000000000000000000",
632 "10000000ffffffffffffffffffffffffffffffffffffffff",
633 "100000000000000000000000000000000000000000000000",
634 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
635 "-ffffffff00000000ffffffff00000000ffffffff00000000",
636 "-ffffffffffffffffffffffff000000000000000000000000",
637 "-ffffffff0000000000000000000000000000000000000000",
638 "-10000000ffffffffffffffffffffffffffffffffffffffff",
639 "-100000000000000000000000000000000000000000000000",
640 "-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
641 };
642
643 for(int i = 0; i < bitPatterns.length; i++) {
644 BigInteger b1 = new BigInteger(bitPatterns[i], 16);
645 BigInteger b2 = null;
646
647 File f = new File("serialtest");
648
649 try (FileOutputStream fos = new FileOutputStream(f)) {
650 try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
651 oos.writeObject(b1);
652 oos.flush();
653 }
654
655 try (FileInputStream fis = new FileInputStream(f);
656 ObjectInputStream ois = new ObjectInputStream(fis))
657 {
658 b2 = (BigInteger)ois.readObject();
659 }
660
661 if (!b1.equals(b2) ||
662 !b1.equals(b1.or(b2))) {
663 failCount++;
664 System.err.println("Serialized failed for hex " +
665 b1.toString(16));
666 }
667 }
668 f.delete();
669 }
670
671 for(int i=0; i<10; i++) {
672 BigInteger b1 = fetchNumber(rnd.nextInt(100));
673 BigInteger b2 = null;
674 File f = new File("serialtest");
675 try (FileOutputStream fos = new FileOutputStream(f)) {
676 try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
677 oos.writeObject(b1);
678 oos.flush();
679 }
680
681 try (FileInputStream fis = new FileInputStream(f);
682 ObjectInputStream ois = new ObjectInputStream(fis))
683 {
684 b2 = (BigInteger)ois.readObject();
685 }
686 }
687
688 if (!b1.equals(b2) ||
689 !b1.equals(b1.or(b2)))
690 failCount++;
691 f.delete();
692 }
693
694 report("Serialize", failCount);
695 }
696
697 /**
698 * Main to interpret arguments and run several tests.
699 *
700 * Up to three arguments may be given to specify the size of BigIntegers
701 * used for call parameters 1, 2, and 3. The size is interpreted as
702 * the maximum number of decimal digits that the parameters will have.
703 *
704 */
705 public static void main(String[] args) throws Exception {
|