From d80b401f128ddc825da9b9fc0c09b1c9a0bfeab6 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Thu, 17 Sep 2020 15:05:16 +0800 Subject: [PATCH] improve tests --- tests/edit_date_test.cc | 37 ++++++++++++++++++++++++++++++++++++ tests/edit_ipv4_test.cc | 31 ++++++++++++++++++++++++++++++ tests/edit_time_full_test.cc | 34 +++++++++++++++++++++++++++++++++ tests/edit_time_test.cc | 30 +++++++++++++++++++++++++++++ tests/mem_pool_test.cc | 2 +- 5 files changed, 133 insertions(+), 1 deletion(-) diff --git a/tests/edit_date_test.cc b/tests/edit_date_test.cc index 04d866db0..9c8e6c8b2 100644 --- a/tests/edit_date_test.cc +++ b/tests/edit_date_test.cc @@ -52,6 +52,43 @@ TEST(Edit, date_fix) { widget_set_text_utf8(w, "20200/21/03"); ASSERT_EQ(edit_date_fix_ex(w, TRUE), RET_OK); ASSERT_EQ(wcscmp(w->text.str, L"2020/01/03"), 0); + + widget_set_text_utf8(w, "20200/21/03"); + ASSERT_EQ(edit_date_fix(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"2020/01/03"), 0); + + widget_destroy(w); +} + +TEST(Edit, inc_dec) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "20200/12/01"); + ASSERT_EQ(edit_date_fix_ex(w, TRUE), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"2020/12/01"), 0); + + ASSERT_EQ(edit_date_inc_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"2020/12/02"), 0); + + ASSERT_EQ(edit_date_dec_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"2020/12/01"), 0); + + widget_destroy(w); +} + +TEST(Edit, is_valid_char) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "20200/12/01"); + ASSERT_EQ(edit_date_fix_ex(w, TRUE), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"2020/12/01"), 0); + + widget_set_text_utf8(w, "20200/12/0"); + ASSERT_EQ(edit_date_is_valid_char(w, '1'), TRUE); + ASSERT_EQ(edit_date_pre_input(w, '1'), RET_OK); + + widget_set_text_utf8(w, "20200/12/01"); + ASSERT_EQ(edit_date_is_valid_char(w, '1'), FALSE); widget_destroy(w); } diff --git a/tests/edit_ipv4_test.cc b/tests/edit_ipv4_test.cc index dec8e4542..e96d628f5 100644 --- a/tests/edit_ipv4_test.cc +++ b/tests/edit_ipv4_test.cc @@ -46,6 +46,37 @@ TEST(Edit, ipv4_fix) { widget_set_text_utf8(w, "1922.268.0.1"); ASSERT_EQ(edit_ipv4_fix_ex(w, TRUE), RET_OK); ASSERT_EQ(wcscmp(w->text.str, L"192.26.0.1"), 0); + + widget_set_text_utf8(w, "1922.268.1.1"); + ASSERT_EQ(edit_ipv4_fix(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"192.26.1.1"), 0); + + widget_destroy(w); +} + +TEST(Edit, ipv4_inc_dec) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "192.26.0.1"); + ASSERT_EQ(edit_ipv4_inc_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"192.26.0.2"), 0); + + ASSERT_EQ(edit_ipv4_dec_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"192.26.0.1"), 0); + + widget_destroy(w); +} + +TEST(Edit, ipv4_is_valid_char) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "192.268.0.1"); + ASSERT_EQ(edit_ipv4_is_valid_char(w, '0'), TRUE); + ASSERT_EQ(edit_ipv4_pre_input(w, '0'), RET_OK); + + widget_set_text_utf8(w, "192.268.0.199"); + ASSERT_EQ(edit_ipv4_is_valid_char(w, '0'), FALSE); + ASSERT_EQ(edit_ipv4_pre_input(w, '0'), RET_OK); widget_destroy(w); } diff --git a/tests/edit_time_full_test.cc b/tests/edit_time_full_test.cc index 09688e659..250abc3e6 100644 --- a/tests/edit_time_full_test.cc +++ b/tests/edit_time_full_test.cc @@ -52,6 +52,40 @@ TEST(Edit, time_full_fix) { widget_set_text_utf8(w, "180:60:03"); ASSERT_EQ(edit_time_full_fix_ex(w, TRUE), RET_OK); ASSERT_EQ(wcscmp(w->text.str, L"18:00:03"), 0); + + widget_set_text_utf8(w, "180:60:03"); + ASSERT_EQ(edit_time_full_fix(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:00:03"), 0); + + widget_destroy(w); +} + +TEST(Edit, time_full_inc_dec) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "18:12:01"); + ASSERT_EQ(edit_time_full_inc_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:12:02"), 0); + + ASSERT_EQ(edit_time_full_dec_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:12:01"), 0); + + widget_destroy(w); +} + +TEST(Edit, time_full_is_valid_char) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "18:12:0"); + ASSERT_EQ(edit_time_full_is_valid_char(w, '0'), TRUE); + ASSERT_EQ(edit_time_full_pre_input(w, '0'), RET_OK); + + widget_set_text_utf8(w, "18:12:01"); + ASSERT_EQ(edit_time_full_is_valid_char(w, '0'), FALSE); + ASSERT_EQ(edit_time_full_pre_input(w, '0'), RET_OK); + + widget_set_text_utf8(w, "18:12:0"); + ASSERT_EQ(edit_time_full_is_valid_char(w, 'a'), FALSE); widget_destroy(w); } diff --git a/tests/edit_time_test.cc b/tests/edit_time_test.cc index 9561615f7..85ae05d0d 100644 --- a/tests/edit_time_test.cc +++ b/tests/edit_time_test.cc @@ -45,6 +45,36 @@ TEST(Edit, time_fix) { widget_set_text_utf8(w, "180:60"); ASSERT_EQ(edit_time_fix_ex(w, TRUE), RET_OK); ASSERT_EQ(wcscmp(w->text.str, L"18:00"), 0); + + widget_set_text_utf8(w, "180:60"); + ASSERT_EQ(edit_time_fix(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:00"), 0); + + widget_destroy(w); +} + +TEST(Edit, time_inc_dec) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "18:12"); + ASSERT_EQ(edit_time_inc_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:13"), 0); + ASSERT_EQ(edit_time_dec_value(w), RET_OK); + ASSERT_EQ(wcscmp(w->text.str, L"18:12"), 0); + + widget_destroy(w); +} + +TEST(Edit, time_is_valid_char) { + widget_t* w = edit_create(NULL, 10, 20, 30, 40); + + widget_set_text_utf8(w, "18:1"); + ASSERT_EQ(edit_time_pre_input(w, '0'), RET_OK); + ASSERT_EQ(edit_time_is_valid_char(w, '0'), TRUE); + + widget_set_text_utf8(w, "18:11"); + ASSERT_EQ(edit_time_pre_input(w, '0'), RET_OK); + ASSERT_EQ(edit_time_is_valid_char(w, '0'), FALSE); widget_destroy(w); } diff --git a/tests/mem_pool_test.cc b/tests/mem_pool_test.cc index dc9c20943..625a0b730 100644 --- a/tests/mem_pool_test.cc +++ b/tests/mem_pool_test.cc @@ -34,7 +34,7 @@ TEST(MemPool, basic2) { ASSERT_EQ(pool->block_size, 16); ASSERT_EQ(pool->used, 0); ASSERT_EQ(pool->bits_size, 4); - + ASSERT_EQ(mem_pool_match_size(pool, 9), TRUE); addr = mem_pool_get(pool); ASSERT_EQ(addr != NULL, true); ASSERT_EQ(mem_pool_put(pool, addr), RET_OK);