-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_l10n.c
106 lines (89 loc) · 3.33 KB
/
test_l10n.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "CuTest.h"
#include "l10n.h"
static void test_l10n_heap(CuTest * tc)
{
char buffer[32];
l10n_text *txt;
txt = l10n_text_create();
CuAssertPtrNotNull(tc, txt);
CuAssertIntEquals(tc, 1, txt->refcount);
CuAssertPtrEquals(tc, buffer, l10n_text_render(txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "", buffer);
l10n_text_assign(txt, "$name's blog (%num stars)", "$name", "Enno", "%num", 42, NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Enno's blog (42 stars)", buffer);
txt = l10n_text_release(txt);
CuAssertPtrEquals(tc, NULL, txt);
}
static void test_l10n(CuTest * tc)
{
char buffer[32];
l10n_text txt;
l10n_text_init(&txt);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "", buffer);
l10n_text_assign(&txt, "$name's blog (%num stars)", "$name", "Enno", "%num", 42, NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Enno's blog (42 stars)", buffer);
l10n_text_assign(&txt, "Hodor", NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Hodor", buffer);
l10n_text_assign(&txt, NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "", buffer);
l10n_text_free(&txt);
}
static void test_l10n_simple(CuTest * tc)
{
char buffer[32];
l10n_text txt = { NULL, 0, 0 };
l10n_text_assign(&txt, "$name's blog (%num stars)", "$name", "Enno", "%num", 42, NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Enno's blog (42 stars)", buffer);
l10n_text_free(&txt);
}
static void test_l10n_const(CuTest * tc)
{
char buffer[32];
l10n_text txt = { "Hodor", 0, NULL };
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Hodor", buffer);
l10n_text_free(&txt);
}
static void test_l10n_nested(CuTest * tc)
{
char buffer[32];
l10n_text txt = { NULL, 0, 0 };
l10n_text *sub;
sub = l10n_text_build("$name!", "$name", "Hodor", NULL);
l10n_text_assign(&txt, "@name @name! @name!!", "@name", sub, NULL);
CuAssertPtrEquals(tc, buffer, l10n_text_render(&txt, buffer, sizeof(buffer)));
CuAssertStrEquals(tc, "Hodor! Hodor!! Hodor!!!", buffer);
l10n_text_free(&txt);
sub = l10n_text_release(sub);
CuAssertPtrEquals(tc, NULL, sub);
}
static void test_l10n_build(CuTest * tc)
{
char buffer[32];
l10n_text *txt;
txt = l10n_text_build("$name's blog (%num stars)", "$name", "Enno", "%num", 42, NULL);
CuAssertPtrNotNull(tc, txt);
CuAssertIntEquals(tc, 1, txt->refcount);
l10n_text_render(txt, buffer, sizeof(buffer));
CuAssertStrEquals(tc, "Enno's blog (42 stars)", buffer);
txt = l10n_text_release(txt);
CuAssertPtrEquals(tc, NULL, txt);
}
void add_suite_l10n(CuSuite *suite)
{
SUITE_ADD_TEST(suite, test_l10n);
SUITE_ADD_TEST(suite, test_l10n_const);
SUITE_ADD_TEST(suite, test_l10n_simple);
SUITE_ADD_TEST(suite, test_l10n_nested);
SUITE_ADD_TEST(suite, test_l10n_build);
SUITE_ADD_TEST(suite, test_l10n_heap);
}