diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 14fb739430..47257282fb 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -79,15 +79,6 @@ int main(int argc, char *argv[]) std::cout << "Running offline and " << (extended ? "extended" : "limited") << " online unit tests. Guild ID: " << TEST_GUILD_ID << " Text Channel ID: " << TEST_TEXT_CHANNEL_ID << " VC ID: " << TEST_VC_ID << " User ID: " << TEST_USER_ID << " Event ID: " << TEST_EVENT_ID << "\n"; } - std::string test_to_escape = "*** _This is a test_ ***\n```cpp\n\ -int main() {\n\ - /* Comment */\n\ - int answer = 42;\n\ - return answer; // ___\n\ -};\n\ -```\n\ -Markdown lol ||spoiler|| ~~strikethrough~~ `small *code* block`\n"; - set_test(COMPARISON, false); dpp::user u1; dpp::user u2; @@ -190,29 +181,6 @@ Markdown lol ||spoiler|| ~~strikethrough~~ `small *code* block`\n"; set_test(ERRORS, error_message_success); - set_test(MD_ESC_1, false); - set_test(MD_ESC_2, false); - std::string escaped1 = dpp::utility::markdown_escape(test_to_escape); - std::string escaped2 = dpp::utility::markdown_escape(test_to_escape, true); - set_test(MD_ESC_1, escaped1 == "\\*\\*\\* \\_This is a test\\_ \\*\\*\\*\n\ -```cpp\n\ -int main() {\n\ - /* Comment */\n\ - int answer = 42;\n\ - return answer; // ___\n\ -};\n\ -```\n\ -Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ `small *code* block`\n"); - set_test(MD_ESC_2, escaped2 == "\\*\\*\\* \\_This is a test\\_ \\*\\*\\*\n\ -\\`\\`\\`cpp\n\ -int main\\(\\) {\n\ - /\\* Comment \\*/\n\ - int answer = 42;\n\ - return answer; // \\_\\_\\_\n\ -};\n\ -\\`\\`\\`\n\ -Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* block\\`\n"); - http_unit_tests(token); utilities_unit_tests(); @@ -227,9 +195,6 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b fclose(fp); set_test(READFILE, off == rf_test.length()); - set_test(TIMESTAMPTOSTRING, false); - set_test(TIMESTAMPTOSTRING, dpp::ts_to_string(1642611864) == "2022-01-19T17:04:24Z"); - set_test(ROLE_COMPARE, false); dpp::role role_1, role_2; role_1.position = 1; @@ -811,17 +776,6 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b ); } -#ifndef _WIN32 - set_test(TIMESTRINGTOTIMESTAMP, false); - json tj; - tj["t1"] = "2022-01-19T17:18:14.506000+00:00"; - tj["t2"] = "2022-01-19T17:18:14+00:00"; - uint32_t inTimestamp = 1642612694; - set_test(TIMESTRINGTOTIMESTAMP, (uint64_t)dpp::ts_not_null(&tj, "t1") == inTimestamp && (uint64_t)dpp::ts_not_null(&tj, "t2") == inTimestamp); -#else - set_test(TIMESTRINGTOTIMESTAMP, true); -#endif - { set_test(TS, false); dpp::managed m(189759562910400512); diff --git a/src/unittest/test.h b/src/unittest/test.h index 0f2b868294..1af3c9b0c5 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -507,8 +507,25 @@ double get_start_time(); */ double get_time(); +/** + * @brief This unit test covers the following: + * - get_host_info + * - HTTPS request + * - HTTP request + * - multiheader cookie test + * + * @param token + */ void http_unit_tests(const std::string& token); +/** + * @brief This unit test covers the following: + * - Markdown escaping + * - URL encoding + * - Base 64 encoding + * - ts_to_string + * - ts_not_null + */ void utilities_unit_tests(); /** diff --git a/src/unittest/utilities.cpp b/src/unittest/utilities.cpp index 5df89ad528..9e7c0bf864 100644 --- a/src/unittest/utilities.cpp +++ b/src/unittest/utilities.cpp @@ -22,6 +22,38 @@ #include "test.h" void utilities_unit_tests() { + std::string text_to_escape = "*** _This is a test_ ***\n```cpp\n\ +int main() {\n\ + /* Comment */\n\ + int answer = 42;\n\ + return answer; // ___\n\ +};\n\ +```\n\ +Markdown lol ||spoiler|| ~~strikethrough~~ `small *code* block`\n"; + + set_test(MD_ESC_1, false); + set_test(MD_ESC_2, false); + std::string escaped1 = dpp::utility::markdown_escape(text_to_escape); + std::string escaped2 = dpp::utility::markdown_escape(text_to_escape, true); + set_test(MD_ESC_1, escaped1 == "\\*\\*\\* \\_This is a test\\_ \\*\\*\\*\n\ +```cpp\n\ +int main() {\n\ + /* Comment */\n\ + int answer = 42;\n\ + return answer; // ___\n\ +};\n\ +```\n\ +Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ `small *code* block`\n"); + set_test(MD_ESC_2, escaped2 == "\\*\\*\\* \\_This is a test\\_ \\*\\*\\*\n\ +\\`\\`\\`cpp\n\ +int main\\(\\) {\n\ + /\\* Comment \\*/\n\ + int answer = 42;\n\ + return answer; // \\_\\_\\_\n\ +};\n\ +\\`\\`\\`\n\ +Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* block\\`\n"); + set_test(URLENC, false); set_test(URLENC, dpp::utility::url_encode("ABC123_+\\|$*/AAA[]😄") == "ABC123_%2B%5C%7C%24%2A%2FAAA%5B%5D%F0%9F%98%84"); @@ -35,4 +67,14 @@ void utilities_unit_tests() { dpp::base64_encode(reinterpret_cast("pqrstu"), 6) == "cHFyc3R1" && dpp::base64_encode(reinterpret_cast("vwxyz12"), 7) == "dnd4eXoxMg==" ); + + set_test(TIMESTAMPTOSTRING, false); + set_test(TIMESTAMPTOSTRING, dpp::ts_to_string(1642611864) == "2022-01-19T17:04:24Z"); + + set_test(TIMESTRINGTOTIMESTAMP, false); + json tj; + tj["t1"] = "2022-01-19T17:18:14.506000+00:00"; + tj["t2"] = "2022-01-19T17:18:14+00:00"; + uint32_t inTimestamp = 1642612694; + set_test(TIMESTRINGTOTIMESTAMP, (uint64_t)dpp::ts_not_null(&tj, "t1") == inTimestamp && (uint64_t)dpp::ts_not_null(&tj, "t2") == inTimestamp); }