From a8080505f32eb5f899371a144a914dddfab189d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 8 Aug 2022 08:05:47 +0200 Subject: [PATCH] tests: add tests on function xfer_file_search_crc32 --- ChangeLog.adoc | 1 + doc/en/weechat_dev.en.adoc | 2 + doc/fr/weechat_dev.fr.adoc | 2 + doc/ja/weechat_dev.ja.adoc | 4 + doc/sr/weechat_dev.sr.adoc | 4 + tests/CMakeLists.txt | 6 ++ tests/Makefile.am | 7 +- tests/unit/plugins/xfer/test-xfer-file.cpp | 103 +++++++++++++++++++++ 8 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/unit/plugins/xfer/test-xfer-file.cpp diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 77f6419c1..8037c84af 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -50,6 +50,7 @@ Tests:: * core: remove macOS 10.15, add macOS 12 in CI * scripts: add tests on hdata functions * scripts: fix run of Guile test script + * xfer: add tests on file functions [[v3.6]] == Version 3.6 (2022-07-10) diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 55c2c6f74..f06b2d5ad 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -453,6 +453,8 @@ WeeChat "core" is located in following directories: |             test-typing-status.cpp | Tests: typing status. |          relay/ | Root of unit tests for Relay plugin. |             test-relay-auth.cpp | Tests: clients authentication. +|          xfer/ | Root of unit tests for Xfer plugin. +|             test-xfer-file.cpp | Tests: file functions. |=== [[documentation_translations]] diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index b0188a3c1..8b61d80f6 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -455,6 +455,8 @@ Le cœur de WeeChat est situé dans les répertoires suivants : |             test-typing-status.cpp | Tests : statut d'écriture. |          relay/ | Racine des tests unitaires pour l'extension Relay. |             test-relay-auth.cpp | Tests : authentification des clients. +|          xfer/ | Racine des tests unitaires pour l'extension Xfer. +|             test-xfer-file.cpp | Tests : fonctions sur les fichiers. |=== [[documentation_translations]] diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 8866da6f3..4779b2ccf 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -506,6 +506,10 @@ WeeChat "core" は以下のディレクトリに配置されています: |          relay/ | Root of unit tests for Relay plugin. // TRANSLATION MISSING |             test-relay-auth.cpp | Tests: clients authentication. +// TRANSLATION MISSING +|          xfer/ | Root of unit tests for Xfer plugin. +// TRANSLATION MISSING +|             test-xfer-file.cpp | Tests: file functions. |=== [[documentation_translations]] diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index 7a63df59d..1e60e2c4c 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -455,6 +455,10 @@ WeeChat „језгро” се налази у следећим директо |             test-typing-status.cpp | Тестови: typing статус. |          relay/ | Корен unit тестова за Релеј додатак. |             test-relay-auth.cpp | Тестови: аутентификација клијената. +// TRANSLATION MISSING +|          xfer/ | Root of unit tests for Xfer plugin. +// TRANSLATION MISSING +|             test-xfer-file.cpp | Tests: file functions. |=== [[documentation_translations]] diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 172e5a39a..0f5bd1e27 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -101,6 +101,12 @@ if(ENABLE_TYPING) ) endif() +if(ENABLE_XFER) + list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC + unit/plugins/xfer/test-xfer-file.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 892837f1b..0ae07b746 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -107,12 +107,17 @@ tests_typing = unit/plugins/typing/test-typing.cpp \ unit/plugins/typing/test-typing-status.cpp endif +if PLUGIN_XFER +tests_xfer = unit/plugins/xfer/test-xfer-file.cpp +endif + lib_weechat_unit_tests_plugins_la_SOURCES = unit/plugins/test-plugins.cpp \ $(tests_irc) \ $(tests_logger) \ $(tests_relay) \ $(tests_trigger) \ - $(tests_typing) + $(tests_typing) \ + $(tests_xfer) lib_weechat_unit_tests_plugins_la_LDFLAGS = -module -no-undefined diff --git a/tests/unit/plugins/xfer/test-xfer-file.cpp b/tests/unit/plugins/xfer/test-xfer-file.cpp new file mode 100644 index 000000000..7a3c50b67 --- /dev/null +++ b/tests/unit/plugins/xfer/test-xfer-file.cpp @@ -0,0 +1,103 @@ +/* + * test-xfer-file.cpp - test xfer file functions + * + * Copyright (C) 2022 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/xfer/xfer-file.h" +} + +TEST_GROUP(XferFile) +{ +}; + +/* + * Tests functions: + * xfer_file_search_crc32 + */ + +TEST(XferFile, SearchCrc32) +{ + POINTERS_EQUAL(NULL, xfer_file_search_crc32 (NULL)); + POINTERS_EQUAL(NULL, xfer_file_search_crc32 ("")); + POINTERS_EQUAL(NULL, xfer_file_search_crc32 ("a")); + POINTERS_EQUAL(NULL, xfer_file_search_crc32 ("z")); + POINTERS_EQUAL(NULL, xfer_file_search_crc32 ("123456781234abcd")); + POINTERS_EQUAL(NULL, xfer_file_search_crc32 ("test_filename")); + + /* valid CRC32 */ + STRCMP_EQUAL("1234abcd", xfer_file_search_crc32 ("test_1234abcd")); + STRCMP_EQUAL("1234aBCd", xfer_file_search_crc32 ("test_1234aBCd")); + STRCMP_EQUAL("1234abcd_test", xfer_file_search_crc32 ("1234abcd_test")); + STRCMP_EQUAL("1234Abcd_test", xfer_file_search_crc32 ("1234Abcd_test")); + STRCMP_EQUAL("12345678", xfer_file_search_crc32 ("1234abcd_12345678")); +} + +/* + * Tests functions: + * xfer_file_resume + */ + +TEST(XferFile, Resume) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * xfer_file_check_suffix + */ + +TEST(XferFile, CheckSuffix) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * xfer_file_find_suffix + */ + +TEST(XferFile, FindSuffix) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * xfer_file_find_filename + */ + +TEST(XferFile, FindFilename) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * xfer_file_calculate_speed + */ + +TEST(XferFile, CalculateSpeed) +{ + /* TODO: write tests */ +}