]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cposxtst.c
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cposxtst.c
1 /*
2 **********************************************************************
3 * Copyright (c) 2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: March 20 2003
8 * Since: ICU 2.6
9 **********************************************************************
10 */
11 #include "cintltst.h"
12 #include "cmemory.h"
13 #include "cstring.h"
14 #include "unicode/ucat.h"
15 #include "unicode/ustring.h"
16
17 /**********************************************************************/
18 /* Prototypes */
19
20 void TestMessageCatalog(void);
21
22 /**********************************************************************/
23 /* Add our tests into the hierarchy */
24
25 void addPosixTest(TestNode** root);
26
27 void addPosixTest(TestNode** root)
28 {
29 addTest(root, &TestMessageCatalog, "tsutil/cposxtst/TestMessageCatalog");
30 }
31
32 /**********************************************************************/
33 /* Test basic ucat.h API */
34
35 void TestMessageCatalog(void) {
36
37 UErrorCode ec = U_ZERO_ERROR;
38 u_nl_catd catd;
39 const char* DATA[] = {
40 /* set_num, msg_num, expected string result, expected error code */
41 "1", "4", "Good morning.", "U_ZERO_ERROR",
42 "1", "5", "Good afternoon.", "U_ZERO_ERROR",
43 "1", "6", "FAIL", "U_MISSING_RESOURCE_ERROR",
44 "1", "7", "Good evening.", "U_ZERO_ERROR",
45 "1", "8", "Good night.", "U_ZERO_ERROR",
46 "1", "9", "FAIL", "U_MISSING_RESOURCE_ERROR",
47 "3", "1", "FAIL", "U_MISSING_RESOURCE_ERROR",
48 "4", "14", "Please ", "U_ZERO_ERROR",
49 "4", "15", "FAIL", "U_MISSING_RESOURCE_ERROR",
50 "4", "19", "Thank you.", "U_ZERO_ERROR",
51 "4", "20", "Sincerely,", "U_ZERO_ERROR",
52 NULL
53 };
54 const UChar FAIL[] = {0x46, 0x41, 0x49, 0x4C, 0x00}; /* "FAIL" */
55 int32_t i;
56 const char *path = loadTestData(&ec);
57
58 if (U_FAILURE(ec)) {
59 log_err("FAIL: loadTestData => %s\n", u_errorName(ec));
60 return;
61 }
62
63 catd = u_catopen(path, "mc", &ec);
64 if (U_FAILURE(ec)) {
65 log_err("FAIL: u_catopen => %s\n", u_errorName(ec));
66 return;
67 }
68
69 for (i=0; DATA[i]!=NULL; i+=4) {
70 int32_t set_num = T_CString_stringToInteger(DATA[i], 10);
71 int32_t msg_num = T_CString_stringToInteger(DATA[i+1], 10);
72 UChar exp[128];
73 int32_t len = -1;
74 const char* err;
75 char str[128];
76 const UChar* ustr;
77
78 u_uastrcpy(exp, DATA[i+2]);
79
80 ec = U_ZERO_ERROR;
81 ustr = u_catgets(catd, set_num, msg_num, FAIL, &len, &ec);
82 u_austrcpy(str, ustr);
83 err = u_errorName(ec);
84
85 log_verbose("u_catgets(%d, %d) => \"%s\", len=%d, %s\n",
86 set_num, msg_num, str, len, err);
87
88 if (u_strcmp(ustr, exp) != 0) {
89 log_err("FAIL: u_catgets => \"%s\", exp. \"%s\"\n",
90 str, DATA[i+2]);
91 }
92
93 if (len != (int32_t) uprv_strlen(DATA[i+2])) {
94 log_err("FAIL: u_catgets => len=%d, exp. %d\n",
95 len, uprv_strlen(DATA[i+2]));
96 }
97
98 if (uprv_strcmp(err, DATA[i+3]) != 0) {
99 log_err("FAIL: u_catgets => %s, exp. %s\n",
100 err, DATA[i+3]);
101 }
102 }
103
104 u_catclose(catd);
105 }
106
107 /*eof*/