changeset 4143:36dd30b5f85d

7040572: Fix broken java/nio/charset/StandardCharset/Standard.java and add more tests. Reviewed-by: alanb
author mduigou
date Fri, 29 Apr 2011 14:09:46 -0700
parents 40e2b3a25533
children ca58907a51f7
files test/java/nio/charset/StandardCharset/Standard.java
diffstat 1 files changed, 39 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/charset/StandardCharset/Standard.java	Fri Apr 29 13:31:13 2011 -0700
+++ b/test/java/nio/charset/StandardCharset/Standard.java	Fri Apr 29 14:09:46 2011 -0700
@@ -29,10 +29,20 @@
  * @run main Standard
  */
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.io.*;
 import java.nio.charset.*;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 public class Standard {
 
+    private final static String standardCharsets[] = {
+        "US-ASCII", "ISO-8859-1", "UTF-8",
+        "UTF-16BE", "UTF-16LE", "UTF-16" };
+
     public static void realMain(String[] args) {
         check(StandardCharset.US_ASCII instanceof Charset);
         check(StandardCharset.ISO_8859_1 instanceof Charset);
@@ -41,12 +51,35 @@
         check(StandardCharset.UTF_16LE instanceof Charset);
         check(StandardCharset.UTF_16 instanceof Charset);
 
-        check("US-ASCII".equals(StandardCharset.US_ASCII.name());
-        check("ISO-8859-1".equals(StandardCharset.ISO_8859_1.name());
-        check("UTF-8".equals(StandardCharset.UTF_8.name());
-        check("UTF-16BE".equals(StandardCharset.UTF_16BE.name());
-        check("UTF-16LE".equals(StandardCharset.UTF_16LE.name());
-        check("UTF-16".equals(StandardCharset.UTF_16.name());
+        check("US-ASCII".equals(StandardCharset.US_ASCII.name()));
+        check("ISO-8859-1".equals(StandardCharset.ISO_8859_1.name()));
+        check("UTF-8".equals(StandardCharset.UTF_8.name()));
+        check("UTF-16BE".equals(StandardCharset.UTF_16BE.name()));
+        check("UTF-16LE".equals(StandardCharset.UTF_16LE.name()));
+        check("UTF-16".equals(StandardCharset.UTF_16.name()));
+
+        Set<String> charsets = new HashSet<>();
+        Field standardCharsetFields[] = StandardCharset.class.getFields();
+
+        for(Field charsetField : standardCharsetFields) {
+            check(StandardCharset.class == charsetField.getDeclaringClass());
+            check(Modifier.isFinal(charsetField.getModifiers()));
+            check(Modifier.isStatic(charsetField.getModifiers()));
+            check(Modifier.isPublic(charsetField.getModifiers()));
+            Object value;
+            try {
+                value = charsetField.get(null);
+            } catch(IllegalAccessException failure) {
+                unexpected(failure);
+                continue;
+            }
+            check(value instanceof Charset);
+            charsets.add(((Charset)value).name());
+        }
+
+        check(charsets.containsAll(Arrays.asList(standardCharsets)));
+        charsets.removeAll(Arrays.asList(standardCharsets));
+        check(charsets.isEmpty());
     }
 
     //--------------------- Infrastructure ---------------------------