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/tools/regression/lib/libc/locale/test-c16rtomb.c 250883 2013-05-21 19:59:37Z 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>
--- 34 unchanged lines hidden (view full) ---
77 assert((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
78
79 /* Unicode character 'Pile of poo'. */
80 memset(&s, 0, sizeof(s));
81 memset(buf, 0xcc, sizeof(buf));
82 assert(c16rtomb(buf, 0xd83d, &s) == 0);
83 assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
84 assert(errno == EILSEQ);
85
86 /*
87 * UTF-8.
88 */
89
90 assert(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0);
91
92 /* Unicode character 'Pile of poo'. */
93 memset(&s, 0, sizeof(s));
94 memset(buf, 0xcc, sizeof(buf));
--- 4 unchanged lines hidden (view full) ---
99 (unsigned char)buf[4] == 0xcc);
100
101 /* Invalid code; 'Pile of poo' without the trail surrogate. */
102 memset(&s, 0, sizeof(s));
103 memset(buf, 0xcc, sizeof(buf));
104 assert(c16rtomb(buf, 0xd83d, &s) == 0);
105 assert(c16rtomb(buf, L'A', &s) == (size_t)-1);
106 assert(errno == EILSEQ);
107
108 /* Invalid code; 'Pile of poo' without the lead surrogate. */
109 memset(&s, 0, sizeof(s));
110 memset(buf, 0xcc, sizeof(buf));
111 assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
112 assert(errno == EILSEQ);
113
114 printf("ok 1 - c16rtomb()\n");
115}
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/tools/regression/lib/libc/locale/test-c16rtomb.c 250883 2013-05-21 19:59:37Z 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>
--- 34 unchanged lines hidden (view full) ---
77 assert((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
78
79 /* Unicode character 'Pile of poo'. */
80 memset(&s, 0, sizeof(s));
81 memset(buf, 0xcc, sizeof(buf));
82 assert(c16rtomb(buf, 0xd83d, &s) == 0);
83 assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
84 assert(errno == EILSEQ);
85
86 /*
87 * UTF-8.
88 */
89
90 assert(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0);
91
92 /* Unicode character 'Pile of poo'. */
93 memset(&s, 0, sizeof(s));
94 memset(buf, 0xcc, sizeof(buf));
--- 4 unchanged lines hidden (view full) ---
99 (unsigned char)buf[4] == 0xcc);
100
101 /* Invalid code; 'Pile of poo' without the trail surrogate. */
102 memset(&s, 0, sizeof(s));
103 memset(buf, 0xcc, sizeof(buf));
104 assert(c16rtomb(buf, 0xd83d, &s) == 0);
105 assert(c16rtomb(buf, L'A', &s) == (size_t)-1);
106 assert(errno == EILSEQ);
107
108 /* Invalid code; 'Pile of poo' without the lead surrogate. */
109 memset(&s, 0, sizeof(s));
110 memset(buf, 0xcc, sizeof(buf));
111 assert(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
112 assert(errno == EILSEQ);
113
114 printf("ok 1 - c16rtomb()\n");
115}