Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: source/test/cintltst/utransts.c

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/cintltst/utmstest.c ('k') | source/test/depstest/dependencies.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ******************************************************************************* 2 *******************************************************************************
3 * Copyright (C) 1997-2009, International Business Machines 3 * Copyright (C) 1997-2009,2014 International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 * Date Name Description 6 * Date Name Description
7 * 06/23/00 aliu Creation. 7 * 06/23/00 aliu Creation.
8 ******************************************************************************* 8 *******************************************************************************
9 */ 9 */
10 10
11 #include "unicode/utypes.h" 11 #include "unicode/utypes.h"
12 12
13 #if !UCONFIG_NO_TRANSLITERATION 13 #if !UCONFIG_NO_TRANSLITERATION
14 14
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <string.h> 16 #include <string.h>
17 #include "unicode/utrans.h" 17 #include "unicode/utrans.h"
18 #include "unicode/ustring.h" 18 #include "unicode/ustring.h"
19 #include "unicode/uset.h"
19 #include "cintltst.h" 20 #include "cintltst.h"
20 21
21 #define TEST(x) addTest(root, &x, "utrans/" # x) 22 #define TEST(x) addTest(root, &x, "utrans/" # x)
22 23
23 static void TestAPI(void); 24 static void TestAPI(void);
24 static void TestSimpleRules(void); 25 static void TestSimpleRules(void);
25 static void TestFilter(void); 26 static void TestFilter(void);
26 static void TestOpenInverse(void); 27 static void TestOpenInverse(void);
27 static void TestClone(void); 28 static void TestClone(void);
28 static void TestRegisterUnregister(void); 29 static void TestRegisterUnregister(void);
29 static void TestExtractBetween(void); 30 static void TestExtractBetween(void);
30 static void TestUnicodeIDs(void); 31 static void TestUnicodeIDs(void);
32 static void TestGetRulesAndSourceSet(void);
31 33
32 static void _expectRules(const char*, const char*, const char*); 34 static void _expectRules(const char*, const char*, const char*);
33 static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto); 35 static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto);
34 36
35 void addUTransTest(TestNode** root); 37 void addUTransTest(TestNode** root);
36 38
37 39
38 void 40 void
39 addUTransTest(TestNode** root) { 41 addUTransTest(TestNode** root) {
40 TEST(TestAPI); 42 TEST(TestAPI);
41 TEST(TestSimpleRules); 43 TEST(TestSimpleRules);
42 TEST(TestFilter); 44 TEST(TestFilter);
43 TEST(TestOpenInverse); 45 TEST(TestOpenInverse);
44 TEST(TestClone); 46 TEST(TestClone);
45 TEST(TestRegisterUnregister); 47 TEST(TestRegisterUnregister);
46 TEST(TestExtractBetween); 48 TEST(TestExtractBetween);
47 TEST(TestUnicodeIDs); 49 TEST(TestUnicodeIDs);
50 TEST(TestGetRulesAndSourceSet);
48 } 51 }
49 52
50 /*------------------------------------------------------------------ 53 /*------------------------------------------------------------------
51 * Replaceable glue 54 * Replaceable glue
52 * 55 *
53 * To test the Replaceable glue we have to dummy up a C-based 56 * To test the Replaceable glue we have to dummy up a C-based
54 * Replaceable callback. This code is for testing purposes only. 57 * Replaceable callback. This code is for testing purposes only.
55 *------------------------------------------------------------------*/ 58 *------------------------------------------------------------------*/
56 59
57 typedef struct XReplaceable { 60 typedef struct XReplaceable {
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 if (U_FAILURE(status)) { 564 if (U_FAILURE(status)) {
562 log_err("FAIL: utrans_open(Lower) failed, error=%s\n", 565 log_err("FAIL: utrans_open(Lower) failed, error=%s\n",
563 u_errorName(status)); 566 u_errorName(status));
564 } else { 567 } else {
565 _expect(trans, "ABC", "abc"); 568 _expect(trans, "ABC", "abc");
566 569
567 utrans_close(trans); 570 utrans_close(trans);
568 } 571 }
569 } 572 }
570 573
574 /**
575 * Test utrans_toRules, utrans_getSourceSet
576 */
577
578 /* A simple transform with a small filter & source set: rules 50-100 chars unesc aped, 100-200 chars escaped,
579 filter & source set 4-20 chars */
580 static const UChar transSimpleID[] = { 0x79,0x6F,0x2D,0x79,0x6F,0x5F,0x42,0x4A,0 }; /* "yo-yo_BJ" */
581 static const char* transSimpleCName = "yo-yo_BJ";
582
583 enum { kUBufMax = 256 };
584 static void TestGetRulesAndSourceSet() {
585 UErrorCode status = U_ZERO_ERROR;
586 UTransliterator *utrans = utrans_openU(transSimpleID, -1, UTRANS_FORWARD, NU LL, 0, NULL, &status);
587 if ( U_SUCCESS(status) ) {
588 USet* uset;
589 UChar ubuf[kUBufMax];
590 int32_t ulen;
591
592 status = U_ZERO_ERROR;
593 ulen = utrans_toRules(utrans, FALSE, ubuf, kUBufMax, &status);
594 if ( U_FAILURE(status) || ulen <= 50 || ulen >= 100) {
595 log_err("FAIL: utrans_toRules unescaped, expected noErr and len 50-1 00, got error=%s and len=%d\n",
596 u_errorName(status), ulen);
597 }
598
599 status = U_ZERO_ERROR;
600 ulen = utrans_toRules(utrans, FALSE, NULL, 0, &status);
601 if ( status != U_BUFFER_OVERFLOW_ERROR || ulen <= 50 || ulen >= 100) {
602 log_err("FAIL: utrans_toRules unescaped, expected U_BUFFER_OVERFLOW_ ERROR and len 50-100, got error=%s and len=%d\n",
603 u_errorName(status), ulen);
604 }
605
606 status = U_ZERO_ERROR;
607 ulen = utrans_toRules(utrans, TRUE, ubuf, kUBufMax, &status);
608 if ( U_FAILURE(status) || ulen <= 100 || ulen >= 200) {
609 log_err("FAIL: utrans_toRules escaped, expected noErr and len 100-20 0, got error=%s and len=%d\n",
610 u_errorName(status), ulen);
611 }
612
613 status = U_ZERO_ERROR;
614 uset = utrans_getSourceSet(utrans, FALSE, NULL, &status);
615 ulen = uset_toPattern(uset, ubuf, kUBufMax, FALSE, &status);
616 uset_close(uset);
617 if ( U_FAILURE(status) || ulen <= 4 || ulen >= 20) {
618 log_err("FAIL: utrans_getSourceSet useFilter, expected noErr and len 4-20, got error=%s and len=%d\n",
619 u_errorName(status), ulen);
620 }
621
622 status = U_ZERO_ERROR;
623 uset = utrans_getSourceSet(utrans, TRUE, NULL, &status);
624 ulen = uset_toPattern(uset, ubuf, kUBufMax, FALSE, &status);
625 uset_close(uset);
626 if ( U_FAILURE(status) || ulen <= 4 || ulen >= 20) {
627 log_err("FAIL: utrans_getSourceSet ignoreFilter, expected noErr and len 4-20, got error=%s and len=%d\n",
628 u_errorName(status), ulen);
629 }
630
631 utrans_close(utrans);
632 } else {
633 log_data_err("FAIL: utrans_openRules(%s) failed, error=%s (Are you missi ng data?)\n",
634 transSimpleCName, u_errorName(status));
635 }
636 }
637
638
571 static void _expectRules(const char* crules, 639 static void _expectRules(const char* crules,
572 const char* cfrom, 640 const char* cfrom,
573 const char* cto) { 641 const char* cto) {
574 /* u_uastrcpy has no capacity param for the buffer -- so just 642 /* u_uastrcpy has no capacity param for the buffer -- so just
575 * make all buffers way too big */ 643 * make all buffers way too big */
576 enum { CAP = 256 }; 644 enum { CAP = 256 };
577 UChar rules[CAP]; 645 UChar rules[CAP];
578 UTransliterator *trans; 646 UTransliterator *trans;
579 UErrorCode status = U_ZERO_ERROR; 647 UErrorCode status = U_ZERO_ERROR;
580 UParseError parseErr; 648 UParseError parseErr;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 } else { 773 } else {
706 char actual[CAP]; 774 char actual[CAP];
707 u_austrcpy(actual, xrep.text); 775 u_austrcpy(actual, xrep.text);
708 log_err("FAIL: utrans_transIncremental(%s) x %s -> %s, expected %s\n", 776 log_err("FAIL: utrans_transIncremental(%s) x %s -> %s, expected %s\n",
709 id, cfrom, actual, cto); 777 id, cfrom, actual, cto);
710 } 778 }
711 FreeXReplaceable(&xrep); 779 FreeXReplaceable(&xrep);
712 } 780 }
713 781
714 #endif /* #if !UCONFIG_NO_TRANSLITERATION */ 782 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
OLDNEW
« no previous file with comments | « source/test/cintltst/utmstest.c ('k') | source/test/depstest/dependencies.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698