2015-01-12 22:53:21 +01:00
|
|
|
#include <platform.h>
|
2014-10-19 06:42:40 +02:00
|
|
|
#include <CuTest.h>
|
|
|
|
#include "unicode.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
static void test_unicode_tolower(CuTest * tc)
|
|
|
|
{
|
|
|
|
char buffer[32];
|
|
|
|
CuAssertIntEquals(tc, 0, unicode_utf8_tolower(buffer, sizeof(buffer), "HeLlO W0Rld"));
|
|
|
|
CuAssertStrEquals(tc, "hello w0rld", buffer);
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2015-01-12 22:53:21 +01:00
|
|
|
buffer[5] = 'X';
|
2014-10-19 06:42:40 +02:00
|
|
|
CuAssertIntEquals(tc, ENOMEM, unicode_utf8_tolower(buffer, 5, "HeLlO W0Rld"));
|
|
|
|
CuAssertStrEquals(tc, "helloX", buffer);
|
|
|
|
}
|
|
|
|
|
2016-10-02 12:46:07 +02:00
|
|
|
static void test_unicode_utf8_to_cp437(CuTest *tc)
|
|
|
|
{
|
|
|
|
const char utf8_str[4] = { 0xc3, 0x98, 'l', 0 }; // Øl
|
|
|
|
char ch;
|
|
|
|
size_t sz;
|
|
|
|
CuAssertIntEquals(tc, 0, unicode_utf8_to_cp437(&ch, utf8_str, &sz));
|
|
|
|
CuAssertIntEquals(tc, 2, sz);
|
|
|
|
CuAssertIntEquals(tc, '?', ch);
|
|
|
|
}
|
|
|
|
|
2014-10-19 06:42:40 +02:00
|
|
|
CuSuite *get_unicode_suite(void)
|
|
|
|
{
|
2015-01-12 22:53:21 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_unicode_tolower);
|
2016-10-02 12:46:07 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_unicode_utf8_to_cp437);
|
2015-01-12 22:53:21 +01:00
|
|
|
return suite;
|
2014-10-19 06:42:40 +02:00
|
|
|
}
|