summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-07-04 11:38:45 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-07-04 13:27:33 +0200
commit7c83ee02f22bed1166d3ffed208679fd016bb4b6 (patch)
tree91f3664c44f2903b57cbea5f81c249b286ea1702 /tests
parent8dc75564c2c799fae37014604d3cb085b6fe9699 (diff)
downloadweechat-7c83ee02f22bed1166d3ffed208679fd016bb4b6.zip
tests: add tests on typing plugin functions
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt7
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/unit/plugins/typing/test-typing-status.cpp137
-rw-r--r--tests/unit/plugins/typing/test-typing.cpp144
4 files changed, 295 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 00cba0348..42090eef0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -78,6 +78,13 @@ if(ENABLE_TRIGGER)
)
endif()
+if(ENABLE_TYPING)
+ list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC
+ unit/plugins/typing/test-typing.cpp
+ unit/plugins/typing/test-typing-status.cpp
+ )
+endif()
+
add_library(weechat_unit_tests_plugins MODULE ${LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC})
if(ICONV_LIBRARY)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9ea082f5d..2a6c7bf87 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,10 +88,16 @@ if PLUGIN_TRIGGER
tests_trigger = unit/plugins/trigger/test-trigger.cpp
endif
+if PLUGIN_TYPING
+tests_typing = unit/plugins/typing/test-typing.cpp \
+ unit/plugins/typing/test-typing-status.cpp
+endif
+
lib_weechat_unit_tests_plugins_la_SOURCES = unit/plugins/test-plugins.cpp \
$(tests_irc) \
$(tests_relay) \
- $(tests_trigger)
+ $(tests_trigger) \
+ $(tests_typing)
lib_weechat_unit_tests_plugins_la_LDFLAGS = -module -no-undefined
diff --git a/tests/unit/plugins/typing/test-typing-status.cpp b/tests/unit/plugins/typing/test-typing-status.cpp
new file mode 100644
index 000000000..dbe30ceb5
--- /dev/null
+++ b/tests/unit/plugins/typing/test-typing-status.cpp
@@ -0,0 +1,137 @@
+/*
+ * test-typing-status.cpp - test typing status functions
+ *
+ * Copyright (C) 2021 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CppUTest/TestHarness.h"
+
+extern "C"
+{
+#include "src/core/wee-hashtable.h"
+#include "src/gui/gui-buffer.h"
+#include "src/plugins/typing/typing-status.h"
+}
+
+#include "tests/tests.h"
+
+
+TEST_GROUP(TypingStatus)
+{
+};
+
+/*
+ * Tests functions:
+ * typing_status_search_state
+ */
+
+TEST(TypingStatus, SearchState)
+{
+ int i;
+
+ LONGS_EQUAL(-1, typing_status_search_state (NULL));
+ LONGS_EQUAL(-1, typing_status_search_state (""));
+ LONGS_EQUAL(-1, typing_status_search_state ("abc"));
+
+ for (i = 0; i < TYPING_STATUS_NUM_STATES; i++)
+ {
+ LONGS_EQUAL(i, typing_status_search_state (typing_status_state_string[i]));
+ }
+}
+
+/*
+ * Tests functions:
+ * typing_status_self_free_value_cb
+ * typing_status_self_add
+ * typing_status_self_search
+ */
+
+TEST(TypingStatus, SelfAddSearch)
+{
+ struct t_typing_status *ptr_typing_status;
+
+ POINTERS_EQUAL(NULL, typing_status_self_add (NULL, 0, 0));
+ POINTERS_EQUAL(NULL, typing_status_self_add (NULL, -1, 0));
+ POINTERS_EQUAL(NULL, typing_status_self_add (gui_buffers, -1, 0));
+ POINTERS_EQUAL(NULL, typing_status_self_add (gui_buffers, 999999, 0));
+
+ ptr_typing_status = typing_status_self_add (gui_buffers,
+ TYPING_STATUS_STATE_TYPING,
+ 1625390031);
+ CHECK(ptr_typing_status);
+ LONGS_EQUAL(TYPING_STATUS_STATE_TYPING, ptr_typing_status->state);
+ LONGS_EQUAL(1625390031, ptr_typing_status->last_typed);
+ LONGS_EQUAL(1, typing_status_self->items_count);
+ POINTERS_EQUAL(gui_buffers, typing_status_self->oldest_item->key);
+ POINTERS_EQUAL(ptr_typing_status, typing_status_self->oldest_item->value);
+ POINTERS_EQUAL(NULL, typing_status_self->oldest_item->next_created_item);
+
+ POINTERS_EQUAL(NULL, typing_status_self_search (NULL));
+ POINTERS_EQUAL(NULL, typing_status_self_search (gui_buffers + 1));
+ POINTERS_EQUAL(ptr_typing_status, typing_status_self_search (gui_buffers));
+
+ hashtable_remove_all (typing_status_self);
+}
+
+/*
+ * Tests functions:
+ * typing_status_nicks_free_value_cb
+ * typing_status_nick_free_value_cb
+ * typing_status_nick_add
+ * typing_status_nick_search
+ * typing_status_nick_remove
+ */
+
+TEST(TypingStatus, NickAddSearchRemove)
+{
+ struct t_typing_status *ptr_typing_status;
+ struct t_hashtable *ptr_nicks;
+
+ POINTERS_EQUAL(NULL, typing_status_nick_add (NULL, NULL, 0, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (NULL, "test", 0, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (NULL, "test", -1, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (NULL, "test", 999999, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (gui_buffers, NULL, -1, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (gui_buffers, "test", -1, 0));
+ POINTERS_EQUAL(NULL, typing_status_nick_add (gui_buffers, "test", 999999, 0));
+
+ ptr_typing_status = typing_status_nick_add (gui_buffers,
+ "alice",
+ TYPING_STATUS_STATE_TYPING,
+ 1625390031);
+ CHECK(ptr_typing_status);
+ LONGS_EQUAL(TYPING_STATUS_STATE_TYPING, ptr_typing_status->state);
+ LONGS_EQUAL(1625390031, ptr_typing_status->last_typed);
+ LONGS_EQUAL(1, typing_status_nicks->items_count);
+ POINTERS_EQUAL(gui_buffers, typing_status_nicks->oldest_item->key);
+ POINTERS_EQUAL(NULL, typing_status_nicks->oldest_item->next_created_item);
+ ptr_nicks = (struct t_hashtable *)hashtable_get (typing_status_nicks,
+ gui_buffers);
+ LONGS_EQUAL(1, ptr_nicks->items_count);
+ STRCMP_EQUAL("alice", (const char *)ptr_nicks->oldest_item->key);
+ POINTERS_EQUAL(ptr_typing_status, ptr_nicks->oldest_item->value);
+ POINTERS_EQUAL(NULL, ptr_nicks->oldest_item->next_created_item);
+
+ POINTERS_EQUAL(NULL, typing_status_nick_search (NULL, NULL));
+ POINTERS_EQUAL(NULL, typing_status_nick_search (gui_buffers, NULL));
+ POINTERS_EQUAL(NULL, typing_status_nick_search (gui_buffers, "abc"));
+ POINTERS_EQUAL(ptr_typing_status, typing_status_nick_search (gui_buffers,
+ "alice"));
+
+ hashtable_remove_all (typing_status_nicks);
+}
diff --git a/tests/unit/plugins/typing/test-typing.cpp b/tests/unit/plugins/typing/test-typing.cpp
new file mode 100644
index 000000000..eb4607e20
--- /dev/null
+++ b/tests/unit/plugins/typing/test-typing.cpp
@@ -0,0 +1,144 @@
+/*
+ * test-typing.cpp - test typing functions
+ *
+ * Copyright (C) 2021 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CppUTest/TestHarness.h"
+
+extern "C"
+{
+#include "src/plugins/typing/typing.h"
+}
+
+#include "tests/tests.h"
+
+
+TEST_GROUP(Typing)
+{
+};
+
+/*
+ * Tests functions:
+ * typing_send_signal
+ */
+
+TEST(Typing, SendSignal)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_buffer_closing_signal_cb
+ */
+
+TEST(Typing, BufferClosingSignalCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_input_text_changed_signal_cb
+ */
+
+TEST(Typing, InputTextChangedSignalCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_input_text_for_buffer_modifier_cb
+ */
+
+TEST(Typing, InputTextForBufferModifierCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_status_self_status_map_cb
+ */
+
+TEST(Typing, StatusSelfStatusMapCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_status_nicks_status_map_cb
+ */
+
+TEST(Typing, StatusNicksStatusMapCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_status_nicks_hash_map_cb
+ */
+
+TEST(Typing, StatusNicksHashMapCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_timer_cb
+ */
+
+TEST(Typing, TimerCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_typing_set_nick_signal_cb
+ */
+
+TEST(Typing, TypingSetNickSignalCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_typing_reset_buffer_signal_cb
+ */
+
+TEST(Typing, TypingResetBufferSignalCb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * typing_setup_hooks
+ */
+
+TEST(Typing, SetupHooks)
+{
+ /* TODO: write tests */
+}