1 23 24 package org.enhydra.xml.io; 25 26 import java.io.File ; 27 import java.io.FileWriter ; 28 import java.io.IOException ; 29 import java.io.PrintWriter ; 30 import java.io.UnsupportedEncodingException ; 31 import java.lang.reflect.Method ; 32 33 import junit.framework.Test; 34 35 import org.enhydra.xml.driver.TestException; 36 37 40 public class EncodingTests extends IOTestCaseBase { 41 42 private static final String MISSING_ENCODINGS_EXT 43 = "missing.encodings"; 44 45 49 private static final String [] JAVA_ENCODINGS = { 50 "ASCII", "Cp1252", "ISO8859_1", "UnicodeBig", "UnicodeBigUnmarked", 51 "UnicodeLittle", "UnicodeLittleUnmarked", "UTF-8", "UTF-16", 52 "Big5", "Cp037", "Cp273", "Cp277", "Cp278", 53 "Cp280", "Cp284", "Cp285", "Cp297", "Cp420", "Cp424", "Cp437", "Cp500", 54 "Cp737", "Cp775", "Cp838", "Cp850", "Cp852", "Cp855", "Cp856", "Cp857", 55 "Cp858", "Cp860", "Cp861", "Cp862", "Cp863", "Cp864", "Cp865", "Cp866", 56 "Cp868", "Cp869", "Cp870", "Cp871", "Cp874", "Cp875", "Cp918", "Cp921", 57 "Cp922", "Cp930", "Cp933", "Cp935", "Cp937", "Cp939", "Cp942", "Cp942C", 58 "Cp943", "Cp943C", "Cp948", "Cp949", "Cp949C", "Cp950", "Cp964", "Cp970", 59 "Cp1006", "Cp1025", "Cp1026", "Cp1046", "Cp1097", "Cp1098", "Cp1112", 60 "Cp1122", "Cp1123", "Cp1124", "Cp1140", "Cp1141", "Cp1142", "Cp1143", 61 "Cp1144", "Cp1145", "Cp1146", "Cp1147", "Cp1148", "Cp1149", "Cp1250", 62 "Cp1251", "Cp1253", "Cp1254", "Cp1255", "Cp1256", "Cp1257", "Cp1258", 63 "Cp1381", "Cp1383", "Cp33722", "EUC_CN", "EUC_JP", "EUC_KR", "EUC_TW", 64 "GBK", "ISO2022CN", "ISO2022CN_CNS", "ISO2022CN_GB", "ISO2022JP", 65 "ISO2022KR", "ISO8859_2", "ISO8859_3", "ISO8859_4", "ISO8859_5", 66 "ISO8859_6", "ISO8859_7", "ISO8859_8", "ISO8859_9", "ISO8859_13", 67 "ISO8859_15_FDIS", "JIS0201", "JIS0208", "JIS0212", "JISAutoDetect", 68 "Johab", "KOI8_R", "MS874", "MS932", "MS936", "MS949", "MS950", 69 "MacArabic", "MacCentralEurope", "MacCroatian", "MacCyrillic", 70 "MacDingbat", "MacGreek", "MacHebrew", "MacIceland", "MacRoman", 71 "MacRomania", "MacSymbol", "MacThai", "MacTurkish", "MacUkraine", "SJIS", 72 "TIS620" 73 }; 74 75 76 private int fUnknownEncodingCnt = 0; 77 78 79 public static Test suite() { 80 return createSuite(EncodingTests.class, null); 81 } 82 83 84 public EncodingTests(Method method) { 85 super(method); 86 } 87 88 91 private void checkEncodingConvert(String encoding) { 92 try { 93 String data = "This is a test"; 94 byte[] b = data.getBytes(encoding); 95 } catch (UnsupportedEncodingException uee) { 96 msgPrintln("Note: encoding not supported by this JVM: " + encoding); 97 } 98 } 99 100 103 private void testEncoding(String encoding, 104 PrintWriter out) { 105 Encodings encodings = Encodings.getEncodings(); 106 if (!encodings.isValid(encoding)) { 107 out.println("No entry for \"" + encoding + "\""); 108 fUnknownEncodingCnt++; 109 } 110 checkEncodingConvert(encoding); 111 112 String mimePrefered = encodings.getMIMEPreferred(encoding); 114 if (mimePrefered != null) { 115 checkEncodingConvert(mimePrefered); 116 } 117 } 118 119 123 public void test1() { 124 File resultFile = getResultFile(MISSING_ENCODINGS_EXT); 125 try { 126 PrintWriter out = new PrintWriter (new FileWriter (resultFile)); 127 try { 128 for (int i = 0; i < JAVA_ENCODINGS.length; i++) { 129 testEncoding(JAVA_ENCODINGS[i], out); 130 } 131 out.println("" + fUnknownEncodingCnt 132 + " encodings not known to XMLC tables"); 133 } finally { 134 out.close(); 135 } 136 } catch (IOException except) { 137 throw new TestException(except); 138 } 139 140 getDiffer().diff(getExpectedFile(MISSING_ENCODINGS_EXT), 141 resultFile); 142 } 143 } 144 145 | Popular Tags |