Exemplo n.º 1
0
  public void test(TestHarness harness) {
    Currency currency;
    boolean threwException;

    /* Check getInstance with a null string */
    threwException = false;
    try {
      currency = Currency.getInstance((String) null);
    } catch (NullPointerException exception) {
      threwException = true;
    }
    harness.check(threwException, "Currency instance request with null string exception check.");
    /* Check getInstance with a non-existant ISO string */
    threwException = false;
    try {
      currency = Currency.getInstance(INVALID_CURRENCY_CODE);
    } catch (IllegalArgumentException exception) {
      threwException = true;
    }
    harness.check(
        threwException,
        "Currency instance request with invalid currency code string exception check.");
    /* Check getInstance with a null locale */
    threwException = false;
    try {
      currency = Currency.getInstance((Locale) null);
    } catch (NullPointerException exception) {
      threwException = true;
    }
    harness.check(threwException, "Currency instance request with null locale exception check.");
  }
Exemplo n.º 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);
  }
Exemplo n.º 3
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");
    */
  }
Exemplo n.º 4
0
  public void test(TestHarness th) {
    LogRecord rec1 = new LogRecord(Level.CONFIG, "msg");
    LogRecord rec2 = new LogRecord(Level.CONFIG, "msg2");
    long s1, s2;

    s1 = rec1.getSequenceNumber();
    s2 = rec2.getSequenceNumber();

    /* Check #1.
     *
     * It could happen that rec1 has a sequence number of
     * Long.MAX_VALUE, or that rec1's sequence number is close to
     * Long.MAX_VALUE and some background threads have created a few
     * LogRecords between the creation of rec1 and rec2, so rec2's
     * sequence number is equal to or slightly greater than
     * Long.MIN_VALUE. In these cases, s2 would not be greater than
     * s1, although the implementation of java.util.logging.LogRecord
     * was entirely correct.
     *
     * While this event is extremely unlikely, it is not entirely
     * impossible, so we can perform the subsequent check only if
     * there was no arithmetic overflow.
     */
    if ((s1 >= 0) == (s2 >= 0)) th.check(s2 > s1);
    else th.check(true);

    // Check #2.
    rec2.setSequenceNumber(42);
    th.check(rec2.getSequenceNumber() == 42);

    // Check #3.
    rec2.setSequenceNumber(s2);
    th.check(rec2.getSequenceNumber() == s2);
  }
Exemplo n.º 5
0
 /**
  * Runs the test using the specified harness.
  *
  * @param harness the test harness (<code>null</code> not permitted).
  */
 public void test(TestHarness harness) {
   Point p1 = new Point(10, 11);
   Point p2 = null;
   p2 = (Point) p1.clone();
   harness.check(p1.equals(p2));
   harness.check(p1 != p2);
 }
Exemplo n.º 6
0
  public void test(TestHarness harness) {
    Currency currency;

    /* Set default Locale for the JVM */
    Locale.setDefault(TEST_LOCALE);
    /* Get an instance of the currency */
    currency = Currency.getInstance(TEST_LOCALE);
    /* Check for the correct currency code */
    harness.check(
        currency.getCurrencyCode(),
        ISO4217_CODE,
        "ISO 4217 currency code retrieval check (" + currency.getCurrencyCode() + ").");
    /* Check for the correct currency symbol */
    harness.check(
        currency.getSymbol(),
        CURRENCY_SYMBOL,
        "Currency symbol retrieval check (" + currency.getSymbol() + ").");
    /* Check for the correct fraction digits */
    harness.check(
        currency.getDefaultFractionDigits(),
        FRACTION_DIGITS,
        "Currency fraction digits retrieval check (" + currency.getDefaultFractionDigits() + ").");
    /* Check for the correct currency code from toString()*/
    harness.check(
        currency.toString(),
        ISO4217_CODE,
        "ISO 4217 currency code retrieval check (" + currency.toString() + ").");
  }
Exemplo n.º 7
0
 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");
   }
 }
Exemplo n.º 8
0
 /**
  * Runs the test using the specified harness.
  *
  * @param harness the test harness (<code>null</code> not permitted).
  */
 public void test(TestHarness harness) {
   DecimalFormat f1 = new DecimalFormat();
   f1.setNegativePrefix("ABC");
   harness.check(f1.getNegativePrefix(), "ABC");
   f1.setNegativePrefix(null);
   harness.check(f1.getNegativePrefix(), null);
 }
Exemplo n.º 9
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");
  }
Exemplo n.º 10
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");
  }
Exemplo n.º 11
0
  public void test_length() {
    StringBuffer buf1 = new StringBuffer("");
    StringBuffer buf2 = new StringBuffer("pentium");

    harness.check(!(buf1.length() != 0), "test_length - 1");

    harness.check(!(buf2.length() != 7), "test_length - 2");
  }
Exemplo n.º 12
0
  public void test_toString() {
    StringBuffer str1 = new StringBuffer("218943289");

    harness.check(!(!str1.toString().equals("218943289")), "test_toString - 1");

    str1 = new StringBuffer();
    harness.check(!(!str1.toString().equals("")), "test_toString - 2");
  }
Exemplo n.º 13
0
 public void test(TestHarness harness) {
   try {
     DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale("foobar"));
     harness.check(dfs.getCurrency().toString().equals("XXX"));
   } catch (Exception x) {
     harness.debug(x);
     harness.check(false);
   }
 }
Exemplo n.º 14
0
  public void test(TestHarness th) {
    Image image = Image.createImage(240, 320);
    Graphics g = image.getGraphics();

    short width = g.getMaxWidth();
    th.check(width, 240);
    short height = g.getMaxHeight();
    th.check(height, 320);
  }
Exemplo n.º 15
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    NoClassDefFoundError error1 = new NoClassDefFoundError();
    harness.check(error1 != null);
    harness.check(error1.toString(), "java.lang.NoClassDefFoundError");

    NoClassDefFoundError error2 = new NoClassDefFoundError("nothing happens");
    harness.check(error2 != null);
    harness.check(error2.toString(), "java.lang.NoClassDefFoundError: nothing happens");
  }
Exemplo n.º 16
0
  public void test(TestHarness th) {
    LogRecord rec = new LogRecord(Level.CONFIG, "foo");

    // Check #1.
    rec.setMillis(12345);
    th.check(rec.getMillis(), 12345);

    // Check #2.
    rec.setMillis(-54321);
    th.check(rec.getMillis(), -54321);
  }
Exemplo n.º 17
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // create instance of a class Integer
    Integer o = new Integer(42);

    // basic check of instanceof operator
    harness.check(o instanceof Integer);

    // check operator instanceof against all superclasses
    harness.check(o instanceof Number);
    harness.check(o instanceof Object);
  }
Exemplo n.º 18
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);
   }
 }
Exemplo n.º 19
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // create instance of a class ClassNotFoundException
    ClassNotFoundException o = new ClassNotFoundException("ClassNotFoundException");

    // basic check of instanceof operator
    harness.check(o instanceof ClassNotFoundException);

    // check operator instanceof against all superclasses
    harness.check(o instanceof Exception);
    harness.check(o instanceof Throwable);
    harness.check(o instanceof Object);
  }
Exemplo n.º 20
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);
  }
Exemplo n.º 21
0
  public void test(TestHarness harness) {
    ParsePosition pp = new ParsePosition(69);
    harness.check(pp.getIndex(), 69, "getIndex() post-create");

    pp.setIndex(666);
    harness.check(pp.getIndex(), 666, "set/getIndex()");

    harness.check(pp.getErrorIndex(), -1, "getErrorIndex() no error");

    pp.setErrorIndex(65536);
    harness.check(pp.getErrorIndex(), 65536, "set/getErrorIndex()");

    harness.debug(pp.toString());
  }
Exemplo n.º 22
0
  public void check(String name, String in, String[] out, BreakIterator bi, TestHarness harness) {
    harness.checkPoint(name);
    bi.setText(in);

    int index = 0;
    int from = bi.current();
    harness.check(from, 0);

    while (true) {
      int to = bi.next();
      if (to == BreakIterator.DONE) break;
      harness.check(in.substring(from, to), out[index]);
      ++index;
      from = to;
    }

    harness.check(index, out.length);

    harness.checkPoint("backwards " + name);
    bi.last();
    index = out.length - 1;
    from = bi.current();
    harness.check(from, in.length());

    while (true) {
      int to = bi.previous();
      if (to == BreakIterator.DONE) break;
      harness.check(in.substring(to, from), out[index]);
      --index;
      from = to;
    }

    harness.check(index, -1);
  }
Exemplo n.º 23
0
  public void test_capacity() {
    StringBuffer buf1 = new StringBuffer("");
    StringBuffer buf2 = new StringBuffer("pentiumpentiumpentium");

    harness.check(!(buf1.capacity() != 16), "test_capacity - 1");

    int cap = buf2.capacity();
    harness.check(!(cap != 37), "test_capacity - 2");

    buf1.ensureCapacity(17);

    // CYGNUS: This is a test for JDK 1.2 conformance
    harness.check(!(buf1.capacity() != 34), "test_capacity - 3");
  }
Exemplo n.º 24
0
  public static int marktest(Reader ins, TestHarness harness) throws IOException {
    BufferedReader br = new BufferedReader(ins, 15);

    int chars_read;
    int total_read = 0;
    char[] buf = new char[12];

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    br.mark(75);
    br.read();
    br.read(buf);
    br.read(buf);
    br.read(buf);
    br.reset();

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    br.mark(555);

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    br.reset();

    br.read(buf);
    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    br.mark(14);

    br.read(buf);

    br.reset();

    chars_read = br.read(buf);
    total_read += chars_read;
    harness.debug(new String(buf, 0, chars_read), false);

    while ((chars_read = br.read(buf)) != -1) {
      harness.debug(new String(buf, 0, chars_read), false);
      total_read += chars_read;
    }

    return (total_read);
  }
Exemplo n.º 25
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // map of declared constructors which should exists
    Map<String, String> testedDeclaredConstructors = null;

    // map of declared constructors for (Open)JDK6
    Map<String, String> testedDeclaredConstructors_jdk6 = new HashMap<String, String>();

    // map of declared constructors for (Open)JDK7
    Map<String, String> testedDeclaredConstructors_jdk7 = new HashMap<String, String>();

    // map for constructors declared in (Open)JDK6
    testedDeclaredConstructors_jdk6.put(
        "public java.lang.TypeNotPresentException(java.lang.String,java.lang.Throwable)",
        "java.lang.TypeNotPresentException");

    // map for constructors declared in (Open)JDK7
    testedDeclaredConstructors_jdk7.put(
        "public java.lang.TypeNotPresentException(java.lang.String,java.lang.Throwable)",
        "java.lang.TypeNotPresentException");

    // create instance of a class TypeNotPresentException
    final Object o = new TypeNotPresentException("TypeNotPresentException", new Throwable());

    // get a runtime class of an object "o"
    final Class c = o.getClass();

    // get the right map containing constructor signatures
    testedDeclaredConstructors =
        getJavaVersion() < 7 ? testedDeclaredConstructors_jdk6 : testedDeclaredConstructors_jdk7;

    // get all declared constructors for this class
    java.lang.reflect.Constructor[] declaredConstructors = c.getDeclaredConstructors();

    // expected number of constructors
    final int expectedNumberOfConstructors = testedDeclaredConstructors.size();

    // basic check for a number of constructors
    harness.check(declaredConstructors.length, expectedNumberOfConstructors);

    // check if all declared constructors exist
    for (java.lang.reflect.Constructor declaredConstructor : declaredConstructors) {
      // constructor name should consists of package name + class name
      String constructorName = declaredConstructor.getName();
      // modifiers + package + class name + parameter types
      String constructorString = declaredConstructor.toString().replaceAll(" native ", " ");
      harness.check(testedDeclaredConstructors.containsKey(constructorString));
      harness.check(testedDeclaredConstructors.get(constructorString), constructorName);
    }
  }
Exemplo n.º 26
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);
   }
 }
Exemplo n.º 27
0
 public void test(TestHarness harness) {
   // test of static method Boolean.parseBoolean()
   harness.check(Boolean.parseBoolean("true"), true);
   harness.check(Boolean.parseBoolean("false"), false);
   harness.check(Boolean.parseBoolean("TRUE"), true);
   harness.check(Boolean.parseBoolean("FALSE"), false);
   harness.check(Boolean.parseBoolean("True"), true);
   harness.check(Boolean.parseBoolean("False"), false);
   harness.check(Boolean.parseBoolean("truE"), true);
   harness.check(Boolean.parseBoolean("falsE"), false);
   harness.check(Boolean.parseBoolean(" true"), false);
   harness.check(Boolean.parseBoolean(" false"), false);
   harness.check(Boolean.parseBoolean(" true "), false);
   harness.check(Boolean.parseBoolean(" false "), false);
 }
Exemplo n.º 28
0
  public void test(TestHarness harness) {
    try {
      harness.debug("First mark/reset test series");
      harness.debug("Underlying reader supports mark/reset");

      String str =
          "Growing up in a rural area brings such delights.  One\n"
              + "time my uncle called me up and asked me to come over and help him\n"
              + "out with something.  Since he lived right across the field, I\n"
              + "walked right over.  Turned out he wanted me to come down to the\n"
              + "barn and help him castrate a calf.  Oh, that was fun.  Not.\n";

      StringReader sr = new StringReader(str);
      BufferedReader br = new BufferedReader(sr);

      int total_read = marktest(br, harness);
      harness.check(total_read, str.length(), "total_read");
    } catch (IOException e) {
      harness.debug(e);
      harness.check(false);
    }

    try {
      harness.debug("Second mark/reset test series");
      harness.debug("Underlying reader does not support mark/reset");

      String str =
          "Growing up we heated our house with a wood stove.  That\n"
              + "thing could pump out some BTU's, let me tell you.  No matter how\n"
              + "cold it got outside, it was always warm inside.  Of course the\n"
              + "downside is that somebody had to chop the wood for the stove. That\n"
              + "somebody was me.  I was slave labor.  My uncle would go back and\n"
              + "chain saw up dead trees and I would load the wood in wagons and\n"
              + "split it with a maul. Somehow my no account brother always seemed\n"
              + "to get out of having to work.\n";

      char[] buf = new char[str.length()];
      str.getChars(0, str.length(), buf, 0);
      MarkReset mr = new MarkReset(buf);
      BufferedReader br = new BufferedReader(mr);

      int total_read = marktest(br, harness);
      harness.check(total_read, str.length(), "total_read");
    } catch (IOException e) {
      harness.debug(e);
      harness.check(false);
    }
  } // main
Exemplo n.º 29
0
  public void test_reverse() {
    StringBuffer buff = new StringBuffer();
    harness.check(!(!buff.reverse().toString().equals("")), "test_reverse - 1");

    buff = new StringBuffer("babu");
    harness.check(!(!buff.reverse().toString().equals("ubab")), "test_reverse - 2");

    buff = new StringBuffer("malayalam");
    harness.check(!(!buff.reverse().toString().equals("malayalam")), "test_reverse - 3");

    buff = new StringBuffer("cnbcbnc");
    harness.check(!(!buff.reverse().toString().equals("cnbcbnc")), "test_reverse - 4");

    buff = new StringBuffer("vinod");
    harness.check(!(!buff.reverse().toString().equals("doniv")), "test_reverse - 5");
  }
Exemplo n.º 30
0
  public void test_equals() {
    Character ch1 = new Character('+');
    Character ch2 = new Character('+');
    Character ch3 = new Character('-');

    harness.check(!(!ch1.equals(ch2) || ch1.equals(ch3) || ch1.equals(null)), "test_equals - 1");
  }