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