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() + ")."); }
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."); }
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); }
/** * 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); }
/** * 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); }
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"); }
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"); }
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); }
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); } }
/** * 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"); }
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); }
/** * 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); }
/** * 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); }
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"); }
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()); }
/** * 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); } }
/** implemented. */ public void test_propertyNames() { th.checkPoint("propertyNames()java.util.Enumeration"); Properties p = new Properties(); try { p.load(bin); } catch (Exception e) { } Enumeration en = p.propertyNames(); Enumeration ek = p.keys(); boolean ok = true; Vector v = new Vector(); Enumeration ek2 = p.keys(); while (ek2.hasMoreElements()) { v.add(ek2.nextElement()); } while (ek.hasMoreElements() && en.hasMoreElements()) { ek.nextElement(); Object next = en.nextElement(); if (!v.contains(next)) { ok = false; th.debug(next + " not in " + v); } } th.check(ok, "all elements are the same"); th.check( !ek.hasMoreElements() && !en.hasMoreElements(), "make sure both enumerations are empty"); p = new Properties(defProps); resetStreams(); try { p.load(bin); } catch (Exception e) { } v.add("Smart"); v.add("animal"); en = p.propertyNames(); ok = true; Object o; while (en.hasMoreElements()) { o = en.nextElement(); if (v.contains(o)) v.removeElement(o); else { ok = false; th.debug("got extra element: " + o); } } th.check(ok, "see if no double were generated"); th.check(v.isEmpty(), "check if all names were mentioned -- got:" + v); }
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"); } }
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); }
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
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); }
public void test(TestHarness h) { // Check #1. Throwable caught = null; try { new TestProvider().getFormatNames(); } catch (Exception ex) { caught = ex; } h.check(caught instanceof NullPointerException); // Check #2. h.check(Arrays.equals(TestProvider.createProvider().getFormatNames(), TestProvider.NAMES)); // Check #3. h.check(TestProvider.createProvider().getFormatNames() != TestProvider.NAMES); }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { // map of fields which should exists Map<String, String> testedFields = null; // map of fields for (Open)JDK6 Map<String, String> testedFields_jdk6 = new HashMap<String, String>(); // map of fields for (Open)JDK7 Map<String, String> testedFields_jdk7 = new HashMap<String, String>(); // map for fields declared in (Open)JDK6 // --- empty --- // map for fields declared in (Open)JDK7 // --- empty --- // create instance of a class UnsupportedOperationException final Object o = new UnsupportedOperationException("java.lang.UnsupportedOperationException"); // get a runtime class of an object "o" final Class c = o.getClass(); // get the right map containing field signatures testedFields = getJavaVersion() < 7 ? testedFields_jdk6 : testedFields_jdk7; // get all fields for this class java.lang.reflect.Field[] fields = c.getFields(); // expected number of fields final int expectedNumberOfFields = testedFields.size(); // basic check for a number of fields harness.check(fields.length, expectedNumberOfFields); }
/** * 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); } }
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"); }
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"); }
public void test(TestHarness h) { IIOByteBuffer buf; byte[] b1 = new byte[] {1, 2, 3}; // Check #1. buf = new IIOByteBuffer(b1, 0, 1); buf.setLength(2); h.check(buf.getLength(), 2); // Check #2: Length greater than array length. buf.setLength(99); h.check(buf.getLength(), 99); // Check #3: Length negative. buf.setLength(-42); h.check(buf.getLength(), -42); }
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"); } }
/** * 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 UnsupportedOperationException final Object o = new UnsupportedOperationException("java.lang.UnsupportedOperationException"); // get a runtime class of an object "o" final Class c = o.getClass(); harness.check(c.getSimpleName(), "UnsupportedOperationException"); }
/** * 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 Double Object o = new StringBuilder("xyzzy"); // get a runtime class of an object "o" Class c = o.getClass(); harness.check(c.getName(), "java.lang.StringBuilder"); }