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