1 // © 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/normalizer2.h"
18 #include "unicode/normlzr.h"
21 typedef struct _FileStream FileStream
;
23 class NormalizerConformanceTest
: public IntlTest
{
24 Normalizer normalizer
;
25 const Normalizer2
*nfc
, *nfd
, *nfkc
, *nfkd
;
28 NormalizerConformanceTest();
29 virtual ~NormalizerConformanceTest();
31 void runIndexedTest(int32_t index
, UBool exec
, const char* &name
, char* par
=NULL
);
34 * Test the conformance of Normalizer to
35 * http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt
37 void TestConformance();
38 void TestConformance32();
39 void TestConformance(FileStream
*input
, int32_t options
);
41 // Specific tests for debugging. These are generally failures taken from
42 // the conformance file, but culled out to make debugging easier.
46 FileStream
*openNormalizationTestFile(const char *filename
);
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].
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)
59 * @param field the 5 columns
60 * @param line the source line from the test suite file
61 * @return true if the test passes
63 UBool
checkConformance(const UnicodeString
* field
,
68 UBool
checkNorm(UNormalizationMode mode
, int32_t options
,
69 const Normalizer2
*norm2
,
70 const UnicodeString
&s
, const UnicodeString
&exp
,
73 void iterativeNorm(const UnicodeString
& str
,
74 UNormalizationMode mode
, int32_t options
,
75 UnicodeString
& result
,
79 * @param op name of normalization form, e.g., "KC"
80 * @param op2 name of test case variant, e.g., "(-1)"
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
87 UBool
assertEqual(const char *op
, const char *op2
,
88 const UnicodeString
& s
,
89 const UnicodeString
& got
,
90 const UnicodeString
& exp
,
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.
102 * @param buf scratch buffer
103 * @return FALSE upon failure
105 UBool
hexsplit(const char *s
, char delimiter
,
106 UnicodeString output
[], int32_t outputLength
);
108 void _testOneLine(const char *line
);
109 void compare(const UnicodeString
& s1
,const UnicodeString
& s2
);
112 #endif /* #if !UCONFIG_NO_NORMALIZATION */