File: test-utf8.c

package info (click to toggle)
libchewing 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,588 kB
  • ctags: 878
  • sloc: sh: 9,738; ansic: 7,644; makefile: 234; python: 49
file content (69 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (3)
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
/**
 * test-utf8.c
 *
 * Copyright (c) 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#include <stdio.h>
#include <string.h>
#include <check.h>
#include "chewing-utf8-util.h"

START_TEST(test_strlen1)
{
	char *u8string = "HelloWorld";
	int u8len = ueStrLen(u8string);
	int len = strlen(u8string);
	fail_unless(u8len == len, NULL);
}
END_TEST

START_TEST(test_strlen2)
{
	char *u8string = "測試計算長度";
	int u8len = ueStrLen(u8string);
	fail_unless(u8len == 6, NULL);
}
END_TEST

START_TEST(test_strncpy)
{
	char *u8string = "測試計算長度";
	char u8string2[16];
	ueStrNCpy(u8string2, u8string, 3, STRNCPY_CLOSE);
	fail_if(strcmp(u8string2, "測試計"), NULL);
}
END_TEST

START_TEST(test_strseek)
{
	char *u8string = "測試計算長度";
	u8string = ueStrSeek(u8string, 3);
	fail_if(strcmp(u8string, "算長度"), NULL);
}
END_TEST

START_TEST(test_strseek2)
{
	char *u8string = "測試計算長度";
	u8string = ueStrSeek(u8string, 0);
	fail_if(strcmp(u8string, "測試計算長度"), NULL);
}
END_TEST

Suite *utf8_suite (void)
{
	Suite *s = suite_create("UTF-8_Util");
	TCase *tc_core = tcase_create("Core");
	suite_add_tcase (s, tc_core);
	tcase_add_test (tc_core, test_strlen1);
	tcase_add_test (tc_core, test_strlen2);
	tcase_add_test (tc_core, test_strncpy);
	tcase_add_test (tc_core, test_strseek);
	tcase_add_test (tc_core, test_strseek2);
	return s;
}