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