]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ************************************************************************ | |
5 | * Copyright (c) 1997-2003, International Business Machines | |
6 | * Corporation and others. All Rights Reserved. | |
7 | ************************************************************************ | |
8 | */ | |
9 | ||
10 | #ifndef _NORMCONF | |
11 | #define _NORMCONF | |
12 | ||
13 | #include "unicode/utypes.h" | |
14 | ||
15 | #if !UCONFIG_NO_NORMALIZATION | |
16 | ||
0f5d89e8 | 17 | #include "unicode/normalizer2.h" |
b75a7d8f A |
18 | #include "unicode/normlzr.h" |
19 | #include "intltest.h" | |
20 | ||
21 | typedef struct _FileStream FileStream; | |
22 | ||
23 | class NormalizerConformanceTest : public IntlTest { | |
24 | Normalizer normalizer; | |
0f5d89e8 | 25 | const Normalizer2 *nfc, *nfd, *nfkc, *nfkd; |
b75a7d8f A |
26 | |
27 | public: | |
28 | NormalizerConformanceTest(); | |
29 | virtual ~NormalizerConformanceTest(); | |
30 | ||
31 | void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL); | |
32 | ||
33 | /** | |
34 | * Test the conformance of Normalizer to | |
35 | * http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt | |
36 | */ | |
37 | void TestConformance(); | |
38 | void TestConformance32(); | |
39 | void TestConformance(FileStream *input, int32_t options); | |
40 | ||
41 | // Specific tests for debugging. These are generally failures taken from | |
42 | // the conformance file, but culled out to make debugging easier. | |
43 | void TestCase6(void); | |
44 | ||
45 | private: | |
46 | FileStream *openNormalizationTestFile(const char *filename); | |
47 | ||
48 | /** | |
49 | * Verify the conformance of the given line of the Unicode | |
50 | * normalization (UTR 15) test suite file. For each line, | |
51 | * there are five columns, corresponding to field[0]..field[4]. | |
52 | * | |
53 | * The following invariants must be true for all conformant implementations | |
54 | * c2 == NFC(c1) == NFC(c2) == NFC(c3) | |
55 | * c3 == NFD(c1) == NFD(c2) == NFD(c3) | |
56 | * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) | |
57 | * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) | |
58 | * | |
59 | * @param field the 5 columns | |
60 | * @param line the source line from the test suite file | |
61 | * @return true if the test passes | |
62 | */ | |
63 | UBool checkConformance(const UnicodeString* field, | |
64 | const char *line, | |
65 | int32_t options, | |
66 | UErrorCode &status); | |
67 | ||
0f5d89e8 A |
68 | UBool checkNorm(UNormalizationMode mode, int32_t options, |
69 | const Normalizer2 *norm2, | |
70 | const UnicodeString &s, const UnicodeString &exp, | |
71 | int32_t field); | |
72 | ||
b75a7d8f A |
73 | void iterativeNorm(const UnicodeString& str, |
74 | UNormalizationMode mode, int32_t options, | |
75 | UnicodeString& result, | |
76 | int8_t dir); | |
77 | ||
78 | /** | |
79 | * @param op name of normalization form, e.g., "KC" | |
0f5d89e8 | 80 | * @param op2 name of test case variant, e.g., "(-1)" |
b75a7d8f A |
81 | * @param s string being normalized |
82 | * @param got value received | |
83 | * @param exp expected value | |
84 | * @param msg description of this test | |
85 | * @param return true if got == exp | |
86 | */ | |
0f5d89e8 | 87 | UBool assertEqual(const char *op, const char *op2, |
b75a7d8f A |
88 | const UnicodeString& s, |
89 | const UnicodeString& got, | |
90 | const UnicodeString& exp, | |
0f5d89e8 | 91 | const char *msg); |
b75a7d8f A |
92 | |
93 | /** | |
94 | * Split a string into pieces based on the given delimiter | |
95 | * character. Then, parse the resultant fields from hex into | |
96 | * characters. That is, "0040 0400;0C00;0899" -> new String[] { | |
97 | * "\u0040\u0400", "\u0C00", "\u0899" }. The output is assumed to | |
98 | * be of the proper length already, and exactly output.length | |
99 | * fields are parsed. If there are too few an exception is | |
100 | * thrown. If there are too many the extras are ignored. | |
101 | * | |
102 | * @param buf scratch buffer | |
103 | * @return FALSE upon failure | |
104 | */ | |
105 | UBool hexsplit(const char *s, char delimiter, | |
106 | UnicodeString output[], int32_t outputLength); | |
107 | ||
108 | void _testOneLine(const char *line); | |
109 | void compare(const UnicodeString& s1,const UnicodeString& s2); | |
110 | }; | |
111 | ||
112 | #endif /* #if !UCONFIG_NO_NORMALIZATION */ | |
113 | ||
114 | #endif |