1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  *
6  *   Copyright (C) 2003-2006, International Business Machines
7  *   Corporation and others.  All Rights Reserved.
8  *
9  *******************************************************************************
10  *   file name:  testidna.h
11  *   encoding:   UTF-8
12  *   tab size:   8 (not used)
13  *   indentation:4
14  *
15  *   created on: 2003feb1
16  *   created by: Ram Viswanadha
17  */
18 
19 #ifndef TESTIDNA_H
20 #define TESTIDNA_H
21 
22 #include "unicode/utypes.h"
23 
24 #if !UCONFIG_NO_IDNA && !UCONFIG_NO_TRANSLITERATION
25 
26 #include "intltest.h"
27 #include "unicode/parseerr.h"
28 #include "unicode/uidna.h"
29 
30 U_CDECL_BEGIN
31 typedef int32_t
32 (U_EXPORT2 *TestFunc) (   const UChar *src, int32_t srcLength,
33                 UChar *dest, int32_t destCapacity,
34                 int32_t options, UParseError *parseError,
35                 UErrorCode *status);
36 typedef int32_t
37 (U_EXPORT2 *CompareFunc) (const UChar *s1, int32_t s1Len,
38                 const UChar *s2, int32_t s2Len,
39                 int32_t options,
40                 UErrorCode *status);
41 
42 
43 U_CDECL_END
44 
45 // test the API
46 
47 class NamePrepTransform;
48 
49 /**
50  * @test
51  * @summary General test of HexadecimalToUnicodeTransliterator
52  */
53 class TestIDNA : public IntlTest {
54 public:
55     void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL) override;
56     void TestDataFile();
57     void TestToASCII();
58     void TestToUnicode();
59     void TestIDNToUnicode();
60     void TestIDNToASCII();
61     void TestCompare();
62     void TestErrorCases();
63     void TestChaining();
64     void TestRootLabelSeparator();
65     void TestCompareReferenceImpl();
66     void TestRefIDNA();
67     void TestIDNAMonkeyTest();
68     void TestConformance();
69     NamePrepTransform* getInstance(UErrorCode& status);
70     NamePrepTransform* gPrep;
TestIDNA()71     TestIDNA() : gPrep(nullptr) {}
72     virtual ~TestIDNA();
73 
74 private:
75     void testToASCII(const char* testName, TestFunc func);
76     void testToUnicode(const char* testName, TestFunc func);
77     void testIDNToUnicode(const char* testName, TestFunc func);
78     void testIDNToASCII(const char* testName, TestFunc func);
79     void testCompare(const char* testName, CompareFunc func);
80     void testChaining(const char* toASCIIName, TestFunc toASCII,
81                     const char* toUnicodeName, TestFunc toUnicode);
82     void debug(const UChar* src, int32_t srcLength, int32_t options);
83     // main testing functions
84     void testAPI(const UChar *src, const UChar *expected, const char *testName,
85              UBool useSTD3ASCIIRules, UErrorCode expectedStatus,
86              UBool doCompare, UBool testUnassigned, TestFunc func, UBool testSTD3ASCIIRules=TRUE);
87 
88     void testCompare(const UChar* s1, int32_t s1Len,
89                         const UChar* s2, int32_t s2Len,
90                         const char* testName, CompareFunc func,
91                         UBool isEqual);
92 
93     void testErrorCases(const char* IDNToASCIIName, TestFunc IDNToASCII,
94                     const char* IDNToUnicodeName, TestFunc IDNToUnicode);
95 
96     void testChaining(const UChar* src,int32_t numIterations,const char* testName,
97                   UBool useSTD3ASCIIRules, UBool caseInsensitive, TestFunc func);
98 
99     void testRootLabelSeparator(const char* testName, CompareFunc func,
100                             const char* IDNToASCIIName, TestFunc IDNToASCII,
101                             const char* IDNToUnicodeName, TestFunc IDNToUnicode);
102 
103     void testCompareReferenceImpl(const UChar* src, int32_t srcLen);
104 
105     UnicodeString testCompareReferenceImpl(UnicodeString& src,
106                                 TestFunc refIDNA, const char* refIDNAName,
107                                 TestFunc uIDNA, const char* uIDNAName,
108                                 int32_t options);
109 
110     void testConformance(const char* toASCIIName, TestFunc toASCII,
111                          const char* IDNToASCIIName, TestFunc IDNToASCII,
112                          const char* IDNToUnicodeName, TestFunc IDNToUnicode,
113                          const char* toUnicodeName, TestFunc toUnicode
114                          );
115 
116 };
117 
118 // test the TRIE data structure
119 int testData(TestIDNA& test);
120 
121 #endif /* #if !UCONFIG_NO_IDNA */
122 
123 #endif
124