Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
e81aff9e
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
1 年多 前同步成功
通知
0
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e81aff9e
编写于
1月 02, 2013
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[tests] Finish test-set.c
All passing now.
上级
7b1b720a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
149 addition
and
224 deletion
+149
-224
test/api/test-set.c
test/api/test-set.c
+149
-224
未找到文件。
test/api/test-set.c
浏览文件 @
e81aff9e
...
...
@@ -29,243 +29,169 @@
/* Unit tests for hb-set.h */
#if 0
static
void
test_
buffer_properties (fixture_t *fixture, gconstpointer user_data
)
test_
empty
(
hb_set_t
*
s
)
{
hb_buffer_t *b = fixture->buffer;
hb_unicode_funcs_t *ufuncs;
/* test default properties */
g_assert (hb_buffer_get_unicode_funcs (b) == hb_unicode_funcs_get_default ());
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID);
g_assert (hb_buffer_get_language (b) == NULL);
g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAGS_DEFAULT);
/* test property changes are retained */
ufuncs = hb_unicode_funcs_create (NULL);
hb_buffer_set_unicode_funcs (b, ufuncs);
hb_unicode_funcs_destroy (ufuncs);
g_assert (hb_buffer_get_unicode_funcs (b) == ufuncs);
hb_buffer_set_direction (b, HB_DIRECTION_RTL);
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_RTL);
hb_buffer_set_script (b, HB_SCRIPT_ARABIC);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_ARABIC);
hb_buffer_set_language (b, hb_language_from_string ("fa", -1));
g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1));
hb_buffer_set_flags (b, HB_BUFFER_FLAG_BOT);
g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAG_BOT);
/* test clear clears all properties but unicode_funcs */
hb_buffer_clear (b);
g_assert (hb_buffer_get_unicode_funcs (b) == ufuncs);
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID);
g_assert (hb_buffer_get_language (b) == NULL);
g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAGS_DEFAULT);
/* test reset clears all properties */
hb_buffer_set_direction (b, HB_DIRECTION_RTL);
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_RTL);
hb_buffer_set_script (b, HB_SCRIPT_ARABIC);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_ARABIC);
hb_buffer_set_language (b, hb_language_from_string ("fa", -1));
g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1));
hb_buffer_set_flags (b, HB_BUFFER_FLAG_BOT);
g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAG_BOT);
hb_buffer_reset (b);
g_assert (hb_buffer_get_unicode_funcs (b) == hb_unicode_funcs_get_default ());
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID);
g_assert (hb_buffer_get_language (b) == NULL);
g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAGS_DEFAULT);
hb_codepoint_t
next
=
(
hb_codepoint_t
)
-
1
;
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
0
);
g_assert_cmpint
(
hb_set_get_min
(
s
),
==
,
(
hb_codepoint_t
)
-
1
);
g_assert_cmpint
(
hb_set_get_max
(
s
),
==
,
(
hb_codepoint_t
)
-
1
);
g_assert
(
!
hb_set_has
(
s
,
13
));
g_assert
(
!
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
(
hb_codepoint_t
)
-
1
);
}
static
void
test_
buffer_contents (fixture_t *fixture, gconstpointer user_data
)
test_
not_empty
(
hb_set_t
*
s
)
{
hb_buffer_t *b = fixture->buffer;
unsigned int i, len, len2;
buffer_type_t buffer_type = GPOINTER_TO_INT (user_data);
hb_glyph_info_t *glyphs;
if (buffer_type == BUFFER_EMPTY) {
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
return;
}
len = hb_buffer_get_population (b);
hb_buffer_get_glyph_infos (b, NULL); /* test NULL */
glyphs = hb_buffer_get_glyph_infos (b, &len2);
g_assert_cmpint (len, ==, len2);
g_assert_cmpint (len, ==, 5);
for (i = 0; i < len; i++) {
g_assert_cmphex (glyphs[i].mask, ==, 1);
g_assert_cmphex (glyphs[i].var1.u32, ==, 0);
g_assert_cmphex (glyphs[i].var2.u32, ==, 0);
}
for (i = 0; i < len; i++) {
unsigned int cluster;
cluster = 1+i;
if (i >= 2) {
if (buffer_type == BUFFER_UTF16)
cluster++;
else if (buffer_type == BUFFER_UTF8)
cluster += 3;
}
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
g_assert_cmphex (glyphs[i].cluster, ==, cluster);
}
/* reverse, test, and reverse back */
hb_buffer_reverse (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[len-i]);
hb_buffer_reverse (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
/* reverse_clusters works same as reverse for now since each codepoint is
* in its own cluster */
hb_buffer_reverse_clusters (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[len-i]);
hb_buffer_reverse_clusters (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
/* now form a cluster and test again */
glyphs[2].cluster = glyphs[1].cluster;
/* reverse, test, and reverse back */
hb_buffer_reverse (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[len-i]);
hb_buffer_reverse (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
/* reverse_clusters twice still should return the original string,
* but when applied once, the 1-2 cluster should be retained. */
hb_buffer_reverse_clusters (b);
for (i = 0; i < len; i++) {
unsigned int j = len-1-i;
if (j == 1)
j = 2;
else if (j == 2)
j = 1;
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+j]);
}
hb_buffer_reverse_clusters (b);
for (i = 0; i < len; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
/* test setting length */
/* enlarge */
g_assert (hb_buffer_set_length (b, 10));
glyphs = hb_buffer_get_glyph_infos (b, NULL);
g_assert_cmpint (hb_buffer_get_population (b), ==, 10);
for (i = 0; i < 5; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
for (i = 5; i < 10; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, 0);
/* shrink */
g_assert (hb_buffer_set_length (b, 3));
glyphs = hb_buffer_get_glyph_infos (b, NULL);
g_assert_cmpint (hb_buffer_get_population (b), ==, 3);
for (i = 0; i < 3; i++)
g_assert_cmphex (glyphs[i].codepoint, ==, utf32[1+i]);
g_assert (hb_buffer_allocation_successful (b));
/* test reset clears content */
hb_buffer_reset (b);
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
hb_codepoint_t
next
=
(
hb_codepoint_t
)
-
1
;
g_assert_cmpint
(
hb_set_get_population
(
s
),
!=
,
0
);
g_assert_cmpint
(
hb_set_get_min
(
s
),
!=
,
(
hb_codepoint_t
)
-
1
);
g_assert_cmpint
(
hb_set_get_max
(
s
),
!=
,
(
hb_codepoint_t
)
-
1
);
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
!=
,
(
hb_codepoint_t
)
-
1
);
}
static
void
test_
buffer_allocation (fixture_t *fixture, gconstpointer user_data
)
test_
set_basic
(
void
)
{
hb_buffer_t *b = fixture->buffer;
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
g_assert (hb_buffer_pre_allocate (b, 100));
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
g_assert (hb_buffer_allocation_successful (b));
/* lets try a huge allocation, make sure it fails */
g_assert (!hb_buffer_pre_allocate (b, (unsigned int) -1));
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
g_assert (!hb_buffer_allocation_successful (b));
/* small one again */
g_assert (hb_buffer_pre_allocate (b, 50));
g_assert_cmpint (hb_buffer_get_population (b), ==, 0);
g_assert (!hb_buffer_allocation_successful (b));
hb_buffer_reset (b);
g_assert (hb_buffer_allocation_successful (b));
/* all allocation and size */
g_assert (!hb_buffer_pre_allocate (b, ((unsigned int) -1) / 20 + 1));
g_assert (!hb_buffer_allocation_successful (b));
hb_buffer_reset (b);
g_assert (hb_buffer_allocation_successful (b));
/* technically, this one can actually pass on 64bit machines, but
* I'm doubtful that any malloc allows 4GB allocations at a time.
* But let's only enable it on a 32-bit machine. */
if (sizeof (long) == 4) {
g_assert (!hb_buffer_pre_allocate (b, ((unsigned int) -1) / 20 - 1));
g_assert (!hb_buffer_allocation_successful (b));
}
hb_set_t
*
s
=
hb_set_create
();
test_empty
(
s
);
hb_set_add
(
s
,
13
);
test_not_empty
(
s
);
hb_set_clear
(
s
);
test_empty
(
s
);
hb_set_add_range
(
s
,
10
,
29
);
test_not_empty
(
s
);
g_assert
(
hb_set_has
(
s
,
13
));
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
20
);
g_assert_cmpint
(
hb_set_get_min
(
s
),
==
,
10
);
g_assert_cmpint
(
hb_set_get_max
(
s
),
==
,
29
);
hb_set_invert
(
s
);
test_not_empty
(
s
);
g_assert
(
!
hb_set_has
(
s
,
13
));
g_assert_cmpint
(
hb_set_get_min
(
s
),
==
,
0
);
hb_set_invert
(
s
);
test_not_empty
(
s
);
g_assert
(
hb_set_has
(
s
,
13
));
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
20
);
g_assert_cmpint
(
hb_set_get_min
(
s
),
==
,
10
);
g_assert_cmpint
(
hb_set_get_max
(
s
),
==
,
29
);
hb_set_del_range
(
s
,
10
,
18
);
test_not_empty
(
s
);
g_assert
(
!
hb_set_has
(
s
,
13
));
}
hb_buffer_reset (b);
g_assert (hb_buffer_allocation_successful (b));
static
void
test_set_algebra
(
void
)
{
hb_set_t
*
s
=
hb_set_create
();
hb_set_t
*
o
=
hb_set_create
();
hb_set_add
(
o
,
13
);
hb_set_add
(
o
,
19
);
test_empty
(
s
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
hb_set_set
(
s
,
o
);
g_assert
(
hb_set_is_equal
(
s
,
o
));
test_not_empty
(
s
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
2
);
hb_set_clear
(
s
);
test_empty
(
s
);
hb_set_add
(
s
,
10
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
1
);
hb_set_union
(
s
,
o
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
3
);
g_assert
(
hb_set_has
(
s
,
10
));
g_assert
(
hb_set_has
(
s
,
13
));
hb_set_clear
(
s
);
test_empty
(
s
);
hb_set_add_range
(
s
,
10
,
17
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
hb_set_intersect
(
s
,
o
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
test_not_empty
(
s
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
1
);
g_assert
(
!
hb_set_has
(
s
,
10
));
g_assert
(
hb_set_has
(
s
,
13
));
hb_set_clear
(
s
);
test_empty
(
s
);
hb_set_add_range
(
s
,
10
,
17
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
hb_set_subtract
(
s
,
o
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
test_not_empty
(
s
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
7
);
g_assert
(
hb_set_has
(
s
,
12
));
g_assert
(
!
hb_set_has
(
s
,
13
));
g_assert
(
!
hb_set_has
(
s
,
19
));
hb_set_clear
(
s
);
test_empty
(
s
);
hb_set_add_range
(
s
,
10
,
17
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
hb_set_symmetric_difference
(
s
,
o
);
g_assert
(
!
hb_set_is_equal
(
s
,
o
));
test_not_empty
(
s
);
g_assert_cmpint
(
hb_set_get_population
(
s
),
==
,
8
);
g_assert
(
hb_set_has
(
s
,
12
));
g_assert
(
!
hb_set_has
(
s
,
13
));
g_assert
(
hb_set_has
(
s
,
19
));
}
#endif
static
void
test_
empty
(
hb_set_t
*
b
)
test_
set_iter
(
void
)
{
g_assert_cmpint
(
hb_set_get_population
(
b
),
==
,
0
);
g_assert_cmpint
(
hb_set_get_min
(
b
),
==
,
(
hb_codepoint_t
)
-
1
);
g_assert_cmpint
(
hb_set_get_max
(
b
),
==
,
(
hb_codepoint_t
)
-
1
);
hb_codepoint_t
next
,
first
,
last
;
hb_set_t
*
s
=
hb_set_create
();
hb_set_add
(
s
,
13
);
hb_set_add_range
(
s
,
6
,
6
);
hb_set_add_range
(
s
,
10
,
15
);
hb_set_add
(
s
,
20005
);
test_not_empty
(
s
);
next
=
(
hb_codepoint_t
)
-
1
;
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
6
);
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
10
);
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
13
);
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
15
);
g_assert
(
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
20005
);
g_assert
(
!
hb_set_next
(
s
,
&
next
));
g_assert_cmpint
(
next
,
==
,
20005
);
first
=
last
=
(
hb_codepoint_t
)
-
1
;
g_assert
(
hb_set_next_range
(
s
,
&
first
,
&
last
));
g_assert_cmpint
(
first
,
==
,
6
);
g_assert_cmpint
(
last
,
==
,
6
);
g_assert
(
hb_set_next_range
(
s
,
&
first
,
&
last
));
g_assert_cmpint
(
first
,
==
,
10
);
g_assert_cmpint
(
last
,
==
,
15
);
g_assert
(
hb_set_next_range
(
s
,
&
first
,
&
last
));
g_assert_cmpint
(
first
,
==
,
20005
);
g_assert_cmpint
(
last
,
==
,
20005
);
g_assert
(
!
hb_set_next_range
(
s
,
&
first
,
&
last
));
g_assert_cmpint
(
first
,
==
,
20005
);
g_assert_cmpint
(
last
,
==
,
20005
);
}
static
void
...
...
@@ -302,10 +228,9 @@ main (int argc, char **argv)
{
hb_test_init
(
&
argc
,
&
argv
);
#if 0
hb_test_add
(
test_set_basic
);
hb_test_add
(
test_set_algebra
);
hb_test_add
(
test_set_iter
);
#endif
hb_test_add
(
test_set_empty
);
return
hb_test_run
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录