Skip to content

Commit

Permalink
refactor: moved more tests, windows now tests ts_not_null
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Feb 19, 2024
1 parent 064ee8b commit b54ef4c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/unittest/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down
42 changes: 42 additions & 0 deletions src/unittest/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -35,4 +67,14 @@ void utilities_unit_tests() {
dpp::base64_encode(reinterpret_cast<unsigned char const*>("pqrstu"), 6) == "cHFyc3R1" &&
dpp::base64_encode(reinterpret_cast<unsigned char const*>("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);
}

0 comments on commit b54ef4c

Please sign in to comment.