示例#1
0
  public void test_clone() {
    try {
      clone();
      harness.fail("Error: test_clone did not raise CloneNotSupportedException");
    } catch (CloneNotSupportedException e) {
    }

    java.util.Vector v = new java.util.Vector();
    java.util.Vector vclone;
    try {
      vclone = (java.util.Vector) v.clone();
    } catch (Exception e) {
      if (e instanceof CloneNotSupportedException) {
        harness.fail(
            "Error: test_clone should not raise CloneNotSupportedException" + " on Vector ");
      } else {
        harness.fail("Error: test_clone should not raise Exception " + e + " on Vector ");
      }
    }

    /*	if (!(( vclone != v ) && ( vclone.getClass() == v.getClass()) &&
    		(vclone.equals( v) )))
    		harness.fail("Error: test_clone did not return proper values");
    */
  }
示例#2
0
  public void test(TestHarness th) {
    Thread notifyThreadArray = new NotifyThreadArray();
    notifyThreadArray.start();

    try {
      synchronized (a) {
        while (!done) {
          a.wait();
        }
      }

      notifyThreadArray.join();
    } catch (InterruptedException e) {
      th.fail("Unexpected exception: " + e);
    }

    done = false;

    Thread notifyThreadMultiArray = new NotifyThreadMultiArray();
    notifyThreadMultiArray.start();

    try {
      synchronized (b) {
        while (!done) {
          b.wait();
        }
      }

      notifyThreadMultiArray.join();
    } catch (InterruptedException e) {
      th.fail("Unexpected exception: " + e);
    }

    th.check(true);
  }
示例#3
0
  public void test_hashCode() {
    Object s = this;
    if (s.hashCode() != hashCode()) harness.fail("Error: test_hashCode returned wrong results - 1");

    int hash = s.hashCode();

    if (hash != s.hashCode()) harness.fail("Error: test_hashCode returned wrong results - 2");
  }
示例#4
0
  public void test_getClass() {
    Integer i = new Integer(10);
    Class cls = i.getClass();
    if (cls == null) harness.fail("Error: test_getClass returned null");

    ObjectTest obj = new ObjectTest();
    if (obj.getClass() != getClass()) harness.fail("Error: test_getClass returned wrong class");
  }
 public void test(TestHarness harness) {
   harness.checkPoint("TestOfSquare");
   cipher = new Square();
   HashMap attrib = new HashMap();
   attrib.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(16));
   attrib.put(IBlockCipher.KEY_MATERIAL, new byte[16]);
   try {
     cipher.init(attrib);
     String algorithm = cipher.name();
     harness.check(validityTest(), "validityTest(" + algorithm + ")");
     harness.check(cloneabilityTest(), "cloneabilityTest(" + algorithm + ")");
     harness.check(katVK(vk_128, cipher, 16), "KAT VK " + algorithm + "-128");
     harness.check(katVT(vt_128, cipher, 16), "KAT VT " + algorithm + "-128");
     harness.check(
         mctEncryptECB(mct_ecb_e_128, cipher, 16), "MCT ECB Encryption " + algorithm + "-128");
     harness.check(
         mctDecryptECB(mct_ecb_d_128, cipher, 16), "MCT ECB Decryption " + algorithm + "-128");
     harness.check(
         mctEncryptCBC(mct_cbc_e_128, cipher, 16), "MCT CBC Encryption " + algorithm + "-128");
     harness.check(
         mctDecryptCBC(mct_cbc_d_128, cipher, 16), "MCT CBC Decryption " + algorithm + "-128");
   } catch (Exception x) {
     harness.debug(x);
     harness.fail("TestOfSquare");
   }
 }
 /** implemented. */
 public void test_setProperty() {
   th.checkPoint("setProperty(java.lang.String,java.lang.String)java.lang.Object");
   Properties p = new Properties();
   try {
     p.setProperty(null, "Noooo...");
     th.fail("should throw NullPointerException -- 1");
   } catch (NullPointerException ne) {
     th.check(true);
   }
   try {
     p.setProperty("Noooo...", null);
     th.fail("should throw NullPointerException -- 2");
   } catch (NullPointerException ne) {
     th.check(true);
   }
   p = new Properties(defProps);
   try {
     p.load(bin);
   } catch (Exception e) {
   }
   try {
     p.setProperty(null, "Noooo...");
     th.fail("should throw NullPointerException -- 3");
   } catch (NullPointerException ne) {
     th.check(true);
   }
   try {
     p.setProperty("No again...", null);
     th.fail("should throw NullPointerException -- 4");
   } catch (NullPointerException ne) {
     th.check(true);
   }
   try {
     th.check(((String) p.setProperty("test", "null")).equals(""), "returns \"\" in our case");
   } catch (NullPointerException ne) {
     th.fail("the value a of property cannot be null, got:" + ne);
   }
   th.check(p.getProperty("test").equals("null"), "check new value in our case null");
   th.check(p.setProperty("testing", "null") == null, "returns value null, name not in list");
   th.check(p.getProperty("test").equals("null"), "check new value in our case null");
   String s = (String) p.setProperty("Smart", "nul");
   th.check(s == null, "returnvalue, is null default list not touched, got");
   th.check(p.getProperty("Smart").equals("nul"), "check new value in our case null");
   s = ((String) p.setProperty("name", "nu"));
   th.check(s.equals("no"), "return value in our case no, got: " + s);
   th.check(p.getProperty("name").equals("nu"), "check new value in our case nu");
 }
示例#7
0
  public void test_charAt() {
    harness.check(
        !((new StringBuffer("abcd")).charAt(0) != 'a'
            || (new StringBuffer("abcd")).charAt(1) != 'b'
            || (new StringBuffer("abcd")).charAt(2) != 'c'
            || (new StringBuffer("abcd")).charAt(3) != 'd'),
        "test_charAt - 1");

    try {
      char ch = (new StringBuffer("abcd")).charAt(4);
      harness.fail("test_charAt - 2");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      char ch = (new StringBuffer("abcd")).charAt(-1);
      harness.fail("test_charAt - 3");
    } catch (IndexOutOfBoundsException e) {
    }
  }
示例#8
0
  public void test(TestHarness th) {
    try {
      Thread t = new RuntimeExceptionThread();
      t.start();
      t.join();
      result = true;
    } catch (InterruptedException e) {
      th.fail("unexpected InterruptedException");
    }

    th.check(result);
  }
示例#9
0
 public void test(TestHarness harness) {
   harness.checkPoint("TestOfToByteArray");
   try {
     BigInteger x = new BigInteger(BYTES);
     harness.verbose("*** x = 0x" + x.toString(16));
     byte[] ba = x.toByteArray();
     harness.check(Arrays.equals(ba, BYTES), true, "Byte arrays MUST be equal");
   } catch (Exception x) {
     harness.debug(x);
     harness.fail("TestOfToByteArray: " + x);
   }
 }
示例#10
0
 protected void test1Encoding(TestHarness h, String encoding, String s, byte[] ba) {
   String signature = "String.getBytes(\"" + encoding + "\")";
   try {
     byte[] theBytes = s.getBytes(encoding);
     boolean result = areEqual(theBytes, ba);
     h.check(result, signature);
     if (!result) {
       dumpArray(h, "Got     : ", theBytes);
       dumpArray(h, "Expected: ", ba);
     }
   } catch (UnsupportedEncodingException x) {
     h.debug(x);
     h.fail(signature);
   }
 }
  /** implemented. */
  public void test_getProperty() {
    th.checkPoint("getProperty(java.lang.String)java.lang.String");
    Properties p = new Properties();
    try {
      p.getProperty(null);
      th.fail("should throw a NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    p = new Properties(defProps);
    try {
      p.getProperty(null);
      th.fail("should throw a NullPointerException -- 2");
    } catch (NullPointerException ne) {
      th.check(true);
    }
    try {
      p.load(bin);
    } catch (Exception e) {
    }
    try {
      p.getProperty(null);
      th.fail("should throw a NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }
    try {
      th.check(p.getProperty("dog").equals("no_cat"), "check returnvalue");
      th.check(p.getProperty("name").equals("no"), "return property from main property table");
      th.check(p.getProperty("Smart").equals("move"), "check returnvalue from default table");
      th.check(p.getProperty("NoEntry") == null, "check for null if not there");
    } catch (Exception e) {
      th.fail("got unexpected exception: " + e);
    }
    th.checkPoint("getProperty(java.lang.String,java.lang.String)java.lang.String");
    try {
      p.getProperty(null, "Noooo...");
      th.fail("should throw a NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }
    try {
      th.check(p.getProperty("Noooo...", null) == null, "defVal may be null");
    } catch (NullPointerException ne) {
      th.fail("shouldn't throw a NullPointerException -- 1");
    }
    th.check(p.getProperty("dog", "not found").equals("no_cat"), "check returnvalue");
    th.check(
        p.getProperty("name", "not found").equals("no"),
        "return property from main property table");
    th.check(
        p.getProperty("Smart", "not found").equals("move"), "check returnvalue from default table");
    th.check(
        p.getProperty("NoEntry", "not found").equals("not found"), "check for defVal if not there");
  }
示例#12
0
 public void test(TestHarness harness) {
   harness.checkPoint("TestOfCast5");
   cipher = new Cast5();
   HashMap attrib = new HashMap();
   attrib.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(8));
   attrib.put(IBlockCipher.KEY_MATERIAL, new byte[16]);
   try {
     harness.check(validityTest(), "validityTest()");
     harness.check(cloneabilityTest(), "cloneabilityTest()");
     harness.check(vectorsTest(), "vectorsTest()");
   } catch (Exception x) {
     harness.debug(x);
     harness.fail("TestOfCast5");
   }
 }
 /**
  * implemented. <br>
  * might need extra testcode
  */
 public void test_Properties() {
   th.checkPoint("Properties()");
   // not much to check for this one !
   Properties p = new Properties();
   th.check(p.isEmpty(), "nothing in there");
   th.checkPoint("Properties(java.util.Properties)");
   p = new Properties(defProps);
   th.check(p.isEmpty(), "nothing in there");
   th.check(p.getProperty("name").equals("yes"), "default field is not empty");
   try {
     p = new Properties(null);
     th.check(true);
   } catch (Exception e) {
     th.fail("should not throw an Exeption. Got: " + e);
   }
 }
示例#14
0
  public void test_Basics() {
    try {
      StringBuffer str0 = new StringBuffer(-10);
      harness.fail("test_Basics - 0");
    } catch (NegativeArraySizeException e) {
    }

    StringBuffer str1 = new StringBuffer();
    harness.check(!(str1.length() != 0 || str1.capacity() != 16), "test_Basics - 1");
    harness.check(!(!str1.toString().equals("")), "test_Basics - 2");

    StringBuffer str2 = new StringBuffer("testing");
    harness.check(!(str2.length() != 7), "test_Basics - 3");
    harness.check(!(!str2.toString().equals("testing")), "test_Basics - 4");

    try {
      String str = null;
      StringBuffer str3 = new StringBuffer(str);
      /*
        CYGNUS: nowhere does it say that we should
        handle a null argument in StringBuffer(str).
        In fact, the JCL implies that we should not.
        But this leads to an asymmetry: `null + ""'
        will fail, while `"" + null' will work.  For
        thaht reason, this test is commented out
        here: it's not a failure.

      harness.fail("test_Basics - 5");

      */
    } catch (NullPointerException e) {
    }

    StringBuffer str4 = new StringBuffer("hi there");
    harness.check(!(str4.length() != 8 || str4.capacity() != 24), "test_Basics - 6");
    harness.check(!(!str4.toString().equals("hi there")), "test_Basics - 7");

    StringBuffer strbuf = new StringBuffer(0);
    harness.check(!(!strbuf.append("hiii").toString().equals("hiii")), "test_Basics - 8");

    strbuf = new StringBuffer(10);
    harness.check(!(strbuf.capacity() != 10), "test_Basics - 9");
  }
示例#15
0
  public void test_setLength() {
    StringBuffer strbuf = new StringBuffer("ba");

    try {
      strbuf.setLength(-10);
      harness.fail("test_setLength - 1");
    } catch (IndexOutOfBoundsException e) {
    }

    strbuf.setLength(4);
    harness.check(!(strbuf.length() != 4), "test_setLength - 2");

    harness.check(
        !(strbuf.charAt(0) != 'b'
            || strbuf.charAt(1) != 'a'
            || strbuf.charAt(2) != '\u0000'
            || strbuf.charAt(3) != '\u0000'),
        "test_setLength - 3");
  }
示例#16
0
  public void test_equals() {
    Object nu = this;

    // reflexive
    if (this != nu) harness.fail("Error: test_equals returned wrong results - 1");
    if (!this.equals(nu)) harness.fail("Error: test_equals returned wrong results - 2");

    if (!nu.equals(nu)) harness.fail("Error: test_equals returned wrong results - 3");

    // symmetric
    Object nu1 = nu;

    if (!(nu.equals(nu1) && nu1.equals(nu)))
      harness.fail("Error: test_equals returned wrong results - 4");

    // transitive
    if (!(nu.equals(nu1) && nu1.equals(this) && equals(nu)))
      harness.fail("Error: test_equals returned wrong results - 5");

    Object p = null;
    if (equals(p)) harness.fail("Error: test_equals returned wrong results - 6");
  }
  private void testSymmetry(TestHarness harness, int ndx) {
    harness.checkPoint("TestOfAssembly.testSymmetry#" + ndx);

    byte[] km = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8};
    byte[] iv = new byte[] {-1, -2, -3, -4, -5, -6, -7, -8, -9};
    byte[] pt = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    byte[] tpt = new byte[11 * pt.length];

    // forward
    modeAttributes.put(IBlockCipher.KEY_MATERIAL, km);
    modeAttributes.put(IMode.IV, iv);
    attributes.put(Assembly.DIRECTION, Direction.FORWARD);
    try {
      asm.init(attributes);
    } catch (TransformerException x) {
      harness.debug(x);
      harness.fail("Forward initialisation");
      return;
    }

    byte[] ct = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      for (int i = 0; i < 10; i++) { // transform in parts of 12-byte a time
        System.arraycopy(pt, 0, tpt, i * pt.length, pt.length);
        ct = asm.update(pt);
        baos.write(ct, 0, ct.length);
      }
    } catch (TransformerException x) {
      harness.debug(x);
      harness.fail("Forward transformation");
      return;
    }
    try {
      System.arraycopy(pt, 0, tpt, 10 * pt.length, pt.length);
      ct = asm.lastUpdate(pt);
    } catch (TransformerException x) {
      harness.debug(x);
      harness.fail("Forward last transformation");
      return;
    }
    baos.write(ct, 0, ct.length);
    ct = baos.toByteArray();

    // reversed
    attributes.put(Assembly.DIRECTION, Direction.REVERSED);
    try {
      asm.init(attributes);
    } catch (TransformerException x) {
      harness.debug(x);
      harness.fail("Reverse initialisation");
      return;
    }

    byte[] ot;
    try {
      ot = asm.lastUpdate(ct); // transform the lot in one go
    } catch (TransformerException x) {
      harness.debug(x);
      harness.fail("Reverse transformation");
      return;
    }

    harness.check(Arrays.equals(ot, tpt), "symmetric test");
  }
示例#18
0
  public void test_insert() {
    StringBuffer buf = new StringBuffer("1234567");
    Object obj = null;
    buf = buf.insert(5, obj);
    harness.check(!(!buf.toString().equals("12345null67")), "test_insert - 1");

    try {
      buf = buf.insert(-1, new Object());
      harness.fail("test_insert - 2");

    } catch (IndexOutOfBoundsException e) {
    }

    buf = new StringBuffer("1234567");
    try {
      buf = buf.insert(8, new Object());
      harness.fail("test_insert - 3");
    } catch (IndexOutOfBoundsException e) {
    }

    buf = new StringBuffer("1234567");
    buf = buf.insert(4, "inserted");
    harness.check(!(!buf.toString().equals("1234inserted567")), "test_insert - 4");

    buf = new StringBuffer("1234567");
    char cdata[] = null;
    try {
      buf = buf.insert(4, cdata);
      harness.fail("test_insert - 5");
    } catch (NullPointerException e) {
    }

    cdata = new char[2];
    try {
      buf = buf.insert(-1, cdata);
      harness.fail("test_insert - 6");

    } catch (IndexOutOfBoundsException e) {
    }

    try {
      buf = buf.insert(8, cdata);
      harness.fail("test_insert - 7");
    } catch (IndexOutOfBoundsException e) {
    }

    buf = new StringBuffer("1234567");
    char cdata1[] = {'h', 'e', 'l', 'l', 'o'};
    buf = buf.insert(4, cdata1);
    harness.check(!(!buf.toString().equals("1234hello567")), "test_insert - 8");

    buf = new StringBuffer("1234567");
    buf = buf.insert(0, true);
    harness.check(!(!buf.toString().equals("true1234567")), "test_insert - 9");

    buf = new StringBuffer("1234567");
    buf = buf.insert(7, false);
    harness.check(!(!buf.toString().equals("1234567false")), "test_insert - 10");

    buf = new StringBuffer("1234567");
    buf = buf.insert(0, 'c');
    harness.check(!(!buf.toString().equals("c1234567")), "test_insert - 11");

    buf = new StringBuffer("1234567");
    buf = buf.insert(7, 'b');
    harness.check(!(!buf.toString().equals("1234567b")), "test_insert - 12");

    buf = new StringBuffer("1234567");
    buf = buf.insert(7, 999);
    harness.check(!(!buf.toString().equals("1234567999")), "test_insert - 13");

    buf = new StringBuffer("1234567");
    buf = buf.insert(0, 99.9f);
    harness.check(!(!buf.toString().equals("99.91234567")), "test_insert - 14");

    buf = new StringBuffer("1234567");
    buf = buf.insert(3, 34.46);
    harness.check(!(!buf.toString().equals("12334.464567")), "test_insert - 15 " + buf.toString());
    buf = new StringBuffer("1234567");
    buf = buf.insert(3, (long) 1230);
    harness.check(!(!buf.toString().equals("12312304567")), "test_insert - 16 " + buf.toString());
  }
示例#19
0
  public void test_append() {
    StringBuffer str = new StringBuffer();
    Object nullobj = null;
    harness.check(!(!str.append(nullobj).toString().equals("null")), "test_append - 1");

    harness.check(!(!str.append(new Integer(100)).toString().equals("null100")), "test_append - 2");

    StringBuffer str1 = new StringBuffer("hi");
    str1 = str1.append(" there");
    str1 = str1.append(" buddy");

    harness.check(!(!str1.toString().equals("hi there buddy")), "test_append - 2");

    StringBuffer str2 = new StringBuffer();
    str2 = str2.append("sdljfksdjfklsdjflksdjflkjsdlkfjlsdkjflksdjfklsd");
    harness.check(
        !(!str2.toString().equals("sdljfksdjfklsdjflksdjflkjsdlkfjlsdkjflksdjfklsd")),
        "test_append - 3");

    char carr[] = null;
    StringBuffer str3 = new StringBuffer();

    try {
      str3 = str3.append(carr);
      harness.fail("test_append - 4");
    } catch (NullPointerException e) {
    }

    char carr1[] = {'h', 'i', 't', 'h', 'e', 'r'};
    StringBuffer str4 = new StringBuffer("!");
    harness.check(!(!str4.append(carr1).toString().equals("!hither")), "test_append - 5");

    try {
      System.out.println("heee22222: " + carr1 + " - " + str3.toString());
      str3 = str3.append(carr, 0, 3);
      harness.fail("test_append - 6");
    } catch (NullPointerException e) {
    }
    str3 = new StringBuffer();
    try {
      str3 = str3.append(carr1, -1, 3);
      harness.fail("test_append - 6");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      str3 = str3.append(carr1, 0, -3);
      harness.fail("test_append - 6");
    } catch (IndexOutOfBoundsException e) {
    }

    StringBuffer str5 = new StringBuffer("!");
    str5 = str5.append(carr1, 2, 3);
    harness.check(!(!str5.toString().equals("!the")), "test_append - 7");

    str5 = new StringBuffer();
    str5 = str5.append(true);
    harness.check(!(!str5.toString().equals("true")), "test_append - 8");

    str5 = str5.append(false);
    harness.check(!(!str5.toString().equals("truefalse")), "test_append - 9");

    str5 = str5.append(20);
    harness.check(!(!str5.toString().equals("truefalse20")), "test_append - 10");

    str5 = new StringBuffer();
    str5 = str5.append(2034L);
    harness.check(!(!str5.toString().equals("2034")), "test_append - 11");

    str5 = new StringBuffer();
    str5 = str5.append(34.45f);
    harness.check(!(!str5.toString().equals("34.45")), "test_append - 12");

    str5 = new StringBuffer();
    str5 = str5.append(34.46);
    harness.check(!(!str5.toString().equals("34.46")), "test_append - 13");
  }
示例#20
0
  public void test_getChars() {
    StringBuffer str = new StringBuffer("abcdefghijklmn");

    try {
      str.getChars(0, 3, null, 1);
      harness.fail("test_getChars - 1");
    } catch (NullPointerException e) {
    }

    char dst[] = new char[5];

    try {
      str.getChars(-1, 3, dst, 1);
      harness.fail("test_getChars - 2");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      str.getChars(4, 3, dst, 3);
      // CYGNUS: This is a test for JDK 1.2 conformance
      harness.fail("test_getChars - 3");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      str.getChars(1, 15, dst, 1);
      harness.fail("test_getChars - 4");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      str.getChars(1, 5, dst, -1);
      harness.fail("test_getChars - 5");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      str.getChars(1, 10, dst, 1);
      harness.fail("test_getChars - 6");
    } catch (IndexOutOfBoundsException e) {
    }

    str.getChars(0, 5, dst, 0);
    harness.check(
        !(dst[0] != 'a' || dst[1] != 'b' || dst[2] != 'c' || dst[3] != 'd' || dst[4] != 'e'),
        "test_getChars - 7");

    dst[0] = dst[1] = dst[2] = dst[3] = dst[4] = ' ';
    str.getChars(0, 0, dst, 0);
    harness.check(
        !(dst[0] != ' ' || dst[1] != ' ' || dst[2] != ' ' || dst[3] != ' ' || dst[4] != ' '),
        "test_getChars - 9");

    dst[0] = dst[1] = dst[2] = dst[3] = dst[4] = ' ';
    str.getChars(0, 1, dst, 0);
    harness.check(
        !(dst[0] != 'a' || dst[1] != ' ' || dst[2] != ' ' || dst[3] != ' ' || dst[4] != ' '),
        "test_getChars - 10");

    dst = new char[25];
    str.getChars(3, 14, dst, 12);
    harness.check(dst[12], 'd', "getChars starting src offset 3");
    harness.check(dst[22], 'n', "getChars ending dst offset 22");
  }
示例#21
0
  public void test(TestHarness harness) {
    harness.checkPoint("TestOfMD2");
    try {
      algorithm = new MD2();
      harness.check(algorithm.selfTest(), "selfTest");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.selfTest");
    }

    try {
      algorithm = new MD2();
      algorithm.update("a".getBytes(), 0, 1);
      byte[] md = algorithm.digest();
      String exp = "32EC01EC4A6DAC72C0AB96FB34C0B5D1";
      harness.check(exp.equals(Util.toString(md)), "testA");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testA");
    }

    try {
      algorithm = new MD2();
      algorithm.update("abc".getBytes(), 0, 3);
      byte[] md = algorithm.digest();
      String exp = "DA853B0D3F88D99B30283A69E6DED6BB";
      harness.check(exp.equals(Util.toString(md)), "testABC");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testABC");
    }

    try {
      algorithm = new MD2();
      algorithm.update("message digest".getBytes(), 0, 14);
      byte[] md = algorithm.digest();
      String exp = "AB4F496BFB2A530B219FF33031FE06B0";
      harness.check(exp.equals(Util.toString(md)), "testMessageDigest");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testMessageDigest");
    }

    try {
      algorithm = new MD2();
      algorithm.update("abcdefghijklmnopqrstuvwxyz".getBytes(), 0, 26);
      byte[] md = algorithm.digest();
      String exp = "4E8DDFF3650292AB5A4108C3AA47940B";
      harness.check(exp.equals(Util.toString(md)), "testAlphabet");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testAlphabet");
    }

    try {
      algorithm = new MD2();
      algorithm.update(
          "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".getBytes(), 0, 62);
      byte[] md = algorithm.digest();
      String exp = "DA33DEF2A42DF13975352846C30338CD";
      harness.check(exp.equals(Util.toString(md)), "testAsciiSubset");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testAsciiSubset");
    }

    try {
      algorithm = new MD2();
      algorithm.update(
          "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
              .getBytes(),
          0,
          80);
      byte[] md = algorithm.digest();
      String exp = "D5976F79D83D3A0DC9806C3C66F3EFD8";
      harness.check(exp.equals(Util.toString(md)), "testEightyNumerics");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testEightyNumerics");
    }

    try {
      algorithm = new MD2();
      algorithm.update("a".getBytes(), 0, 1);
      clone = (IMessageDigest) algorithm.clone();
      byte[] md = algorithm.digest();
      String exp = "32EC01EC4A6DAC72C0AB96FB34C0B5D1";
      harness.check(exp.equals(Util.toString(md)), "testCloning #1");

      clone.update("bc".getBytes(), 0, 2);
      md = clone.digest();
      exp = "DA853B0D3F88D99B30283A69E6DED6BB";
      harness.check(exp.equals(Util.toString(md)), "testCloning #2");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfMD2.testCloning");
    }
  }
  /**
   * implemented. <br>
   * Add a test to determine of store generates a comment line with the current time <br>
   * <br>
   * depricated method !!!
   */
  public void test_save() {
    th.checkPoint("save(java.io.OutputStream,java.lang.String)void");
    Properties p = new Properties(defProps);
    try {
      p.save(null, "no comment");
      th.fail("should throw NullPointerException");
    } catch (NullPointerException ne) {
      th.check(true);
    } catch (Exception e) {
      th.fail("should throw an NullPointerEception instead of: " + e);
    }

    try {
      p.save(bout, null);
      th.check(true);
    } catch (NullPointerException ne) {
      th.fail("should not throw NullPointerException");
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }

    resetStreams();
    try {
      p.save(bout, null);
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }
    byte ba[] = bout.toByteArray();
    th.check((ba[0] == (byte) '#') && (ba[1] != (byte) '#'), "just date should be written");
    th.debug(ba.length + " -- got: " + new String(ba));
    th.check(ba.length < 50, "default properties are never printed out");
    resetStreams();
    try {
      p.load(bin);
    } catch (Exception e) {
    }
    try {
      p.save(bout, "no comments");
    } catch (Exception e) {
      th.fail("shouldn't throw any Exception, but got: " + e);
    }
    ba = bout.toByteArray();
    String s = new String(ba, 0, 12);
    th.check(s.equals("#no comments"), "got: " + s);
    int i = 0, count = 0;
    while (i < 2 && count < ba.length) {
      if (ba[count++] == (byte) '\n') i++;
    }
    // we will construct a vector containing all the lines with should be written
    Vector v = new Vector();
    Enumeration ek = p.keys();
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    while (count < ba.length) {
      int start = count;
      while (count < ba.length) {
        if (ba[count] != '\n') count++;
        else break;
      }
      s = new String(ba, start, count - start);
      th.check(v.contains(s), "v does not contain: " + s);
      v.removeElement(s);
      count++;
    }
  }
示例#23
0
 public void test_toString() {
   if (toString() == null) harness.fail("Error: test_toString returned null string");
   if (!toString().equals(getClass().getName() + "@" + Integer.toHexString(hashCode())))
     harness.fail("Error: test_toString returned wrong string");
 }
  /**
   * implemented. <br>
   * load is used by other tests to make a propeties file <br>
   * failures in load will mak other tests fail !
   */
  public void test_load() {
    th.checkPoint("load(java.io.InputStream)void");
    Properties p = new Properties();
    try {
      p.load((ByteArrayInputStream) null);
      th.fail("should throw NullPointerException");
    } catch (NullPointerException ne) {
      th.check(true);
    } catch (Exception e) {
      th.fail("should throw an NullPointerException instead of: " + e);
    }

    try {
      p.load(bin);
    } catch (Exception e) {
    }
    Enumeration ek1 = p.keys();
    resetStreams();
    try {
      p.load(bin);
    } catch (Exception e) {
    }
    Enumeration ek2 = p.keys();
    boolean ok = true;
    while (ek1.hasMoreElements() && ek2.hasMoreElements()) {
      if (ek1.nextElement() != ek2.nextElement()) ok = false;
    }
    th.check(
        !ek1.hasMoreElements() && !ek2.hasMoreElements(),
        "no extra elements may be added with same name");
    th.check(ok, " all elements are equal ");
    bin = new ByteArrayInputStream(new String("name=yes\nSmart=move\nanimal=dog").getBytes());
    try {
      p.load(bin);
    } catch (Exception e) {
    }
    th.check(p.getProperty("name").equals("yes"), "load overrides previous values");
    Vector v = new Vector();
    v.add("name");
    v.add("Smart");
    v.add("animal");
    v.add("dog");
    v.add("test");
    v.add("date");
    v.add("longvalue");
    v.add("40chars");
    ek1 = p.keys();
    ok = true;
    Object o;
    while (ek1.hasMoreElements()) {
      o = ek1.nextElement();
      if (v.contains(o)) v.removeElement(o);
      else {
        ok = false;
        th.debug("got extra element: " + (String) o);
      }
    }

    th.check(ok, "all elements were there");
    th.check(v.isEmpty(), "all elements should be gone, got" + v);
    setUpTest();
  }
  /** implemented. */
  public void test_list() {
    th.checkPoint("list(java.io.PrintStream)void");
    Properties p = new Properties();
    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    try {
      p.load(bin);
    } catch (Exception e) {
    }
    p.list(psout);
    byte ba[] = bout.toByteArray();
    Vector v = new Vector();
    Enumeration ek = p.keys();
    String s;
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    v.add("Smart=move");
    v.add("animal=dog");

    int start, count = 0;
    v.removeElement("longvalue=I'mtryingtogiveavaluelongerthen40characters");
    v.add("longvalue=I'mtryingtogiveavaluelongerthen40char...");
    while (count < ba.length) {
      start = count;
      while (ba[count] != '\n' && count < ba.length) {
        count++;
      }
      s = new String(ba, start, count - start);
      if (!s.startsWith("--")) // list() adds a header
      th.check(v.contains(s), "v does not contain:$" + s + "$");
      v.removeElement(s);
      count++;
    }

    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 2");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    th.checkPoint("list(java.io.PrintWriter)void");
    resetStreams();
    p = new Properties();
    try {
      p.list((PrintWriter) null);
      th.fail("should throw NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    try {
      p.load(bin);
    } catch (Exception e) {
    }
    p.list(pwout);
    ba = bout.toByteArray();
    v = new Vector();
    ek = p.keys();
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    v.add("Smart=move");
    v.add("animal=dog");

    count = 0;
    v.removeElement("longvalue=I'mtryingtogiveavaluelongerthen40characters");
    v.add("longvalue=I'mtryingtogiveavaluelongerthen40char...");

    while (count < ba.length) {
      start = count;
      while (ba[count] != '\n' && count < ba.length) {
        count++;
      }
      s = new String(ba, start, count - start);
      if (!s.startsWith("--")) // list() adds a header
      th.check(v.contains(s), "v does not contain:$" + s + "$");
      v.removeElement(s);
      count++;
    }

    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 2");
    } catch (NullPointerException ne) {
      th.check(true);
    }
  }
示例#26
0
  public void test(TestHarness harness) {
    harness.checkPoint("TestOfTMMH16");

    /*
    KEY_LENGTH: 10
    TAG_LENGTH: 2
    key: { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc }
    message: { 0xca, 0xfe, 0xba, 0xbe, 0xba, 0xde }
    output: { 0x9d, 0x6a }
    */
    try {
      attributes.clear();
      keystream = new DummyKeystream();
      keystream.init(null);

      output = new byte[] {(byte) 0x9d, (byte) 0x6a};
      mac = new TMMH16();
      attributes.put(TMMH16.KEYSTREAM, keystream);
      attributes.put(TMMH16.TAG_LENGTH, new Integer(2));
      mac.init(attributes);
      message =
          new byte[] {(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, (byte) 0xba, (byte) 0xde};
      for (int i = 0; i < message.length; i++) {
        mac.update(message[i]);
      }
      result = mac.digest();
      harness.check(Arrays.equals(result, output), "testVector1");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfTMMH16.testVector1");
    }

    /*
    KEY_LENGTH: 10
    TAG_LENGTH: 2
    key: { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc }
    message: { 0xca, 0xfe, 0xba }
    output: { 0xc8, 0x8e }
    */
    try {
      attributes.clear();
      keystream = new DummyKeystream();
      keystream.init(null);

      output = new byte[] {(byte) 0xc8, (byte) 0x8e};
      mac = new TMMH16();
      attributes.put(TMMH16.KEYSTREAM, keystream);
      attributes.put(TMMH16.TAG_LENGTH, new Integer(2));
      mac.init(attributes);
      message = new byte[] {(byte) 0xca, (byte) 0xfe, (byte) 0xba};
      for (int i = 0; i < message.length; i++) {
        mac.update(message[i]);
      }
      result = mac.digest();
      harness.check(Arrays.equals(result, output), "testVector2");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfTMMH16.testVector2");
    }

    /*
    KEY_LENGTH: 10
    TAG_LENGTH: 4
    key: { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc }
    message: { 0xca, 0xfe, 0xba, 0xbe, 0xba, 0xde }
    output: { 0x9d, 0x6a, 0xc0, 0xd3 }
    */
    try {
      attributes.clear();
      keystream = new DummyKeystream();
      keystream.init(null);

      output = new byte[] {(byte) 0x9d, (byte) 0x6a, (byte) 0xc0, (byte) 0xd3};
      mac = new TMMH16();
      attributes.put(TMMH16.KEYSTREAM, keystream);
      attributes.put(TMMH16.TAG_LENGTH, new Integer(4));
      mac.init(attributes);
      message =
          new byte[] {(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, (byte) 0xba, (byte) 0xde};
      for (int i = 0; i < message.length; i++) {
        mac.update(message[i]);
      }
      result = mac.digest();
      harness.check(Arrays.equals(result, output), "testVector3");
    } catch (Exception x) {
      harness.debug(x);
      harness.fail("TestOfTMMH16.testVector3");
    }
  }