10596faeddefbf198de137d5e893708495ab1584cFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 2001-2009, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This test program is intended for testing error conditions of the 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterator APIs to make sure the exceptions are raised where 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * necessary. 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Date Name Description 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 11/14/2001 hshih Creation. 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ittrans.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "trnserr.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/translit.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uniset.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unifilt.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cpdtrans.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h> 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/rep.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/locid.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//--------------------------------------------- 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// runIndexedTest 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//--------------------------------------------- 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTransliteratorErrorTest::runIndexedTest(int32_t index, UBool exec, 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* &name, char* /*par*/) { 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(0,TestTransliteratorErrors); 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(1, TestUnicodeSetErrors); 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(2, TestRBTErrors); 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TESTCASE(3, TestCoverage); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //TESTCASE(3, TestUniToHexErrors); 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //TESTCASE(4, TestHexToUniErrors); 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // TODO: Add a subclass to test clone(). 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: name = ""; break; 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorErrorTest::TestTransliteratorErrors() { 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString trans="Latin-Greek"; 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString bogusID="LATINGREEK-GREEKLATIN"; 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newID="Bogus-Latin"; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newIDRules="zzz > Z; f <> ph"; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString bogusRules="a } [b-g m-p "; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError parseError; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString testString="A quick fox jumped over the lazy dog."; 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString insertString="cats and dogs"; 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t stoppedAt = 0, len; 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTransPosition pos; 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t= Transliterator::createInstance(trans, UTRANS_FORWARD, parseError, status); 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(t==0 || U_FAILURE(status)){ 6885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho dataerrln("FAIL: construction of Latin-Greek - %s", u_errorName(status)); 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextLimit = 0; 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextStart = 0; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.limit = 0; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 0; 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = testString.length(); 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru stoppedAt = t->transliterate(testString, 0, 100); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (stoppedAt != -1) { 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Out of bounds check failed (1)."); 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if (testString.length() != len) { 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString="A quick fox jumped over the lazy dog."; 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Transliterate fails and the target string was modified."); 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru stoppedAt = t->transliterate(testString, 100, testString.length()-1); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (stoppedAt != -1) 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Out of bounds check failed (2)."); 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if (testString.length() != len) { 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString="A quick fox jumped over the lazy dog."; 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Transliterate fails and the target string was modified."); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 100; 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.limit = testString.length(); 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t->transliterate(testString, pos, status); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Start offset is out of bounds, error not reported.\n"); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.limit = 100; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 0; 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t->transliterate(testString, pos, status); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Limit offset is out of bounds, error not reported.\n"); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = pos.contextLimit = testString.length(); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextStart = 0; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.limit = len - 1; 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 5; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t->transliterate(testString, pos, insertString, status); 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (len == pos.limit) { 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Test insertion with string: the transliteration position limit didn't change as expected."); 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Error code wasn't set either."); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextStart = 0; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextLimit = testString.length(); 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.limit = testString.length() -1; 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 5; 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t->transliterate(testString, pos, (UChar32)0x0061, status); 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (len == pos.limit) { 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Test insertion with character: the transliteration position limit didn't change as expected."); 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Error code wasn't set either."); 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len = pos.limit = testString.length(); 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextStart = 0; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.contextLimit = testString.length() - 1; 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos.start = 5; 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t->transliterate(testString, pos, insertString, status); 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Out of bounds check failed (3)."); 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (testString.length() != len) 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The input string was modified though the offsets were out of bounds."); 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t1= Transliterator::createInstance(bogusID, UTRANS_FORWARD, parseError, status); 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(t1!=0 || U_SUCCESS(status)){ 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t1; 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: construction of bogus ID \"LATINGREEK-GREEKLATIN\""); 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t2 = Transliterator::createFromRules(newID, newIDRules, UTRANS_FORWARD, parseError, status); 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t3 = t2->createInverse(status); 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t3; 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The newID transliterator was not registered so createInverse should fail."); 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t3; 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t4 = Transliterator::createFromRules(newID, bogusRules, UTRANS_FORWARD, parseError, status); 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (t4 != NULL || U_SUCCESS(status)) { 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The rules is malformed but error was not reported."); 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (parseError.offset != -1) { 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The parse error offset isn't set correctly when fails."); 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if (parseError.postContext[0] == 0 || parseError.preContext[0] == 0) { 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The parse error pre/post context isn't reset properly."); 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t4; 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t; 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t2; 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorErrorTest::TestUnicodeSetErrors() { 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString badPattern="[[:L:]-[0x0300-0x0400]"; 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeSet set; 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString result; 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!set.isEmpty()) { 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: The default ctor of UnicodeSet created a non-empty object."); 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru set.applyPattern(badPattern, status); 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Applied a bad pattern to the UnicodeSet object okay."); 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeSet *set1 = new UnicodeSet(badPattern, status); 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Created a UnicodeSet based on bad patterns."); 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete set1; 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//void TransliteratorErrorTest::TestUniToHexErrors() { 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// UErrorCode status = U_ZERO_ERROR; 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Transliterator *t = new UnicodeToHexTransliterator("", TRUE, NULL, status); 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_SUCCESS(status)) { 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: Created a UnicodeToHexTransliterator with an empty pattern."); 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// status = U_ZERO_ERROR; 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// t = new UnicodeToHexTransliterator("\\x", TRUE, NULL, status); 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_SUCCESS(status)) { 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: Created a UnicodeToHexTransliterator with a bad pattern."); 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// status = U_ZERO_ERROR; 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// t = new UnicodeToHexTransliterator(); 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// ((UnicodeToHexTransliterator*)t)->applyPattern("\\x", status); 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_SUCCESS(status)) { 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: UnicodeToHexTransliterator::applyPattern succeeded with a bad pattern."); 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//} 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorErrorTest::TestRBTErrors() { 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString rules="ab>y"; 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString id="MyRandom-YReverse"; 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //UnicodeString goodPattern="[[:L:]&[\\u0000-\\uFFFF]]"; /* all BMP letters */ 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError parseErr; 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*UnicodeSet *set = new UnicodeSet(goodPattern, status); 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Was not able to create a good UnicodeSet based on valid patterns."); 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }*/ 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator *t = Transliterator::createFromRules(id, rules, UTRANS_REVERSE, parseErr, status); 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: Was not able to create a good RBT to test registration."); 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //delete set; 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator::registerInstance(t); 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator::unregister(id); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Transliterator* t1= Transliterator::createInstance(id, UTRANS_REVERSE, parseErr, status); 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete t1; 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: construction of unregistered ID failed."); 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//void TransliteratorErrorTest::TestHexToUniErrors() { 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// UErrorCode status = U_ZERO_ERROR; 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Transliterator *t = new HexToUnicodeTransliterator("", NULL, status); 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_FAILURE(status)) { 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: Could not create a HexToUnicodeTransliterator with an empty pattern."); 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// status = U_ZERO_ERROR; 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// t = new HexToUnicodeTransliterator("\\x", NULL, status); 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_SUCCESS(status)) { 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: Created a HexToUnicodeTransliterator with a bad pattern."); 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// status = U_ZERO_ERROR; 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// t = new HexToUnicodeTransliterator(); 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// ((HexToUnicodeTransliterator*)t)->applyPattern("\\x", status); 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// if (U_SUCCESS(status)) { 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// errln("FAIL: HexToUnicodeTransliterator::applyPattern succeeded with a bad pattern."); 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// } 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// delete t; 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//} 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass StubTransliterator: public Transliterator{ 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru StubTransliterator(): Transliterator(UNICODE_STRING_SIMPLE("Any-Null"), 0) {} 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void handleTransliterate(Replaceable& ,UTransPosition& offsets,UBool) const { 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru offsets.start = offsets.limit; 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID() const{ 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static char classID = 0; 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (UClassID)&classID; 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorErrorTest::TestCoverage() { 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru StubTransliterator stub; 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (stub.clone() != NULL){ 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("FAIL: default Transliterator::clone() should return NULL"); 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */ 286