1 // Copyright (C) 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: US-ASCII 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); 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 static NamePrepTransform* getInstance(UErrorCode& status); 70 static NamePrepTransform* gPrep; 71 virtual ~TestIDNA(); 72 73 private: 74 void testToASCII(const char* testName, TestFunc func); 75 void testToUnicode(const char* testName, TestFunc func); 76 void testIDNToUnicode(const char* testName, TestFunc func); 77 void testIDNToASCII(const char* testName, TestFunc func); 78 void testCompare(const char* testName, CompareFunc func); 79 void testChaining(const char* toASCIIName, TestFunc toASCII, 80 const char* toUnicodeName, TestFunc toUnicode); 81 void debug(const UChar* src, int32_t srcLength, int32_t options); 82 // main testing functions 83 void testAPI(const UChar *src, const UChar *expected, const char *testName, 84 UBool useSTD3ASCIIRules, UErrorCode expectedStatus, 85 UBool doCompare, UBool testUnassigned, TestFunc func, UBool testSTD3ASCIIRules=TRUE); 86 87 void testCompare(const UChar* s1, int32_t s1Len, 88 const UChar* s2, int32_t s2Len, 89 const char* testName, CompareFunc func, 90 UBool isEqual); 91 92 void testErrorCases(const char* IDNToASCIIName, TestFunc IDNToASCII, 93 const char* IDNToUnicodeName, TestFunc IDNToUnicode); 94 95 void testChaining(const UChar* src,int32_t numIterations,const char* testName, 96 UBool useSTD3ASCIIRules, UBool caseInsensitive, TestFunc func); 97 98 void testRootLabelSeparator(const char* testName, CompareFunc func, 99 const char* IDNToASCIIName, TestFunc IDNToASCII, 100 const char* IDNToUnicodeName, TestFunc IDNToUnicode); 101 102 void testCompareReferenceImpl(const UChar* src, int32_t srcLen); 103 104 UnicodeString testCompareReferenceImpl(UnicodeString& src, 105 TestFunc refIDNA, const char* refIDNAName, 106 TestFunc uIDNA, const char* uIDNAName, 107 int32_t options); 108 109 void testConformance(const char* toASCIIName, TestFunc toASCII, 110 const char* IDNToASCIIName, TestFunc IDNToASCII, 111 const char* IDNToUnicodeName, TestFunc IDNToUnicode, 112 const char* toUnicodeName, TestFunc toUnicode 113 ); 114 115 }; 116 117 // test the TRIE data structure 118 int testData(TestIDNA& test); 119 120 #endif /* #if !UCONFIG_NO_IDNA */ 121 122 #endif 123