summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-01-01 14:41:06 +0100
committerSébastien Helleu <flashcode@flashtux.org>2023-01-01 14:41:06 +0100
commit1fb6d52984800ae9ce06d5a7a919431ce5a2eef0 (patch)
tree70594ed8aa4afca41847435d2d65c327189ec917 /tests
parent727c46591143747f91438d1c84f44a2dffdfce78 (diff)
downloadweechat-1fb6d52984800ae9ce06d5a7a919431ce5a2eef0.zip
tests: add tests on gui input functions
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/gui/test-gui-input.cpp238
1 files changed, 225 insertions, 13 deletions
diff --git a/tests/unit/gui/test-gui-input.cpp b/tests/unit/gui/test-gui-input.cpp
index 86ac80bfb..2608ed937 100644
--- a/tests/unit/gui/test-gui-input.cpp
+++ b/tests/unit/gui/test-gui-input.cpp
@@ -27,6 +27,7 @@ extern "C"
#include "src/gui/gui-buffer.h"
#include "src/gui/gui-input.h"
+extern void gui_input_clipboard_copy (const char *buffer, int size);
extern void gui_input_delete_range (struct t_gui_buffer *buffer,
char *start, char *end);
}
@@ -162,7 +163,26 @@ TEST(GuiInput, InsertString)
TEST(GuiInput, ClipboardCopy)
{
- /* TODO: write tests */
+ if (gui_input_clipboard)
+ {
+ free (gui_input_clipboard);
+ gui_input_clipboard = NULL;
+ }
+
+ gui_input_clipboard_copy (NULL, 1);
+ POINTERS_EQUAL(NULL, gui_input_clipboard);
+
+ gui_input_clipboard_copy ("abc", -1);
+ POINTERS_EQUAL(NULL, gui_input_clipboard);
+
+ gui_input_clipboard_copy ("abc", 0);
+ POINTERS_EQUAL(NULL, gui_input_clipboard);
+
+ gui_input_clipboard_copy ("abc", 1);
+ STRCMP_EQUAL("a", gui_input_clipboard);
+
+ gui_input_clipboard_copy ("abc", 3);
+ STRCMP_EQUAL("abc", gui_input_clipboard);
}
/*
@@ -172,7 +192,16 @@ TEST(GuiInput, ClipboardCopy)
TEST(GuiInput, ClipboardPaste)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+
+ gui_input_clipboard_copy ("abc", 3);
+ gui_input_clipboard_paste (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 2);
+ gui_input_clipboard_copy ("def", 3);
+ gui_input_clipboard_paste (gui_buffers);
+ STRCMP_EQUAL("abdefc", gui_buffers->input_buffer);
}
/*
@@ -192,7 +221,7 @@ TEST(GuiInput, Return)
* gui_input_complete_previous
*/
-TEST(GuiInput, CompleteNext)
+TEST(GuiInput, Complete)
{
gui_input_replace_input (gui_buffers, "");
LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
@@ -215,6 +244,8 @@ TEST(GuiInput, CompleteNext)
STRCMP_EQUAL("/wallchops ", gui_buffers->input_buffer);
gui_input_complete_previous (gui_buffers);
STRCMP_EQUAL("/wait ", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -619,7 +650,22 @@ TEST(GuiInput, DeleteNextWord)
TEST(GuiInput, DeleteBeginningOfLine)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_delete_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "abcdef");
+ gui_input_set_pos (gui_buffers, 0);
+ gui_input_delete_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("abcdef", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_delete_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("def", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_delete_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
}
/*
@@ -629,7 +675,22 @@ TEST(GuiInput, DeleteBeginningOfLine)
TEST(GuiInput, DeleteEndOfLine)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_delete_end_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "abcdef");
+ gui_input_set_pos (gui_buffers, 6);
+ gui_input_delete_end_of_line (gui_buffers);
+ STRCMP_EQUAL("abcdef", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_delete_end_of_line (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 0);
+ gui_input_delete_end_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
}
/*
@@ -639,7 +700,14 @@ TEST(GuiInput, DeleteEndOfLine)
TEST(GuiInput, DeleteLine)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_delete_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "abcdef");
+ gui_input_set_pos (gui_buffers, 6);
+ gui_input_delete_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
}
/*
@@ -649,7 +717,24 @@ TEST(GuiInput, DeleteLine)
TEST(GuiInput, TransposeChars)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_transpose_chars (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "abc");
+ gui_input_set_pos (gui_buffers, 0);
+ gui_input_transpose_chars (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 1);
+ gui_input_transpose_chars (gui_buffers);
+ STRCMP_EQUAL("bac", gui_buffers->input_buffer);
+
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_transpose_chars (gui_buffers);
+ STRCMP_EQUAL("bca", gui_buffers->input_buffer);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -659,7 +744,23 @@ TEST(GuiInput, TransposeChars)
TEST(GuiInput, MoveBeginningOfLine)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc");
+ gui_input_set_pos (gui_buffers, 0);
+ gui_input_move_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_move_beginning_of_line (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -669,7 +770,23 @@ TEST(GuiInput, MoveBeginningOfLine)
TEST(GuiInput, MoveEndOfLine)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_end_of_line (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc");
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_move_end_of_line (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_set_pos (gui_buffers, 0);
+ gui_input_move_end_of_line (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -679,7 +796,30 @@ TEST(GuiInput, MoveEndOfLine)
TEST(GuiInput, MovePreviousChar)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_previous_char (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc");
+ gui_input_set_pos (gui_buffers, 3);
+ gui_input_move_previous_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(2, gui_buffers->input_buffer_pos);
+
+ gui_input_move_previous_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(1, gui_buffers->input_buffer_pos);
+
+ gui_input_move_previous_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_move_previous_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -689,7 +829,31 @@ TEST(GuiInput, MovePreviousChar)
TEST(GuiInput, MoveNextChar)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_next_char (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc");
+ gui_input_set_pos (gui_buffers, 0);
+
+ gui_input_move_next_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(1, gui_buffers->input_buffer_pos);
+
+ gui_input_move_next_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(2, gui_buffers->input_buffer_pos);
+
+ gui_input_move_next_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_move_next_char (gui_buffers);
+ STRCMP_EQUAL("abc", gui_buffers->input_buffer);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "");
}
/*
@@ -699,7 +863,31 @@ TEST(GuiInput, MoveNextChar)
TEST(GuiInput, MovePreviousWord)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_previous_word (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc/def");
+ gui_input_set_pos (gui_buffers, 0);
+
+ gui_input_move_previous_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_set_pos (gui_buffers, 7);
+
+ gui_input_move_previous_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(4, gui_buffers->input_buffer_pos);
+
+ gui_input_move_previous_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_move_previous_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
}
/*
@@ -709,7 +897,31 @@ TEST(GuiInput, MovePreviousWord)
TEST(GuiInput, MoveNextWord)
{
- /* TODO: write tests */
+ gui_input_replace_input (gui_buffers, "");
+ gui_input_move_next_word (gui_buffers);
+ STRCMP_EQUAL("", gui_buffers->input_buffer);
+ LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+ gui_input_replace_input (gui_buffers, "abc/def");
+ gui_input_set_pos (gui_buffers, 7);
+
+ gui_input_move_next_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(7, gui_buffers->input_buffer_pos);
+
+ gui_input_set_pos (gui_buffers, 0);
+
+ gui_input_move_next_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+ gui_input_move_next_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(7, gui_buffers->input_buffer_pos);
+
+ gui_input_move_next_word (gui_buffers);
+ STRCMP_EQUAL("abc/def", gui_buffers->input_buffer);
+ LONGS_EQUAL(7, gui_buffers->input_buffer_pos);
}
/*