/** * Verify the conformance of the given line of the Unicode * normalization (UTR 15) test suite file. For each line, * there are five columns, corresponding to field[0]..field[4]. * * The following invariants must be true for all conformant implementations * c2 == NFC(c1) == NFC(c2) == NFC(c3) * c3 == NFD(c1) == NFD(c2) == NFD(c3) * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) * * @param field the 5 columns * @param line the source line from the test suite file * @return true if the test passes */ private bool checkConformance(string[] field, string line) { bool pass = true; // StringBuffer buf = new StringBuffer(); // scratch string @out; int i = 0; for (i = 0; i < 5; ++i) { if (i < 3) { @out = normalizer_C.normalize(field[i]); pass &= assertEqual("C", field[i], @out, field[1], "c2!=C(c" + (i + 1)); @out = normalizer_D.normalize(field[i]); pass &= assertEqual("D", field[i], @out, field[2], "c3!=D(c" + (i + 1)); } @out = normalizer_KC.normalize(field[i]); pass &= assertEqual("KC", field[i], @out, field[3], "c4!=KC(c" + (i + 1)); @out = normalizer_KD.normalize(field[i]); pass &= assertEqual("KD", field[i], @out, field[4], "c5!=KD(c" + (i + 1)); } if (!pass) { Errln("FAIL: " + line); } return(pass); }
public void TestNormalize() { if (unicode_NFD == null) { try { unicode_NFD = new UnicodeNormalizer(UnicodeNormalizer.D, true); unicode_NFC = new UnicodeNormalizer(UnicodeNormalizer.C, true); unicode_NFKD = new UnicodeNormalizer(UnicodeNormalizer.KD, true); unicode_NFKC = new UnicodeNormalizer(UnicodeNormalizer.KC, true); } catch (Exception e) { Errln("Normalization tests could not be run: " + e.ToString()); } } int i = 0; while (i < loopCount) { String source = GetTestSource(); Logln("Test source:" + source); //NFD String uncodeNorm = unicode_NFD.normalize(source); String icuNorm = Normalizer.Normalize(source, Normalizer.NFD); Logln("\tNFD(Unicode): " + uncodeNorm); Logln("\tNFD(icu4j) : " + icuNorm); if (!uncodeNorm.Equals(icuNorm)) { Errln("NFD: Unicode sample output => " + uncodeNorm + "; icu4j output=> " + icuNorm); } //NFC uncodeNorm = unicode_NFC.normalize(source); icuNorm = Normalizer.Normalize(source, Normalizer.NFC); Logln("\tNFC(Unicode): " + uncodeNorm); Logln("\tNFC(icu4j) : " + icuNorm); if (!uncodeNorm.Equals(icuNorm)) { Errln("NFC: Unicode sample output => " + uncodeNorm + "; icu4j output=> " + icuNorm); } //NFKD uncodeNorm = unicode_NFKD.normalize(source); icuNorm = Normalizer.Normalize(source, Normalizer.NFKD); Logln("\tNFKD(Unicode): " + uncodeNorm); Logln("\tNFKD(icu4j) : " + icuNorm); if (!uncodeNorm.Equals(icuNorm)) { Errln("NFKD: Unicode sample output => " + uncodeNorm + "; icu4j output=> " + icuNorm); } //NFKC uncodeNorm = unicode_NFKC.normalize(source); icuNorm = Normalizer.Normalize(source, Normalizer.NFKC); Logln("\tNFKC(Unicode): " + uncodeNorm); Logln("\tNFKC(icu4j) : " + icuNorm); if (!uncodeNorm.Equals(icuNorm)) { Errln("NFKC: Unicode sample output => " + uncodeNorm + "; icu4j output=> " + icuNorm); } i++; } }