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