/* Test c8rtomb.
Copyright (C) 2022-2023 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uchar.h>
#include <wchar.h>
#include <support/check.h>
#include <support/support.h>
static int
test_truncated_code_unit_sequence (void)
{
/* Missing trailing code unit for a two code byte unit sequence. */
{
const char8_t *u8s = (const char8_t*) u8"\xC2";
char buf[MB_LEN_MAX] = { 0 };
mbstate_t s = { 0 };
TEST_COMPARE (c8rtomb (buf, u8s[0], &s), (size_t) 0);
errno = 0;
TEST_COMPARE (c8rtomb (buf, u8s[1], &s), (size_t) -1);
TEST_COMPARE (errno, EILSEQ);
}
/* Missing first trailing code unit for a three byte code unit sequence. */
{
const char8_t *u8s = (const char8_t*) u8"\xE0";
char buf[MB_LEN_MAX] = { 0 };
mbstate_t s = { 0 };
TEST_COMPARE (c8rtomb (buf, u8s[0], &s), (size_t) 0);
errno = 0;
TEST_COMPARE (c8rtomb (buf, u8s[1], &s), (size_t) -1);
TEST_COMPARE (errno, EILSEQ);
}
/* Missing second trailing code unit for a three byte code unit sequence. */
{
const char8_t *u8s = (const char8_t*) u8"\xE0\xA0";
char buf[MB_LEN_MAX] = { 0 };
mbstate_t s = { 0 };
TEST_COMPARE (c8rtomb (buf, u8s[0], &s), (size_t) 0);
TEST_COMPARE (c8rtomb (buf, u8s[1], &s), (size_t) 0);
errno = 0;
TEST_COMPARE (c8rtomb (buf, u8s[2], &s), (size_t) -1);
TEST_COMPARE (errno, EILSEQ);
}
/* Missing first trailing code unit for a four byte code unit sequence. */
{
const char8_t *u8s = (const char8_t*) u8"\xF0";
char buf[MB_LEN_MAX] = { 0 };
mbstate_t s = { 0 };
TEST_COMPARE (c8rtomb (buf, u8s[0], &s), (size_t) 0);
errno = 0;
TEST_COMPARE (c8rtomb (buf, u8s[1], &s), (size_t) -1);
TEST_COMPARE (errno, EILSEQ);
}
/* Missing second trailing code unit for a four byte code unit sequence. */
{
const char8_t *u8s = (const char8_t*) u8"\xF0\x90"