1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/** \file utf8test.c
* Unit tests for utf 8 conversion routines on Windows
*/
#include <setjmp.h>
#include <stdbool.h>
#include <string.h>
#include <cmocka.h>
#include <wlib.h>
#define SIMPLEASCIITEXT "The quick brown fox jumps over the lazy dog."
#define UMLAUTTEXT "äöüÄÖÜß"
static void
ASCIIText(void **state)
{
char output[100];
char result[100];
bool success;
(void)state;
success = wSystemToUTF8(SIMPLEASCIITEXT, output, 100);
assert_true((void *)success);
success = wUTF8ToSystem(output, result, 100);
assert_true((void *)success);
assert_false(strcmp(SIMPLEASCIITEXT, result));
}
static void
Umlauts(void **state)
{
char output[100];
char result[100];
bool success;
(void)state;
success = wIsUTF8(UMLAUTTEXT);
assert_false((void *)success);
success = wSystemToUTF8(UMLAUTTEXT, output, 100);
assert_true((void *)success);
success = wIsUTF8(output);
assert_true((void *)success);
success = wUTF8ToSystem(output, result, 100);
assert_true((void *)success);
assert_false(strcmp(UMLAUTTEXT, result));
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(ASCIIText),
cmocka_unit_test(Umlauts),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|