1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ************************************************************************
5 * Copyright (c) 1997-2003, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ************************************************************************
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_NORMALIZATION
17 #include "unicode/normlzr.h"
20 typedef struct _FileStream FileStream;
22 class NormalizerConformanceTest : public IntlTest {
23 Normalizer normalizer;
26 NormalizerConformanceTest();
27 virtual ~NormalizerConformanceTest();
29 void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL);
32 * Test the conformance of Normalizer to
33 * http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt
35 void TestConformance();
36 void TestConformance32();
37 void TestConformance(FileStream *input, int32_t options);
39 // Specific tests for debugging. These are generally failures taken from
40 // the conformance file, but culled out to make debugging easier.
44 FileStream *openNormalizationTestFile(const char *filename);
47 * Verify the conformance of the given line of the Unicode
48 * normalization (UTR 15) test suite file. For each line,
49 * there are five columns, corresponding to field[0]..field[4].
51 * The following invariants must be true for all conformant implementations
52 * c2 == NFC(c1) == NFC(c2) == NFC(c3)
53 * c3 == NFD(c1) == NFD(c2) == NFD(c3)
54 * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5)
55 * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5)
57 * @param field the 5 columns
58 * @param line the source line from the test suite file
59 * @return true if the test passes
61 UBool checkConformance(const UnicodeString* field,
66 void iterativeNorm(const UnicodeString& str,
67 UNormalizationMode mode, int32_t options,
68 UnicodeString& result,
72 * @param op name of normalization form, e.g., "KC"
73 * @param s string being normalized
74 * @param got value received
75 * @param exp expected value
76 * @param msg description of this test
77 * @param return true if got == exp
79 UBool assertEqual(const char *op,
80 const UnicodeString& s,
81 const UnicodeString& got,
82 const UnicodeString& exp,
87 * Split a string into pieces based on the given delimiter
88 * character. Then, parse the resultant fields from hex into
89 * characters. That is, "0040 0400;0C00;0899" -> new String[] {
90 * "\u0040\u0400", "\u0C00", "\u0899" }. The output is assumed to
91 * be of the proper length already, and exactly output.length
92 * fields are parsed. If there are too few an exception is
93 * thrown. If there are too many the extras are ignored.
95 * @param buf scratch buffer
96 * @return FALSE upon failure
98 UBool hexsplit(const char *s, char delimiter,
99 UnicodeString output[], int32_t outputLength);
101 void _testOneLine(const char *line);
102 void compare(const UnicodeString& s1,const UnicodeString& s2);
105 #endif /* #if !UCONFIG_NO_NORMALIZATION */