c16rtomb_test.c (290532) | c16rtomb_test.c (291178) |
---|---|
1/*- 2 * Copyright (c) 2002 Tim J. Robbins 3 * All rights reserved. 4 * 5 * Copyright (c) 2013 Ed Schouten <ed@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 17 unchanged lines hidden (view full) --- 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29/* 30 * Test program for c16rtomb() as specified by ISO/IEC 9899:2011. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002 Tim J. Robbins 3 * All rights reserved. 4 * 5 * Copyright (c) 2013 Ed Schouten <ed@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 17 unchanged lines hidden (view full) --- 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29/* 30 * Test program for c16rtomb() as specified by ISO/IEC 9899:2011. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/lib/libc/tests/locale/c16rtomb_test.c 290532 2015-11-08 02:06:17Z ngie $"); | 34__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/c16rtomb_test.c 291178 2015-11-23 08:31:41Z ngie $"); |
35 36#include <errno.h> 37#include <limits.h> 38#include <locale.h> 39#include <stdio.h> 40#include <string.h> 41#include <uchar.h> 42 43#include <atf-c.h> 44 | 35 36#include <errno.h> 37#include <limits.h> 38#include <locale.h> 39#include <stdio.h> 40#include <string.h> 41#include <uchar.h> 42 43#include <atf-c.h> 44 |
45ATF_TC_WITHOUT_HEAD(c16rtomb_test); 46ATF_TC_BODY(c16rtomb_test, tc) | 45static void 46require_lc_ctype(const char *locale_name) |
47{ | 47{ |
48 mbstate_t s; 49 char buf[MB_LEN_MAX + 1]; | 48 char *lc_ctype_set; |
50 | 49 |
51 /* C/POSIX locale. */ | 50 lc_ctype_set = setlocale(LC_CTYPE, locale_name); 51 if (lc_ctype_set == NULL) 52 atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", 53 locale_name, errno); |
52 | 54 |
55 ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); 56} 57 58static mbstate_t s; 59static char buf[MB_LEN_MAX + 1]; 60 61ATF_TC_WITHOUT_HEAD(c16rtomb_c_locale_test); 62ATF_TC_BODY(c16rtomb_c_locale_test, tc) 63{ 64 65 require_lc_ctype("C"); 66 |
|
53 /* 54 * If the buffer argument is NULL, c16 is implicitly 0, 55 * c16rtomb() resets its internal state. 56 */ 57 ATF_REQUIRE(c16rtomb(NULL, L'\0', NULL) == 1); 58 ATF_REQUIRE(c16rtomb(NULL, 0xdc00, NULL) == 1); 59 60 /* Null wide character. */ --- 14 unchanged lines hidden (view full) --- 75 76 /* Unicode character 'Pile of poo'. */ 77 memset(&s, 0, sizeof(s)); 78 memset(buf, 0xcc, sizeof(buf)); 79 ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0); 80 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1); 81 ATF_REQUIRE(errno == EILSEQ); 82 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); | 67 /* 68 * If the buffer argument is NULL, c16 is implicitly 0, 69 * c16rtomb() resets its internal state. 70 */ 71 ATF_REQUIRE(c16rtomb(NULL, L'\0', NULL) == 1); 72 ATF_REQUIRE(c16rtomb(NULL, 0xdc00, NULL) == 1); 73 74 /* Null wide character. */ --- 14 unchanged lines hidden (view full) --- 89 90 /* Unicode character 'Pile of poo'. */ 91 memset(&s, 0, sizeof(s)); 92 memset(buf, 0xcc, sizeof(buf)); 93 ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0); 94 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1); 95 ATF_REQUIRE(errno == EILSEQ); 96 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); |
97} |
|
83 | 98 |
84 /* ISO8859-1. */ | 99ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_1_test); 100ATF_TC_BODY(c16rtomb_iso_8859_1_test, tc) 101{ |
85 | 102 |
86 ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"), 87 "en_US.ISO8859-1") == 0); | 103 require_lc_ctype("en_US.ISO8859-1"); |
88 89 /* Unicode character 'Euro sign'. */ 90 memset(&s, 0, sizeof(s)); 91 memset(buf, 0xcc, sizeof(buf)); 92 ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == (size_t)-1); 93 ATF_REQUIRE(errno == EILSEQ); 94 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); | 104 105 /* Unicode character 'Euro sign'. */ 106 memset(&s, 0, sizeof(s)); 107 memset(buf, 0xcc, sizeof(buf)); 108 ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == (size_t)-1); 109 ATF_REQUIRE(errno == EILSEQ); 110 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); |
111} |
|
95 | 112 |
96 /* ISO8859-15. */ | 113ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_15_test); 114ATF_TC_BODY(c16rtomb_iso_8859_15_test, tc) 115{ |
97 | 116 |
98 ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"), 99 "en_US.ISO8859-15") == 0); | 117 require_lc_ctype("en_US.ISO8859-15"); |
100 101 /* Unicode character 'Euro sign'. */ 102 memset(&s, 0, sizeof(s)); 103 memset(buf, 0xcc, sizeof(buf)); 104 ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == 1); 105 ATF_REQUIRE((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 0xcc); | 118 119 /* Unicode character 'Euro sign'. */ 120 memset(&s, 0, sizeof(s)); 121 memset(buf, 0xcc, sizeof(buf)); 122 ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == 1); 123 ATF_REQUIRE((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 0xcc); |
124} |
|
106 | 125 |
107 /* UTF-8. */ | 126ATF_TC_WITHOUT_HEAD(c16rtomb_utf_8_test); 127ATF_TC_BODY(c16rtomb_utf_8_test, tc) 128{ |
108 | 129 |
109 ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0); | 130 require_lc_ctype("en_US.UTF-8"); |
110 111 /* Unicode character 'Pile of poo'. */ 112 memset(&s, 0, sizeof(s)); 113 memset(buf, 0xcc, sizeof(buf)); 114 ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0); 115 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == 4); 116 ATF_REQUIRE((unsigned char)buf[0] == 0xf0 && (unsigned char)buf[1] == 0x9f && 117 (unsigned char)buf[2] == 0x92 && (unsigned char)buf[3] == 0xa9 && --- 13 unchanged lines hidden (view full) --- 131 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1); 132 ATF_REQUIRE(errno == EILSEQ); 133 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); 134} 135 136ATF_TP_ADD_TCS(tp) 137{ 138 | 131 132 /* Unicode character 'Pile of poo'. */ 133 memset(&s, 0, sizeof(s)); 134 memset(buf, 0xcc, sizeof(buf)); 135 ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0); 136 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == 4); 137 ATF_REQUIRE((unsigned char)buf[0] == 0xf0 && (unsigned char)buf[1] == 0x9f && 138 (unsigned char)buf[2] == 0x92 && (unsigned char)buf[3] == 0xa9 && --- 13 unchanged lines hidden (view full) --- 152 ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1); 153 ATF_REQUIRE(errno == EILSEQ); 154 ATF_REQUIRE((unsigned char)buf[0] == 0xcc); 155} 156 157ATF_TP_ADD_TCS(tp) 158{ 159 |
139 ATF_TP_ADD_TC(tp, c16rtomb_test); | 160 ATF_TP_ADD_TC(tp, c16rtomb_c_locale_test); 161 ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_1_test); 162 ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_15_test); 163 ATF_TP_ADD_TC(tp, c16rtomb_utf_8_test); |
140 141 return (atf_no_error()); 142} | 164 165 return (atf_no_error()); 166} |