D++ (DPP)  10.0.30
C++ Discord API Bot Library
unittest.cpp File Reference
#include "test.h"
#include <dpp/dpp.h>
#include <dpp/json.h>
Include dependency graph for unittest.cpp:

Namespaces

 anonymous_namespace{unittest.cpp}
 

Functions

double get_start_time ()
 Get the start time of tests. More...
 
std::string anonymous_namespace{unittest.cpp}::get_testdata_dir ()
 
double get_time ()
 Get the current execution time in seconds. More...
 
std::string get_token ()
 Get the token from the environment variable DPP_UNIT_TEST_TOKEN. More...
 
bool is_skipped (const test_t &test)
 Check if a test is/should be skipped. More...
 
std::vector< std::byte > load_data (const std::string &file)
 Load bytes from file. More...
 
std::vector< uint8_t > load_test_audio ()
 Load test audio for the voice channel tests. More...
 
void set_status (test_t &test, test_status_t newstatus, std::string_view message)
 Sets a test's status. More...
 
void set_test (test_t &test, bool success)
 Sets a test's status (legacy) More...
 
void skip_test (test_t &test)
 Sets a test's status to ts_skipped. More...
 
void start_test (test_t &test)
 Sets a test's status to ts_started. More...
 
int test_summary ()
 Prints a summary of all tests executed. More...
 
void wait_for_tests ()
 Wait for all tests to be completed or test program to time out. More...
 

Variables

bool extended = false
 
bool offline = false
 
double start = dpp::utility::time_f()
 
dpp::snowflake TEST_EVENT_ID = std::stoull((getenv( "TEST_EVENT_ID" ) && *(getenv( "TEST_EVENT_ID" )) ? getenv( "TEST_EVENT_ID" ) : "0"))
 
dpp::snowflake TEST_GUILD_ID = std::stoull((getenv( "TEST_GUILD_ID" ) && *(getenv( "TEST_GUILD_ID" )) ? getenv( "TEST_GUILD_ID" ) : "0"))
 
dpp::snowflake TEST_TEXT_CHANNEL_ID = std::stoull((getenv( "TEST_TEXT_CHANNEL_ID" ) && *(getenv( "TEST_TEXT_CHANNEL_ID" )) ? getenv( "TEST_TEXT_CHANNEL_ID" ) : "0"))
 
dpp::snowflake TEST_USER_ID = std::stoull((getenv( "TEST_USER_ID" ) && *(getenv( "TEST_USER_ID" )) ? getenv( "TEST_USER_ID" ) : "0"))
 
dpp::snowflake TEST_VC_ID = std::stoull((getenv( "TEST_VC_ID" ) && *(getenv( "TEST_VC_ID" )) ? getenv( "TEST_VC_ID" ) : "0"))
 

Function Documentation

◆ get_start_time()

double get_start_time ( )

Get the start time of tests.

Returns
double start time in fractional seconds

References start.

Referenced by get_time(), and main().

Here is the caller graph for this function:

◆ get_time()

double get_time ( )

Get the current execution time in seconds.

Returns
double fractional seconds

References get_start_time(), and dpp::utility::time_f().

Referenced by crossplatform_strptime(), set_status(), test_summary(), and wait_for_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_token()

std::string get_token ( )

Get the token from the environment variable DPP_UNIT_TEST_TOKEN.

Returns
std::string token
Note
If the environment variable does not exist, this will exit the program.

References offline.

Referenced by main().

Here is the caller graph for this function:

◆ is_skipped()

bool is_skipped ( const test_t test)

Check if a test is/should be skipped.

Returns
bool Whether the test is/should be skipped

References coro, extended, test_t::flags, offline, tf_coro, tf_extended, and tf_online.

Referenced by set_status(), and wait_for_tests().

Here is the caller graph for this function:

◆ load_data()

std::vector<std::byte> load_data ( const std::string &  file)

Load bytes from file.

Returns
std::vector<std::byte> File data

References anonymous_namespace{unittest.cpp}::get_testdata_dir().

Here is the call graph for this function:

◆ load_test_audio()

std::vector<uint8_t> load_test_audio ( )

Load test audio for the voice channel tests.

Returns
std::vector<uint8_t> data and size for test audio

References anonymous_namespace{unittest.cpp}::get_testdata_dir().

Here is the call graph for this function:

◆ set_status()

◆ set_test()

void set_test ( test_t test,
bool  success = false 
)

Sets a test's status (legacy)

Parameters
testThe test to set the status of
successIf set to true, sets success to true, if set to false and called once, sets executed to true, if called twice, also sets success to false. This means that before you run the test you should call this function once with success set to false, then if/wen the test completes call it again with true. If the test fails, call it a second time with false, or not at all.

References set_status(), test_t::status, ts_failed, ts_not_executed, ts_started, and ts_success.

Referenced by message_collector::completed(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skip_test()

void skip_test ( test_t test)

Sets a test's status to ts_skipped.

Parameters
testThe test to set the status of

References set_status(), and ts_skipped.

Here is the call graph for this function:

◆ start_test()

void start_test ( test_t test)

Sets a test's status to ts_started.

Parameters
testThe test to set the status of

References set_status(), and ts_started.

Referenced by coro_offline_tests(), coro_online_tests(), and event_handler_test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_summary()

int test_summary ( )

Prints a summary of all tests executed.

Parameters
testsList of tests executed
Returns
int Returns number of failed tests, for use as a return value from the main() function

References coro, extended, get_time(), offline, tests, tf_coro, tf_extended, tf_online, ts_not_executed, ts_skipped, and ts_success.

Here is the call graph for this function:

◆ wait_for_tests()

void wait_for_tests ( )

Wait for all tests to be completed or test program to time out.

References get_time(), is_skipped(), TEST_TIMEOUT, tests, ts_skipped, and ts_started.

Here is the call graph for this function:

Variable Documentation

◆ extended

bool extended = false

◆ offline

bool offline = false

◆ start

◆ TEST_EVENT_ID

dpp::snowflake TEST_EVENT_ID = std::stoull((getenv( "TEST_EVENT_ID" ) && *(getenv( "TEST_EVENT_ID" )) ? getenv( "TEST_EVENT_ID" ) : "0"))

Referenced by main().

◆ TEST_GUILD_ID

dpp::snowflake TEST_GUILD_ID = std::stoull((getenv( "TEST_GUILD_ID" ) && *(getenv( "TEST_GUILD_ID" )) ? getenv( "TEST_GUILD_ID" ) : "0"))

Referenced by event_handler_test(), and main().

◆ TEST_TEXT_CHANNEL_ID

dpp::snowflake TEST_TEXT_CHANNEL_ID = std::stoull((getenv( "TEST_TEXT_CHANNEL_ID" ) && *(getenv( "TEST_TEXT_CHANNEL_ID" )) ? getenv( "TEST_TEXT_CHANNEL_ID" ) : "0"))

Referenced by main().

◆ TEST_USER_ID

dpp::snowflake TEST_USER_ID = std::stoull((getenv( "TEST_USER_ID" ) && *(getenv( "TEST_USER_ID" )) ? getenv( "TEST_USER_ID" ) : "0"))

Referenced by event_handler_test(), and main().

◆ TEST_VC_ID

dpp::snowflake TEST_VC_ID = std::stoull((getenv( "TEST_VC_ID" ) && *(getenv( "TEST_VC_ID" )) ? getenv( "TEST_VC_ID" ) : "0"))

Referenced by main().