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 mbrtoc16() as specified by ISO/IEC 9899:2011. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/tools/regression/lib/libc/locale/test-mbrtoc16.c 251314 2013-06-03 17:17:56Z ed $"); |
35 36#include <assert.h> 37#include <errno.h> 38#include <limits.h> 39#include <locale.h> 40#include <stdio.h> 41#include <string.h> 42#include <uchar.h> --- 37 unchanged lines hidden (view full) --- 80 assert(c16 == L'z'); 81 82 /* Check that mbrtoc16() doesn't access the buffer when n == 0. */ 83 c16 = L'z'; 84 memset(&s, 0, sizeof(s)); 85 assert(mbrtoc16(&c16, "", 0, &s) == (size_t)-2); 86 assert(c16 == L'z'); 87 |
88 /* Check that mbrtoc16() doesn't read ahead too aggressively. */ 89 memset(&s, 0, sizeof(s)); 90 assert(mbrtoc16(&c16, "AB", 2, &s) == 1); 91 assert(c16 == L'A'); 92 assert(mbrtoc16(&c16, "C", 1, &s) == 1); 93 assert(c16 == L'C'); 94 |
95 /* |
96 * ISO-8859-1. 97 */ 98 99 assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"), 100 "en_US.ISO8859-1") == 0); 101 102 /* Currency sign. */ 103 memset(&s, 0, sizeof(s)); 104 assert(mbrtoc16(&c16, "\xa4", 1, &s) == 1); 105 assert(c16 == 0xa4); 106 107 /* 108 * ISO-8859-15. 109 */ 110 111 assert(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"), 112 "en_US.ISO8859-15") == 0); 113 114 /* Euro sign. */ 115 memset(&s, 0, sizeof(s)); 116 assert(mbrtoc16(&c16, "\xa4", 1, &s) == 1); 117 assert(c16 == 0x20ac); 118 119 /* |
120 * UTF-8. 121 */ 122 123 assert(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0); 124 125 /* Null wide character, internal state. */ 126 assert(mbrtoc16(NULL, 0, 0, NULL) == 0); 127 assert(mbrtoc16(&c16, "", 1, NULL) == 0); --- 42 unchanged lines hidden (view full) --- 170 /* Surrogate pair. */ 171 memset(&s, 0, sizeof(s)); 172 c16 = 0; 173 assert(mbrtoc16(&c16, "\xf0\x9f\x92\xa9", 4, &s) == 4); 174 assert(c16 == 0xd83d); 175 assert(mbrtoc16(&c16, "", 0, &s) == (size_t)-3); 176 assert(c16 == 0xdca9); 177 |
178 /* Letter e with acute, precomposed. */ 179 memset(&s, 0, sizeof(s)); 180 c16 = 0; 181 assert(mbrtoc16(&c16, "\xc3\xa9", 2, &s) == 2); 182 assert(c16 == 0xe9); 183 184 /* Letter e with acute, combined. */ 185 memset(&s, 0, sizeof(s)); 186 c16 = 0; 187 assert(mbrtoc16(&c16, "\x65\xcc\x81", 3, &s) == 1); 188 assert(c16 == 0x65); 189 assert(mbrtoc16(&c16, "\xcc\x81", 2, &s) == 2); 190 assert(c16 == 0x301); 191 |
192 printf("ok 1 - mbrtoc16()\n"); 193 194 return (0); 195} |