/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "test-common.h"
#include "charset-utf8.h"
static void test_charset_is_utf8(void)
{
test_begin("charset_is_utf8");
test_end();
}
{
static const struct {
const char *input;
const char *output;
} tests[] = {
};
unsigned int i;
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
}
/* check that E2BIG handling works. We assume that iconv() is called
with 8192 byte buffer (tmpbuf[8192]) */
for (i = 0; i < 8190; i++)
for (i = 0; i < 256; i++) {
str_truncate(str, 0);
}
}
static void test_charset_utf8(void)
{
test_begin("charset utf8");
test_charset_utf8_common("UTF-8");
test_end();
}
#ifdef HAVE_ICONV
static void test_charset_iconv(void)
{
static const struct {
const char *charset;
const char *input;
const char *output;
} tests[] = {
{ "UTF-7", "+AOQA5AD2AOQA9gDkAPYA5AD2AOQA9gDkAPYA5AD2AOQA9gDkAPYA5AD2AOQA9gDkAPYA5AD2AOQA9gDkAPYA5AD2AOQA9gDk",
"\xC3\xA4\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4"
"\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4"
"\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4"
"\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4"
"\xC3\xB6\xC3\xA4\xC3\xB6\xC3\xA4", CHARSET_RET_OK }
};
unsigned int i;
test_begin("charset iconv");
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
str_truncate(str, 0);
if (result != CHARSET_RET_INCOMPLETE_INPUT &&
result != CHARSET_RET_OK)
break;
}
}
/* Use //IGNORE just to force handling to be done by iconv
instead of our own UTF-8 routines. */
test_charset_utf8_common("UTF-8//TEST");
test_end();
}
static void test_charset_iconv_crashes(void)
{
static const struct {
const char *charset;
const char *input;
} tests[] = {
{ "CP932", "\203\334" }
};
unsigned int i;
test_begin("charset iconv crashes");
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
/* we don't care about checking the result. we only want to
verify that there's no crash. */
}
test_end();
}
static void test_charset_iconv_utf7_state(void)
{
test_begin("charset iconv utf7 state");
size = 2;
test_assert(charset_to_utf8(trans, (const void *)"a+", &size, str) == CHARSET_RET_INCOMPLETE_INPUT);
test_end();
}
#endif
int main(void)
{
static void (*const test_functions[])(void) = {
#ifdef HAVE_ICONV
#endif
};
return test_run(test_functions);
}