Newer
Older
#include "parse-pinyin.h"
#include <glib.h>
#include <glib/gprintf.h>
static void
test_parse_pinyin ()
{
GList* result = NULL;
Pinyin* thispy = NULL;
result = parse_pinyin ("liyifeng", 15);
g_assert_cmpint (g_list_length (result), ==, 3);
thispy = (Pinyin*) g_list_nth_data (result, 0);
g_assert_cmpint (thispy->shengmu_i, ==, 10);
g_assert_cmpint (thispy->yunmu_i, ==, 34);
g_assert_cmpint (thispy->length, ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 1);
g_assert_cmpint (thispy->shengmu_i, ==, 21);
g_assert_cmpint (thispy->yunmu_i, ==, 34);
g_assert_cmpint (thispy->length, ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 2);
g_assert_cmpint (thispy->shengmu_i, ==, 5);
g_assert_cmpint (thispy->yunmu_i, ==, 32);
g_assert_cmpint (thispy->length, ==, 4);
g_list_free_full (result, g_free);
}
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
/**
* print GList of Pinyin.
*/
static void
print_parse_result (GList* result)
{
GList* iter = result;
Pinyin* thispy = NULL;
while (iter != NULL) {
thispy = (Pinyin*) iter->data;
g_printf ("shengmu_i=%i yunmu_i=%i length=%u\n",
thispy->shengmu_i, thispy->yunmu_i, thispy->length);
iter = iter->next;
}
}
static void
test_parse_pinyin_incomplete_pinyin ()
{
GList* result = NULL;
Pinyin* thispy = NULL;
result = parse_pinyin ("zhey", 15);
print_parse_result (result);
g_assert_cmpint (g_list_length (result), ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 0);
g_assert_cmpint (thispy->shengmu_i, ==, 23);
g_assert_cmpint (thispy->yunmu_i, ==, 29);
g_assert_cmpint (thispy->length, ==, 3);
thispy = (Pinyin*) g_list_nth_data (result, 1);
g_assert_cmpint (thispy->shengmu_i, ==, 21);
g_assert_cmpint (thispy->yunmu_i, ==, 0);
g_assert_cmpint (thispy->length, ==, 1);
g_list_free_full (result, g_free);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/zero/test_parse_pinyin",
test_parse_pinyin);
g_test_add_func ("/zero/test_parse_pinyin incomplete pinyin",
test_parse_pinyin_incomplete_pinyin);