mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "tkc/utils.h"
|
|
#include "widgets/edit_ipv4.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
TEST(Edit, ipv4_is_valid) {
|
|
widget_t* w = edit_create(NULL, 10, 20, 30, 40);
|
|
|
|
widget_set_text_utf8(w, "192.168.1.1");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), TRUE);
|
|
|
|
widget_set_text_utf8(w, "0.0.0.0");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), TRUE);
|
|
|
|
widget_set_text_utf8(w, "0.0");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_set_text_utf8(w, "0");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_set_text_utf8(w, "292.168.1.1");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_set_text_utf8(w, "192.368.1.1");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_set_text_utf8(w, "1.3.1.1223");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_set_text_utf8(w, "0001.3.1.12");
|
|
ASSERT_EQ(edit_ipv4_is_valid(w), FALSE);
|
|
|
|
widget_destroy(w);
|
|
}
|
|
|
|
TEST(Edit, ipv4_fix) {
|
|
widget_t* w = edit_create(NULL, 10, 20, 30, 40);
|
|
|
|
widget_set_text_utf8(w, "1922.168.1.1");
|
|
ASSERT_EQ(edit_ipv4_fix_ex(w, TRUE), RET_OK);
|
|
ASSERT_EQ(wcscmp(w->text.str, L"192.168.1.1"), 0);
|
|
|
|
widget_set_text_utf8(w, "1922.268.1.1");
|
|
ASSERT_EQ(edit_ipv4_fix_ex(w, TRUE), RET_OK);
|
|
ASSERT_EQ(wcscmp(w->text.str, L"192.26.1.1"), 0);
|
|
|
|
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);
|
|
}
|