From c96e2f35934576e9ba0aa45901c6a80ecae7d856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 11 Jan 2019 22:26:16 +0100 Subject: [PATCH] tests: add tests on function irc_config_check_autojoin --- ChangeLog.adoc | 4 + doc/en/weechat_dev.en.adoc | 59 ++++++++------- doc/fr/weechat_dev.fr.adoc | 58 ++++++++------- doc/ja/weechat_dev.ja.adoc | 65 +++++++++------- src/plugins/irc/irc-config.h | 1 + tests/CMakeLists.txt | 45 ++++++----- tests/Makefile.am | 41 +++++----- tests/tests.cpp | 30 +++++++- ...-arraylist.cpp => test-core-arraylist.cpp} | 2 +- .../{test-eval.cpp => test-core-eval.cpp} | 2 +- ...-hashtable.cpp => test-core-hashtable.cpp} | 2 +- .../{test-hdata.cpp => test-core-hdata.cpp} | 2 +- .../{test-hook.cpp => test-core-hook.cpp} | 2 +- ...st-infolist.cpp => test-core-infolist.cpp} | 2 +- .../{test-list.cpp => test-core-list.cpp} | 2 +- .../{test-secure.cpp => test-core-secure.cpp} | 2 +- .../{test-string.cpp => test-core-string.cpp} | 2 +- .../core/{test-url.cpp => test-core-url.cpp} | 2 +- .../{test-utf8.cpp => test-core-utf8.cpp} | 2 +- .../{test-util.cpp => test-core-util.cpp} | 2 +- .../gui/{test-line.cpp => test-gui-line.cpp} | 2 +- tests/unit/plugins/irc/test-irc-config.cpp | 74 +++++++++++++++++++ 22 files changed, 274 insertions(+), 129 deletions(-) rename tests/unit/core/{test-arraylist.cpp => test-core-arraylist.cpp} (99%) rename tests/unit/core/{test-eval.cpp => test-core-eval.cpp} (99%) rename tests/unit/core/{test-hashtable.cpp => test-core-hashtable.cpp} (99%) rename tests/unit/core/{test-hdata.cpp => test-core-hdata.cpp} (97%) rename tests/unit/core/{test-hook.cpp => test-core-hook.cpp} (99%) rename tests/unit/core/{test-infolist.cpp => test-core-infolist.cpp} (99%) rename tests/unit/core/{test-list.cpp => test-core-list.cpp} (99%) rename tests/unit/core/{test-secure.cpp => test-core-secure.cpp} (99%) rename tests/unit/core/{test-string.cpp => test-core-string.cpp} (99%) rename tests/unit/core/{test-url.cpp => test-core-url.cpp} (96%) rename tests/unit/core/{test-utf8.cpp => test-core-utf8.cpp} (99%) rename tests/unit/core/{test-util.cpp => test-core-util.cpp} (98%) rename tests/unit/gui/{test-line.cpp => test-gui-line.cpp} (98%) create mode 100644 tests/unit/plugins/irc/test-irc-config.cpp diff --git a/ChangeLog.adoc b/ChangeLog.adoc index da5a02254..873ffde49 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -34,6 +34,10 @@ Bug fixes:: * buflist: fix warning displayed when script buffers.pl is loaded (issue #1274) * relay: fix memory leak in connection of client +Tests:: + + * unit: add tests on IRC configuration functions + Build:: * core: add C compiler flag "-fsigned--char" to force "char" data type to be always signed (issue #1277) diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index e55de186f..8175475ca 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -95,6 +95,9 @@ The main WeeChat directories are: |       python/ | Python scripts to generate and run the scripting API tests. |    unit/ | Unit tests. |       core/ | Unit tests for core functions. +|       gui/ | Unit tests for interfaces functions. +|       plugins/ | Unit tests for plugins. +|          irc/ | Unit tests for IRC plugin. | doc/ | Documentation. | po/ | Translations files (gettext). | debian/ | Debian packaging. @@ -371,32 +374,36 @@ WeeChat "core" is located in following directories: [width="100%",cols="1m,3",options="header"] |=== -| Path/file | Description -| tests/ | Root of tests. -|    tests.cpp | Program used to run all tests. -|    scripts/ | Root of scripting API tests. -|       test-scripts.cpp | Program used to run the scripting API tests. -|       python/ | Python scripts to generate and run the scripting API tests. -|          testapigen.py | Python script generating scripts in all languages to test the scripting API. -|          testapi.py | Python script with scripting API tests, used by script testapigen.py. -|          unparse.py | Convert Python code to other languages, used by script testapigen.py. -|    unit/ | Root of unit tests. -|       test-plugins.cpp | Tests: plugins. -|       core/ | Root of unit tests for core. -|          test-arraylist.cpp | Tests: arraylists. -|          test-eval.cpp | Tests: evaluation of expressions. -|          test-hashtble.cpp | Tests: hashtables. -|          test-hdata.cpp | Tests: hdata. -|          test-hook.cpp | Tests: hooks. -|          test-infolist.cpp | Tests: infolists. -|          test-list.cpp | Tests: lists. -|          test-secure.cpp | Tests: secured data. -|          test-string.cpp | Tests: strings. -|          test-url.cpp | Tests: URLs. -|          test-utf8.cpp | Tests: UTF-8. -|          test-util.cpp | Tests: utility functions. -|       gui/ | Root of unit tests for GUI. -|          test-line.cpp | Tests: lines. +| Path/file | Description +| tests/ | Root of tests. +|    tests.cpp | Program used to run all tests. +|    scripts/ | Root of scripting API tests. +|       test-scripts.cpp | Program used to run the scripting API tests. +|       python/ | Python scripts to generate and run the scripting API tests. +|          testapigen.py | Python script generating scripts in all languages to test the scripting API. +|          testapi.py | Python script with scripting API tests, used by script testapigen.py. +|          unparse.py | Convert Python code to other languages, used by script testapigen.py. +|    unit/ | Root of unit tests. +|       test-plugins.cpp | Tests: plugins. +|       core/ | Root of unit tests for core. +|          test-core-arraylist.cpp | Tests: arraylists. +|          test-core-eval.cpp | Tests: evaluation of expressions. +|          test-core-hashtble.cpp | Tests: hashtables. +|          test-core-hdata.cpp | Tests: hdata. +|          test-core-hook.cpp | Tests: hooks. +|          test-core-infolist.cpp | Tests: infolists. +|          test-core-list.cpp | Tests: lists. +|          test-core-secure.cpp | Tests: secured data. +|          test-core-string.cpp | Tests: strings. +|          test-core-url.cpp | Tests: URLs. +|          test-core-utf8.cpp | Tests: UTF-8. +|          test-core-util.cpp | Tests: utility functions. +|       gui/ | Root of unit tests for interfaces. +|          test-gui-line.cpp | Tests: lines. +|       plugins/ | Root of unit tests for plugins. +|          irc/ | Root of unit tests for IRC plugin. +|             test-irc-config.cpp | Tests: IRC configuration. + |=== [[documentation_translations]] diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index d40876439..a2ccb6478 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -97,6 +97,9 @@ Les répertoires principaux de WeeChat sont : |       python/ | Scripts Python pour générer et lancer les tests de l'API script. |    unit/ | Tests unitaires. |       core/ | Tests unitaires pour les fonctions du cœur. +|       gui/ | Tests unitaires pour les fonctions de l'interface. +|       plugins/ | Tests unitaires pour les extensions. +|          irc/ | Tests unitaires pour l'extension IRC. | doc/ | Documentation. | po/ | Fichiers de traductions (gettext). | debian/ | Empaquetage Debian. @@ -373,32 +376,35 @@ Le cœur de WeeChat est situé dans les répertoires suivants : [width="100%",cols="1m,3",options="header"] |=== -| Chemin/fichier | Description -| tests/ | Racine des tests. -|    tests.cpp | Programme utilisé pour lancer tous les tests. -|    scripts/ | Racine des tests de l'API script. -|       test-scripts.cpp | Programme utilisé pour lancer les tests de l'API script. -|       python/ | Scripts Python pour générer et lancer les tests de l'API script. -|          testapigen.py | Script Python générant des scripts dans tous les languages pour tester l'API script. -|          testapi.py | Script Python avec les tests API, utilisé par le script testapigen.py. -|          unparse.py | Conversion de code Python vers d'autres langages, utilisé par le script testapigen.py. -|    unit/ | Racine des tests unitaires. -|       test-plugins.cpp | Tests : extensions. -|       core/ | Racine des tests unitaires pour le cœur. -|          test-arraylist.cpp | Tests : listes avec tableau (« arraylists »). -|          test-eval.cpp | Tests : évaluation d'expressions. -|          test-hashtble.cpp | Tests : tables de hachage. -|          test-hdata.cpp | Tests : hdata. -|          test-hook.cpp | Tests : hooks. -|          test-infolist.cpp | Tests : infolists. -|          test-list.cpp | Tests : listes. -|          test-secure.cpp | Tests : données sécurisées. -|          test-string.cpp | Tests : chaînes. -|          test-url.cpp | Tests : URLs. -|          test-utf8.cpp | Tests : UTF-8. -|          test-util.cpp | Tests : fonctions utiles. -|       gui/ | Racine des tests unitaires pour la GUI. -|          test-line.cpp | Tests : lignes. +| Chemin/fichier | Description +| tests/ | Racine des tests. +|    tests.cpp | Programme utilisé pour lancer tous les tests. +|    scripts/ | Racine des tests de l'API script. +|       test-scripts.cpp | Programme utilisé pour lancer les tests de l'API script. +|       python/ | Scripts Python pour générer et lancer les tests de l'API script. +|          testapigen.py | Script Python générant des scripts dans tous les languages pour tester l'API script. +|          testapi.py | Script Python avec les tests API, utilisé par le script testapigen.py. +|          unparse.py | Conversion de code Python vers d'autres langages, utilisé par le script testapigen.py. +|    unit/ | Racine des tests unitaires. +|       test-plugins.cpp | Tests : extensions. +|       core/ | Racine des tests unitaires pour le cœur. +|          test-core-arraylist.cpp | Tests : listes avec tableau (« arraylists »). +|          test-core-eval.cpp | Tests : évaluation d'expressions. +|          test-core-hashtble.cpp | Tests : tables de hachage. +|          test-core-hdata.cpp | Tests : hdata. +|          test-core-hook.cpp | Tests : hooks. +|          test-core-infolist.cpp | Tests : infolists. +|          test-core-list.cpp | Tests : listes. +|          test-core-secure.cpp | Tests : données sécurisées. +|          test-core-string.cpp | Tests : chaînes. +|          test-core-url.cpp | Tests : URLs. +|          test-core-utf8.cpp | Tests : UTF-8. +|          test-core-util.cpp | Tests : fonctions utiles. +|       gui/ | Racine des tests unitaires pour les interfaces. +|          test-gui-line.cpp | Tests : lignes. +|       plugins/ | Racine des tests unitaires pour les extensions. +|          irc/ | Racine des tests unitaires pour l'extension IRC. +|             test-irc-config.cpp | Tests : configuration IRC. |=== [[documentation_translations]] diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 709aebade..e00c4a5cc 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -101,6 +101,12 @@ qweechat:: |       python/ | スクリプト API テストを生成、実行する Python スクリプト |    unit/ | 単体テスト |       core/ | コア関数の単体テスト +// TRANSLATION MISSING +|       gui/ | Unit tests for interfaces functions. +// TRANSLATION MISSING +|       plugins/ | Unit tests for plugins. +// TRANSLATION MISSING +|          irc/ | Unit tests for IRC plugin. | doc/ | 文書 | po/ | 翻訳ファイル (gettext) | debian/ | Debian パッケージ用 @@ -377,32 +383,39 @@ WeeChat "core" は以下のディレクトリに配置されています: [width="100%",cols="1m,3",options="header"] |=== -| パス/ファイル名 | 説明 -| tests/ | テスト用のルートディレクトリ -|    tests.cpp | 全テストの実行時に使われるプログラム -|    scripts/ | スクリプト API テスト用のルートディレクトリ -|       test-scripts.cpp | スクリプト API テストの実行時に使われるプログラム -|       python/ | スクリプト API テストを生成、実行する Python スクリプト -|          testapigen.py | スクリプト API のテスト時にすべての言語に関するスクリプトを生成する Python スクリプト -|          testapi.py | スクリプト API テスト時に使われる Python スクリプト (スクリプト testapigen.py から使われます) -|          unparse.py | Python コードを別の言語に変換 (スクリプト testapigen.py から使われます) -|    unit/ | 単体テスト用のルートディレクトリ -|       test-plugins.cpp | テスト: プラグイン -|       core/ | core 向け単体テスト用のルートディレクトリ -|          test-arraylist.cpp | テスト: 配列リスト -|          test-eval.cpp | テスト: 式の評価 -|          test-hashtble.cpp | テスト: ハッシュテーブル -|          test-hdata.cpp | テスト: hdata -|          test-hook.cpp | テスト: フック -|          test-infolist.cpp | テスト: インフォリスト -|          test-list.cpp | テスト: リスト -|          test-secure.cpp | テスト: データ保護 -|          test-string.cpp | テスト: 文字列 -|          test-url.cpp | テスト: URL -|          test-utf8.cpp | テスト: UTF-8 -|          test-util.cpp | テスト: ユーティリティ関数 -|       gui/ | GUI に関する単体テスト用のルートディレクトリ -|          test-line.cpp | テスト: 行 +| パス/ファイル名 | 説明 +| tests/ | テスト用のルートディレクトリ +|    tests.cpp | 全テストの実行時に使われるプログラム +|    scripts/ | スクリプト API テスト用のルートディレクトリ +|       test-scripts.cpp | スクリプト API テストの実行時に使われるプログラム +|       python/ | スクリプト API テストを生成、実行する Python スクリプト +|          testapigen.py | スクリプト API のテスト時にすべての言語に関するスクリプトを生成する Python スクリプト +|          testapi.py | スクリプト API テスト時に使われる Python スクリプト (スクリプト testapigen.py から使われます) +|          unparse.py | Python コードを別の言語に変換 (スクリプト testapigen.py から使われます) +|    unit/ | 単体テスト用のルートディレクトリ +|       test-plugins.cpp | テスト: プラグイン +|       core/ | core 向け単体テスト用のルートディレクトリ +|          test-core-arraylist.cpp | テスト: 配列リスト +|          test-core-eval.cpp | テスト: 式の評価 +|          test-core-hashtble.cpp | テスト: ハッシュテーブル +|          test-core-hdata.cpp | テスト: hdata +|          test-core-hook.cpp | テスト: フック +|          test-core-infolist.cpp | テスト: インフォリスト +|          test-core-list.cpp | テスト: リスト +|          test-core-secure.cpp | テスト: データ保護 +|          test-core-string.cpp | テスト: 文字列 +|          test-core-url.cpp | テスト: URL +|          test-core-utf8.cpp | テスト: UTF-8 +|          test-core-util.cpp | テスト: ユーティリティ関数 +// TRANSLATION MISSING +|       gui/ | Root of unit tests for interfaces. +|          test-gui-line.cpp | テスト: 行 +// TRANSLATION MISSING +|       plugins/ | Root of unit tests for plugins. +// TRANSLATION MISSING +|          irc/ | Root of unit tests for IRC plugin. +// TRANSLATION MISSING +|             test-irc-config.cpp | Tests: IRC configuration. |=== [[documentation_translations]] diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 755a1a0ba..b60be4737 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -189,6 +189,7 @@ extern char **irc_config_nicks_hide_password; extern int irc_config_num_nicks_hide_password; extern int irc_config_display_channel_modes_arguments (const char *modes); +extern int irc_config_check_autojoin (const char *autojoin); extern int irc_config_server_check_value_cb (const void *pointer, void *data, struct t_config_option *option, const char *value); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c6d1b20b..98b96d417 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,25 +22,31 @@ enable_language(CXX) remove_definitions(-DHAVE_CONFIG_H) include_directories(${CPPUTEST_INCLUDE_DIRS} ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}) -# unit tests -set(LIB_WEECHAT_UNIT_TESTS_SRC +# unit tests (core) +set(LIB_WEECHAT_UNIT_TESTS_CORE_SRC unit/test-plugins.cpp - unit/core/test-arraylist.cpp - unit/core/test-eval.cpp - unit/core/test-hashtable.cpp - unit/core/test-hdata.cpp - unit/core/test-hook.cpp - unit/core/test-infolist.cpp - unit/core/test-list.cpp - unit/core/test-secure.cpp - unit/core/test-string.cpp - unit/core/test-url.cpp - unit/core/test-utf8.cpp - unit/core/test-util.cpp - unit/gui/test-line.cpp + unit/core/test-core-arraylist.cpp + unit/core/test-core-eval.cpp + unit/core/test-core-hashtable.cpp + unit/core/test-core-hdata.cpp + unit/core/test-core-hook.cpp + unit/core/test-core-infolist.cpp + unit/core/test-core-list.cpp + unit/core/test-core-secure.cpp + unit/core/test-core-string.cpp + unit/core/test-core-url.cpp + unit/core/test-core-utf8.cpp + unit/core/test-core-util.cpp + unit/gui/test-gui-line.cpp scripts/test-scripts.cpp ) -add_library(weechat_unit_tests STATIC ${LIB_WEECHAT_UNIT_TESTS_SRC}) +add_library(weechat_unit_tests_core STATIC ${LIB_WEECHAT_UNIT_TESTS_CORE_SRC}) + +# unit tests (plugins) +set(LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC + unit/plugins/irc/test-irc-config.cpp +) +add_library(weechat_unit_tests_plugins MODULE ${LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC}) if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") list(APPEND EXTRA_LIBS "intl") @@ -59,7 +65,7 @@ set(LIBS ${PROJECT_BINARY_DIR}/src/gui/libweechat_gui_common.a ${PROJECT_BINARY_DIR}/src/gui/curses/headless/libweechat_gui_headless.a ${PROJECT_BINARY_DIR}/src/gui/curses/headless/libweechat_ncurses_fake.a - ${CMAKE_CURRENT_BINARY_DIR}/libweechat_unit_tests.a + ${CMAKE_CURRENT_BINARY_DIR}/libweechat_unit_tests_core.a # due to circular references, we must link two times with libweechat_core.a ${PROJECT_BINARY_DIR}/src/core/libweechat_core.a ${EXTRA_LIBS} @@ -69,7 +75,7 @@ target_link_libraries(tests ${LIBS}) add_dependencies(tests weechat_core weechat_plugins weechat_gui_common weechat_gui_headless weechat_ncurses_fake - weechat_unit_tests) + weechat_unit_tests_core) # test for cmake (ctest) add_test(NAME unit @@ -78,4 +84,5 @@ add_test(NAME unit set_property(TEST unit PROPERTY ENVIRONMENT "WEECHAT_TESTS_ARGS=-p;" "WEECHAT_EXTRA_LIBDIR=${PROJECT_BINARY_DIR}/src;" - "WEECHAT_TESTS_SCRIPTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}/scripts/python") + "WEECHAT_TESTS_SCRIPTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}/scripts/python" + "WEECHAT_TESTS_PLUGINS_LIB=${CMAKE_CURRENT_BINARY_DIR}/libweechat_unit_tests_plugins.so") diff --git a/tests/Makefile.am b/tests/Makefile.am index 6f7b8524e..f2689512e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,23 +19,23 @@ AM_CPPFLAGS = -DLOCALEDIR=\"$(datadir)/locale\" $(CPPUTEST_CFLAGS) -I$(abs_top_srcdir) -noinst_LIBRARIES = lib_weechat_unit_tests.a +noinst_LIBRARIES = lib_weechat_unit_tests_core.a -lib_weechat_unit_tests_a_SOURCES = unit/test-plugins.cpp \ - unit/core/test-arraylist.cpp \ - unit/core/test-eval.cpp \ - unit/core/test-hashtable.cpp \ - unit/core/test-hdata.cpp \ - unit/core/test-hook.cpp \ - unit/core/test-infolist.cpp \ - unit/core/test-list.cpp \ - unit/core/test-secure.cpp \ - unit/core/test-string.cpp \ - unit/core/test-url.cpp \ - unit/core/test-utf8.cpp \ - unit/core/test-util.cpp \ - unit/gui/test-line.cpp \ - scripts/test-scripts.cpp +lib_weechat_unit_tests_core_a_SOURCES = unit/test-plugins.cpp \ + unit/core/test-core-arraylist.cpp \ + unit/core/test-core-eval.cpp \ + unit/core/test-core-hashtable.cpp \ + unit/core/test-core-hdata.cpp \ + unit/core/test-core-hook.cpp \ + unit/core/test-core-infolist.cpp \ + unit/core/test-core-list.cpp \ + unit/core/test-core-secure.cpp \ + unit/core/test-core-string.cpp \ + unit/core/test-core-url.cpp \ + unit/core/test-core-utf8.cpp \ + unit/core/test-core-util.cpp \ + unit/gui/test-gui-line.cpp \ + scripts/test-scripts.cpp noinst_PROGRAMS = tests @@ -46,7 +46,7 @@ tests_LDADD = ./../src/core/lib_weechat_core.a \ ../src/gui/lib_weechat_gui_common.a \ ../src/gui/curses/headless/lib_weechat_gui_headless.a \ ../src/gui/curses/headless/lib_weechat_ncurses_fake.a \ - lib_weechat_unit_tests.a \ + lib_weechat_unit_tests_core.a \ ../src/core/lib_weechat_core.a \ $(PLUGINS_LFLAGS) \ $(GCRYPT_LFLAGS) \ @@ -54,8 +54,15 @@ tests_LDADD = ./../src/core/lib_weechat_core.a \ $(CURL_LFLAGS) \ $(CPPUTEST_LFLAGS) \ -lm +tests_LDFLAGS = -rdynamic tests_SOURCES = tests.cpp \ tests.h +lib_LTLIBRARIES = lib_weechat_unit_tests_plugins.la + +lib_weechat_unit_tests_plugins_la_SOURCES = unit/plugins/irc/test-irc-config.cpp + +lib_weechat_unit_tests_plugins_la_LDFLAGS = -module -no-undefined + EXTRA_DIST = CMakeLists.txt diff --git a/tests/tests.cpp b/tests/tests.cpp index 1196d1cdb..b4c1a8e90 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,10 @@ extern "C" #define WEECHAT_TESTS_HOME "./tmp_weechat_test" +/* lib with tests on plugins when autotools is used to compile */ +#define WEECHAT_TESTS_PLUGINS_LIB_DEFAULT \ + "./tests/.libs/lib_weechat_unit_tests_plugins.so.0.0.0" + /* import tests from libs */ /* core */ IMPORT_TEST_GROUP(Plugins); @@ -108,8 +113,11 @@ test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, (void) highlight; /* keep only messages displayed on core buffer */ - if (strcmp (gui_buffer_get_string (buffer, "full_name"), "core.weechat") != 0) + if (strcmp (gui_buffer_get_string (buffer, "full_name"), + "core.weechat") != 0) + { return WEECHAT_RC_OK; + } printf ("%s%s%s\n", /* with color: "\33[34m%s%s%s\33[0m\n" */ (prefix && prefix[0]) ? prefix : "", @@ -165,7 +173,10 @@ int main (int argc, char *argv[]) { int rc, length, weechat_argc; - char *weechat_tests_args, *args, **weechat_argv; + char *weechat_tests_args, *args, **weechat_argv, *tests_plugins_lib; + const char *tests_plugins_lib_default = WEECHAT_TESTS_PLUGINS_LIB_DEFAULT; + const char *ptr_path; + void *handle; /* setup environment: English language, no specific timezone */ setenv ("LC_ALL", LOCALE_TESTS, 1); @@ -225,6 +236,19 @@ main (int argc, char *argv[]) plugin_auto_load (NULL, 0, 1, 0, 0, NULL); } + /* load plugins tests */ + tests_plugins_lib = getenv ("WEECHAT_TESTS_PLUGINS_LIB"); + ptr_path = (tests_plugins_lib && tests_plugins_lib[0]) ? + tests_plugins_lib : tests_plugins_lib_default; + printf ("Loading tests on plugins: \"%s\"\n", ptr_path); + handle = dlopen (ptr_path, RTLD_GLOBAL | RTLD_NOW); + if (!handle) + { + fprintf (stderr, "ERROR: unable to load tests on plugins: %s\n", + dlerror ()); + return 1; + } + /* display WeeChat version and directories */ run_cmd ("/command core version"); run_cmd ("/debug dirs"); @@ -247,5 +271,7 @@ main (int argc, char *argv[]) (rc == 0) ? 32 : 31, /* 32 = green (OK), 31 = red (error) */ (rc == 0) ? "OK" : "ERROR"); + dlclose (handle); + return rc; } diff --git a/tests/unit/core/test-arraylist.cpp b/tests/unit/core/test-core-arraylist.cpp similarity index 99% rename from tests/unit/core/test-arraylist.cpp rename to tests/unit/core/test-core-arraylist.cpp index f24bbe02d..8f0f9aacf 100644 --- a/tests/unit/core/test-arraylist.cpp +++ b/tests/unit/core/test-core-arraylist.cpp @@ -1,5 +1,5 @@ /* - * test-arraylist.cpp - test arraylist functions + * test-core-arraylist.cpp - test arraylist functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-core-eval.cpp similarity index 99% rename from tests/unit/core/test-eval.cpp rename to tests/unit/core/test-core-eval.cpp index bfbd02d83..4f2a90e9e 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-core-eval.cpp @@ -1,5 +1,5 @@ /* - * test-eval.cpp - test evaluation functions + * test-core-eval.cpp - test evaluation functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-hashtable.cpp b/tests/unit/core/test-core-hashtable.cpp similarity index 99% rename from tests/unit/core/test-hashtable.cpp rename to tests/unit/core/test-core-hashtable.cpp index 4e3e51542..d7bedd6ef 100644 --- a/tests/unit/core/test-hashtable.cpp +++ b/tests/unit/core/test-core-hashtable.cpp @@ -1,5 +1,5 @@ /* - * test-hashtable.cpp - test hashtable functions + * test-core-hashtable.cpp - test hashtable functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-hdata.cpp b/tests/unit/core/test-core-hdata.cpp similarity index 97% rename from tests/unit/core/test-hdata.cpp rename to tests/unit/core/test-core-hdata.cpp index e27e40087..c92235f0f 100644 --- a/tests/unit/core/test-hdata.cpp +++ b/tests/unit/core/test-core-hdata.cpp @@ -1,5 +1,5 @@ /* - * test-hdata.cpp - test hdata functions + * test-core-hdata.cpp - test hdata functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-hook.cpp b/tests/unit/core/test-core-hook.cpp similarity index 99% rename from tests/unit/core/test-hook.cpp rename to tests/unit/core/test-core-hook.cpp index eb6605b4d..5fc9390f1 100644 --- a/tests/unit/core/test-hook.cpp +++ b/tests/unit/core/test-core-hook.cpp @@ -1,5 +1,5 @@ /* - * test-hook.cpp - test hook functions + * test-core-hook.cpp - test hook functions * * Copyright (C) 2018-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-infolist.cpp b/tests/unit/core/test-core-infolist.cpp similarity index 99% rename from tests/unit/core/test-infolist.cpp rename to tests/unit/core/test-core-infolist.cpp index 14de688a1..8a00b3be7 100644 --- a/tests/unit/core/test-infolist.cpp +++ b/tests/unit/core/test-core-infolist.cpp @@ -1,5 +1,5 @@ /* - * test-infolist.cpp - test infolist functions + * test-core-infolist.cpp - test infolist functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-list.cpp b/tests/unit/core/test-core-list.cpp similarity index 99% rename from tests/unit/core/test-list.cpp rename to tests/unit/core/test-core-list.cpp index 407fe6ea7..180fbb5e6 100644 --- a/tests/unit/core/test-list.cpp +++ b/tests/unit/core/test-core-list.cpp @@ -1,5 +1,5 @@ /* - * test-list.cpp - test list functions + * test-core-list.cpp - test list functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-secure.cpp b/tests/unit/core/test-core-secure.cpp similarity index 99% rename from tests/unit/core/test-secure.cpp rename to tests/unit/core/test-core-secure.cpp index ad4639ec4..48d587128 100644 --- a/tests/unit/core/test-secure.cpp +++ b/tests/unit/core/test-core-secure.cpp @@ -1,5 +1,5 @@ /* - * test-secure.cpp - test secured data functions + * test-core-secure.cpp - test secured data functions * * Copyright (C) 2018-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-core-string.cpp similarity index 99% rename from tests/unit/core/test-string.cpp rename to tests/unit/core/test-core-string.cpp index 224695a18..ea76b714e 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -1,5 +1,5 @@ /* - * test-string.cpp - test string functions + * test-core-string.cpp - test string functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-url.cpp b/tests/unit/core/test-core-url.cpp similarity index 96% rename from tests/unit/core/test-url.cpp rename to tests/unit/core/test-core-url.cpp index 2e5821e0f..18b19aafd 100644 --- a/tests/unit/core/test-url.cpp +++ b/tests/unit/core/test-core-url.cpp @@ -1,5 +1,5 @@ /* - * test-url.cpp - test URL functions + * test-core-url.cpp - test URL functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-utf8.cpp b/tests/unit/core/test-core-utf8.cpp similarity index 99% rename from tests/unit/core/test-utf8.cpp rename to tests/unit/core/test-core-utf8.cpp index 3a3cc78c9..b5f94d98a 100644 --- a/tests/unit/core/test-utf8.cpp +++ b/tests/unit/core/test-core-utf8.cpp @@ -1,5 +1,5 @@ /* - * test-utf8.cpp - test UTF-8 string functions + * test-core-utf8.cpp - test UTF-8 string functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/core/test-util.cpp b/tests/unit/core/test-core-util.cpp similarity index 98% rename from tests/unit/core/test-util.cpp rename to tests/unit/core/test-core-util.cpp index e87556e13..86627a3fe 100644 --- a/tests/unit/core/test-util.cpp +++ b/tests/unit/core/test-core-util.cpp @@ -1,5 +1,5 @@ /* - * test-util.cpp - test util functions + * test-core-util.cpp - test util functions * * Copyright (C) 2014-2019 Sébastien Helleu * diff --git a/tests/unit/gui/test-line.cpp b/tests/unit/gui/test-gui-line.cpp similarity index 98% rename from tests/unit/gui/test-line.cpp rename to tests/unit/gui/test-gui-line.cpp index 3b798f06d..dc652b3b2 100644 --- a/tests/unit/gui/test-line.cpp +++ b/tests/unit/gui/test-gui-line.cpp @@ -1,5 +1,5 @@ /* - * test-eval.cpp - test evaluation functions + * test-gui-line.cpp - test line functions * * Copyright (C) 2018-2019 Sébastien Helleu * diff --git a/tests/unit/plugins/irc/test-irc-config.cpp b/tests/unit/plugins/irc/test-irc-config.cpp new file mode 100644 index 000000000..a9af2702f --- /dev/null +++ b/tests/unit/plugins/irc/test-irc-config.cpp @@ -0,0 +1,74 @@ +/* + * test-irc-config.cpp - test IRC configuration functions + * + * Copyright (C) 2019 Sébastien Helleu + * + * 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 . + */ + +#include "CppUTest/TestHarness.h" + +extern "C" +{ +#include "src/plugins/irc/irc-config.h" +} + +TEST_GROUP(IrcConfig) +{ +}; + +/* + * Tests functions: + * irc_config_check_autojoin + */ + +TEST(IrcConfig, CheckAutojoin) +{ + /* NULL/empty string */ + LONGS_EQUAL(1, irc_config_check_autojoin(NULL)); + LONGS_EQUAL(1, irc_config_check_autojoin("")); + + /* wrong delimiter: space instead of comma */ + LONGS_EQUAL(0, irc_config_check_autojoin("#chan1 #chan2 #chan3")); + + /* no spaces allowed around comma */ + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1, #chan2")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1 ,#chan2")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1 , #chan2")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1, #chan2, #chan3")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1 ,#chan2 ,#chan3")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1 , #chan2 , #chan3")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1,#chan2 key1, key2")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1,#chan2 key1 ,key2")); + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1,#chan2 key1 , key2")); + + /* too many keys */ + LONGS_EQUAL(0, irc_config_check_autojoin ("#chan1,#chan2 key1,key2,key3")); + + /* correct values */ + LONGS_EQUAL(1, irc_config_check_autojoin ("#chan1")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#chan1 ")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#chan1 ")); + LONGS_EQUAL(1, irc_config_check_autojoin (" #chan1")); + LONGS_EQUAL(1, irc_config_check_autojoin (" #chan1")); + LONGS_EQUAL(1, irc_config_check_autojoin (" #chan1 ")); + LONGS_EQUAL(1, irc_config_check_autojoin (" #chan1 ")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#c1,#c2")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#c1,#c2,#c3")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#c1,#c2,#c3 key1")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#c1,#c2,#c3 key1,key2")); + LONGS_EQUAL(1, irc_config_check_autojoin ("#c1,#c2,#c3 key1,key2,key3")); +}