diff options
author | James Booth <boothj5@gmail.com> | 2015-01-20 00:56:35 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-20 00:56:35 +0000 |
commit | 58239244bb703d770aa423d8fcea19522771ae0d (patch) | |
tree | 6f08e419088644f8ee776dd9258eb7f2a464b912 /tests | |
parent | 2ed78fe5afaa0197de65a0edbf2423b5d7fe9792 (diff) | |
download | profani-tty-58239244bb703d770aa423d8fcea19522771ae0d.tar.gz |
Added key insert handler tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_keyhandlers.c | 117 | ||||
-rw-r--r-- | tests/test_keyhandlers.h | 7 | ||||
-rw-r--r-- | tests/testsuite.c | 4 |
3 files changed, 111 insertions, 17 deletions
diff --git a/tests/test_keyhandlers.c b/tests/test_keyhandlers.c index e01133e1..2e29ec6d 100644 --- a/tests/test_keyhandlers.c +++ b/tests/test_keyhandlers.c @@ -11,19 +11,36 @@ static char line[INP_WIN_MAX]; +static int utf8_pos_to_col(char *str, int utf8_pos) +{ + int col = 0; + + int i = 0; + for (i = 0; i<utf8_pos; i++) { + col++; + gchar *ch = g_utf8_offset_to_pointer(str, i); + gunichar uni = g_utf8_get_char(ch); + if (g_unichar_iswide(uni)) { + col++; + } + } + + return col; +} + void append_non_wide_to_empty(void **state) { setlocale(LC_ALL, ""); line[0] = '\0'; int line_utf8_pos = 0; - int col = 0; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 'a', 80); assert_string_equal("a", line); assert_int_equal(line_utf8_pos, 1); - assert_int_equal(col, 1); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -32,14 +49,14 @@ void append_wide_to_empty(void **state) setlocale(LC_ALL, ""); line[0] = '\0'; int line_utf8_pos = 0; - int col = 0; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80); assert_string_equal("四", line); assert_int_equal(line_utf8_pos, 1); - assert_int_equal(col, 2); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -49,14 +66,14 @@ void append_non_wide_to_non_wide(void **state) strncpy(line, "a", 1); line[1] = '\0'; int line_utf8_pos = 1; - int col = 1; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80); assert_string_equal("ab", line); assert_int_equal(line_utf8_pos, 2); - assert_int_equal(col, 2); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -66,14 +83,14 @@ void append_wide_to_non_wide(void **state) strncpy(line, "a", 1); line[1] = '\0'; int line_utf8_pos = 1; - int col = 1; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80); assert_string_equal("a四", line); assert_int_equal(line_utf8_pos, 2); - assert_int_equal(col, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -83,14 +100,14 @@ void append_non_wide_to_wide(void **state) g_utf8_strncpy(line, "四", 1); line[strlen(line)] = '\0'; int line_utf8_pos = 1; - int col = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80); assert_string_equal("四b", line); assert_int_equal(line_utf8_pos, 2); - assert_int_equal(col, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -100,14 +117,14 @@ void append_wide_to_wide(void **state) g_utf8_strncpy(line, "四", 1); line[strlen(line)] = '\0'; int line_utf8_pos = 1; - int col = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 80); assert_string_equal("四三", line); assert_int_equal(line_utf8_pos, 2); - assert_int_equal(col, 4); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); } @@ -117,7 +134,7 @@ void append_no_wide_when_overrun(void **state) g_utf8_strncpy(line, "0123456789四1234567", 18); line[strlen(line)] = '\0'; int line_utf8_pos = 18; - int col = 19; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20); @@ -126,7 +143,7 @@ void append_no_wide_when_overrun(void **state) assert_string_equal("0123456789四1234567zzz", line); assert_int_equal(line_utf8_pos, 21); - assert_int_equal(col, 22); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 3); } @@ -136,7 +153,7 @@ void append_wide_when_overrun(void **state) g_utf8_strncpy(line, "0123456789四1234567", 18); line[strlen(line)] = '\0'; int line_utf8_pos = 18; - int col = 19; + int col = utf8_pos_to_col(line, line_utf8_pos); int pad_start = 0; key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20); @@ -145,6 +162,74 @@ void append_wide_when_overrun(void **state) assert_string_equal("0123456789四1234567三三三", line); assert_int_equal(line_utf8_pos, 21); - assert_int_equal(col, 25); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 6); +} + +void insert_non_wide_to_non_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd", 4); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, '0', 80); + + assert_string_equal("ab0cd", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void insert_wide_to_non_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd", 26); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 80); + + assert_string_equal("abがcd", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void insert_non_wide_to_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "ひらなひ", 4); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, '0', 80); + + assert_string_equal("ひら0なひ", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void insert_wide_to_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "ひらなひ", 4); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 80); + + assert_string_equal("ひら三なひ", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); } \ No newline at end of file diff --git a/tests/test_keyhandlers.h b/tests/test_keyhandlers.h index 142a05ef..f70ee81e 100644 --- a/tests/test_keyhandlers.h +++ b/tests/test_keyhandlers.h @@ -8,4 +8,9 @@ void append_non_wide_to_wide(void **state); void append_wide_to_wide(void **state); void append_no_wide_when_overrun(void **state); -void append_wide_when_overrun(void **state); \ No newline at end of file +void append_wide_when_overrun(void **state); + +void insert_non_wide_to_non_wide(void **state); +void insert_wide_to_non_wide(void **state); +void insert_non_wide_to_wide(void **state); +void insert_wide_to_wide(void **state); \ No newline at end of file diff --git a/tests/testsuite.c b/tests/testsuite.c index 4964d99d..3a60317e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -632,6 +632,10 @@ int main(int argc, char* argv[]) { unit_test(append_wide_to_wide), unit_test(append_no_wide_when_overrun), unit_test(append_wide_when_overrun), + unit_test(insert_non_wide_to_non_wide), + unit_test(insert_wide_to_non_wide), + unit_test(insert_non_wide_to_wide), + unit_test(insert_wide_to_wide), }; return run_tests(all_tests); |