Debian Codegraph @

src/unittest/test.h

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ************************************************************************************/
22 #undef DPP_BUILDcxx . . $ `<built-in>:503:9`!
23 #ifdef _WIN32
24 _Pragma("warning( disable : 4251 )"); // 4251 warns when we export classes or structures with stl member variables
25 _Pragma("warning( disable : 5105 )"); // 4251 warns when we export classes or structures with stl member variables
26 #endif
27 #include <dpp/dpp.h>cxx . . $ `<file>/include/dpp/dpp.h`/
28 #include <dpp/json_fwd.h>cxx . . $ `<file>/include/dpp/json_fwd.h`/
29 #include <iomanip>
30 #include <type_traits>
31
32 #ifdef _WIN32
33 #define SHARED_OBJECT "dpp.dll"
34 #elif __APPLE__
35 #define SHARED_OBJECT "libdpp.dylib"
36 #else
37 #define SHARED_OBJECTcxx . . $ `src/unittest/test.h:37:9`! "libdpp.so"
38 #endif
39
40 using jsoncxx . . $ json# = nlohmanncxx . . $ nlohmann/::jsoncxx . . $ nlohmann/json_abi_v3_11_3/json#;
41
42 extern stdcxx . . $ std/::mutexcxx . . $ std/mutex# loglockcxx . . $ loglock.;
43
44 enum test_flags_tcxx . . $ test_flags_t# {
45 tf_offlinecxx . . $ tf_offline. = 0,
46 /* A test that requires discord connectivity */
47 tf_onlinecxx . . $ tf_online. = 1,
48 /* A test that requires full tests to be enabled */
49 tf_extendedcxx . . $ tf_extended. = 1 << 1,
50 /* A test that requires coro to be enabled */
51 tf_corocxx . . $ tf_coro. = 1 << 2
52 };
53
54 enum test_status_tcxx . . $ test_status_t# {
55 /* Test was not executed */
56 ts_not_executedcxx . . $ ts_not_executed. = 0,
57 /* Test was started */
58 ts_startedcxx . . $ ts_started.,
59 /* Test was skipped */
60 ts_skippedcxx . . $ ts_skipped.,
61 /* Test succeeded */
62 ts_successcxx . . $ ts_success.,
63 /* Test failed */
64 ts_failedcxx . . $ ts_failed.
65 };
66
67 struct test_tcxx . . $ test_t#;
68
69 inline stdcxx . . $ std/::vectorcxx . . $ std/vector#<test_tcxx . . $ test_t# *> testscxx . . $ tests. = {cxx . . $ std/vector#vector(49f6e7a06ebc5aa8).};
70
71 /* Represents a test case */
72 struct test_tcxx . . $ test_t# {
73 stdcxx . . $ std/::string_viewcxx . . $ std/string_view# namecxx . . $ test_t#name.;
74 /* Description of test */
75 stdcxx . . $ std/::string_viewcxx . . $ std/string_view# descriptioncxx . . $ test_t#description.;
76 /* Test type */
77 test_flags_tcxx . . $ test_flags_t# flagscxx . . $ test_t#flags.;
78 /* Test status */
79 test_status_tcxx . . $ test_status_t# statuscxx . . $ test_t#status. = ts_not_executedcxx . . $ ts_not_executed.;
80
81 test_tcxx . . $ test_t#test_t(3a7d5cc967913103).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# testname, stdcxx . . $ std/::string_viewcxx . . $ std/string_view# testdesc, int testflags);
82 };
83
84 #define DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(name, desc, flags) inline test_t name = {#name, desc, flags}
85
86 /* Current list of unit tests */
87 DPP_TESTcxx . . $ tf_offline.(SNOWFLAKE, "dpp::snowflake class", tf_offline);
88 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(BIGNUM, "dpp::bignumber decimal to raw buffer", tf_offline);
89 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(BIGNUM2, "dpp::bignumber raw buffer to hex", tf_offline);
90 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(BIGNUM3, "dpp::bignumber to_binary()", tf_offline);
91 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(JSON_INTERFACE, "dpp::json_interface class", tf_offline);
92 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(CLUSTER, "Instantiate DPP cluster", tf_offline);
93 DPP_TESTcxx . . $ BOTSTART.(BOTSTART, "cluster::start method", tf_online);
94 DPP_TESTcxx . . $ tf_online.(CONNECTION, "Connection to client websocket", tf_online);
95 DPP_TESTcxx . . $ tf_online.(APPCOMMAND, "Creation of application command", tf_online);
96 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(DELCOMMAND, "Deletion of application command", tf_online);
97 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(GETAPP, "cluster::current_application_get()", tf_online);
98 DPP_TESTcxx . . $ tf_online.(LOGGER, "Log events", tf_online);
99 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(MESSAGECREATE, "Creation of a channel message", tf_online);
100 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(MESSAGEEDIT, "Editing a channel message", tf_online);
101 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(EDITEVENT, "Message edit event", tf_online);
102 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(MESSAGEDELETE, "Deletion of a channel message", tf_online);
103 DPP_TESTcxx . . $ tf_online.(MESSAGERECEIVE, "Receipt of a created message", tf_online);
104 DPP_TESTcxx . . $ MESSAGEFILE.(MESSAGEFILE, "Message attachment send and check", tf_online);
105 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(CACHE, "Test guild cache", tf_online);
106 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(USERCACHE, "Test user cache", tf_online);
107 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(REACT, "React to a message", tf_online);
108 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(REACTEVENT, "Reaction event", tf_online);
109 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GUILDCREATE, "Receive guild create event", tf_online);
110 DPP_TESTcxx . . $ MESSAGESGET.(MESSAGESGET, "Get messages", tf_online);
111 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(TIMESTAMP, "crossplatform_strptime()", tf_online);
112 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(ICONHASH, "utility::iconhash", tf_offline);
113 DPP_TESTcxx . . $ CURRENTUSER.(CURRENTUSER, "cluster::current_user_get()", tf_online);
114 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(GETGUILD, "cluster::guild_get()", tf_online);
115 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GETCHAN, "cluster::channel_get()", tf_online);
116 DPP_TESTcxx . . $ tf_online.(GETCHANS, "cluster::channels_get()", tf_online);
117 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(GETCHANNELINVS, "cluster::channel_invites_get()", tf_online);
118 DPP_TESTcxx . . $ tf_online.(GETROLES, "cluster::roles_get()", tf_online);
119 DPP_TESTcxx . . $ tf_online.(GETGUILDINVS, "cluster::guild_get_invites()", tf_online);
120 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GETBANS, "cluster::guild_get_bans()", tf_online);
121 DPP_TESTcxx . . $ GETPINS.(GETPINS, "cluster::channel_pins_get()", tf_online);
122 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(GETEVENTS, "cluster::guild_events_get()", tf_online);
123 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GETEVENT, "cluster::guild_event_get()", tf_online);
124 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(MSGCREATESEND, "message_create_t::send()", tf_online);
125 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GETEVENTUSERS, "cluster::guild_event_users_get()", tf_online);
126 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(TIMERSTART, "start timer", tf_online);
127 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(TIMERSTOP, "stop timer", tf_online);
128 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(ONESHOT, "one-shot timer", tf_online);
129 DPP_TESTcxx . . $ tf_online.(TIMEDLISTENER, "timed listener", tf_online);
130 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(PRESENCE, "Presence intent", tf_online);
131 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(CUSTOMCACHE, "Instantiate a cache", tf_offline);
132 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(MSGCOLLECT, "message_collector", tf_online);
133 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(TS, "managed::get_creation_date()", tf_online);
134 DPP_TESTcxx . . $ tf_offline.(READFILE, "utility::read_file()", tf_offline);
135 DPP_TESTcxx . . $ tf_offline.(TIMESTAMPTOSTRING, "ts_to_string()", tf_offline);
136 DPP_TESTcxx . . $ tf_offline.(TIMESTRINGTOTIMESTAMP, "ts_not_null()", tf_offline);
137 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(OPTCHOICE_DOUBLE, "command_option_choice::fill_from_json: double", tf_offline);
138 DPP_TESTcxx . . $ OPTCHOICE_INT.(OPTCHOICE_INT, "command_option_choice::fill_from_json: int64_t", tf_offline);
139 DPP_TESTcxx . . $ OPTCHOICE_BOOL.(OPTCHOICE_BOOL, "command_option_choice::fill_from_json: bool", tf_offline);
140 DPP_TESTcxx . . $ OPTCHOICE_SNOWFLAKE.(OPTCHOICE_SNOWFLAKE, "command_option_choice::fill_from_json: snowflake", tf_offline);
141 DPP_TESTcxx . . $ tf_offline.(OPTCHOICE_STRING, "command_option_choice::fill_from_json: string", tf_offline);
142 DPP_TESTcxx . . $ HOSTINFO.(HOSTINFO, "https_client::get_host_info()", tf_offline);
143 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(HTTPS, "https_client HTTPS request", tf_online);
144 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(HTTP, "https_client HTTP request", tf_online);
145 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(RUNONCE, "run_once<T>", tf_offline);
146 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(WEBHOOK, "webhook construct from URL", tf_offline);
147 DPP_TESTcxx . . $ MD_ESC_1.(MD_ESC_1, "Markdown escaping (ignore code block contents)", tf_offline);
148 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(MD_ESC_2, "Markdown escaping (escape code block contents)", tf_offline);
149 DPP_TESTcxx . . $ URLENC.(URLENC, "URL encoding", tf_offline);
150 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(BASE64ENC, "Base 64 encoding", tf_offline);
151 DPP_TESTcxx . . $ tf_offline.(COMPARISON, "manged object comparison", tf_offline);
152 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(CHANNELCACHE, "find_channel()", tf_online);
153 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(CHANNELTYPES, "channel type flags", tf_online);
154 DPP_TESTcxx . . $ FORUM_CREATION.(FORUM_CREATION, "create a forum channel", tf_online);
155 DPP_TESTcxx . . $ FORUM_CHANNEL_GET.(FORUM_CHANNEL_GET, "retrieve the created forum channel", tf_online);
156 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(FORUM_CHANNEL_DELETE, "delete the created forum channel", tf_online);
157 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(ERRORS, "Human readable error translation", tf_offline);
158 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(INVALIDUTF8, "Invalid UTF-8 handling", tf_online);
159
160 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(GUILD_EDIT, "cluster::guild_edit", tf_online);
161 DPP_TESTcxx . . $ tf_online.(GUILD_BAN_CREATE, "cluster::guild_ban_add ban three well-known discord accounts", tf_online);
162 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(GUILD_BAN_GET, "cluster::guild_get_ban getting one of the banned accounts", tf_online);
163 DPP_TESTcxx . . $ GUILD_BANS_GET.(GUILD_BANS_GET, "cluster::guild_get_bans get bans using the after-parameter", tf_online);
164 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(GUILD_BAN_DELETE, "cluster::guild_ban_delete unban the banned discord accounts", tf_online);
165
166 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(THREAD_CREATE, "cluster::thread_create", tf_online);
167 DPP_TESTcxx . . $ THREAD_CREATE_EVENT.(THREAD_CREATE_EVENT, "cluster::on_thread_create event", tf_online);
168 DPP_TESTcxx . . $ THREAD_DELETE.(THREAD_DELETE, "cluster::channel_delete with thread", tf_online);
169 DPP_TESTcxx . . $ tf_online.(THREAD_DELETE_EVENT, "cluster::on_thread_delete event", tf_online);
170 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(THREAD_EDIT, "cluster::thread_edit", tf_online);
171 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_UPDATE_EVENT, "cluster::on_thread_update event", tf_online);
172 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_GET_ACTIVE, "cluster::threads_get_active", tf_online);
173
174 DPP_TESTcxx . . $ VOICE_CHANNEL_CREATE.(VOICE_CHANNEL_CREATE, "creating a voice channel", tf_online);
175 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(VOICE_CHANNEL_EDIT, "editing the created voice channel", tf_online);
176 DPP_TESTcxx . . $ VOICE_CHANNEL_DELETE.(VOICE_CHANNEL_DELETE, "deleting the created voice channel", tf_online);
177
178 DPP_TESTcxx . . $ tf_offline.(PERMISSION_CLASS, "permission", tf_offline);
179 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(EVENT_CLASS, "event class", tf_offline);
180 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(USER_GET, "cluster::user_get", tf_online);
181 DPP_TESTcxx . . $ tf_online.(USER_GET_FLAGS, "cluster::user_get flag parsing", tf_online);
182 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(MEMBER_GET, "cluster::guild_get_member", tf_online);
183 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(USER_GET_MENTION, "user::get_mention", tf_offline);
184 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(USER_GET_URL, "user::get_url", tf_offline);
185 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(USER_FORMAT_USERNAME, "user::format_username", tf_offline);
186 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(USER_GET_CREATION_TIME, "user::get_creation_time", tf_offline);
187 DPP_TESTcxx . . $ USER_GET_AVATAR_URL.(USER_GET_AVATAR_URL, "user::get_avatar_url", tf_offline);
188 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(CHANNEL_SET_TYPE, "channel::set_type", tf_offline);
189 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(CHANNEL_GET_MENTION, "channel::get_mention", tf_offline);
190 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(CHANNEL_GET_URL, "channel::get_url", tf_offline);
191 DPP_TESTcxx . . $ MESSAGE_GET_URL.(MESSAGE_GET_URL,"message::get_url",tf_offline);
192 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(UTILITY_GUILD_NAVIGATION, "utility::guild_navigation", tf_offline);
193 DPP_TESTcxx . . $ tf_offline.(UTILITY_ICONHASH, "utility::iconhash", tf_offline);
194 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(UTILITY_MAKE_URL_PARAMETERS, "utility::make_url_parameters", tf_offline);
195 DPP_TESTcxx . . $ tf_offline.(UTILITY_MARKDOWN_ESCAPE, "utility::markdown_escape", tf_offline);
196 DPP_TESTcxx . . $ UTILITY_TOKENIZE.(UTILITY_TOKENIZE, "utility::tokenize", tf_offline);
197 DPP_TESTcxx . . $ UTILITY_URL_ENCODE.(UTILITY_URL_ENCODE, "utility::url_encode", tf_offline);
198 DPP_TESTcxx . . $ tf_offline.(UTILITY_SLASHCOMMAND_MENTION, "utility::slashcommand_mention", tf_offline);
199 DPP_TESTcxx . . $ UTILITY_CHANNEL_MENTION.(UTILITY_CHANNEL_MENTION, "utility::channel_mention", tf_offline);
200 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(UTILITY_USER_MENTION, "utility::user_mention", tf_offline);
201 DPP_TESTcxx . . $ UTILITY_ROLE_MENTION.(UTILITY_ROLE_MENTION, "utility::role_mention", tf_offline);
202 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(UTILITY_EMOJI_MENTION, "utility::emoji_mention", tf_offline);
203 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(UTILITY_USER_URL, "utility::user_url", tf_offline);
204 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(UTILITY_MESSAGE_URL, "utility::message_url", tf_offline);
205 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(UTILITY_CHANNEL_URL, "utility::channel_url", tf_offline);
206 DPP_TESTcxx . . $ tf_offline.(UTILITY_THREAD_URL, "utility::thread_url", tf_offline);
207 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(UTILITY_AVATAR_SIZE, "utility::avatar_size", tf_offline);
208 DPP_TESTcxx . . $ tf_offline.(UTILITY_CDN_ENDPOINT_URL_HASH, "utility::cdn_endpoint_url_hash", tf_offline);
209 DPP_TESTcxx . . $ STICKER_GET_URL.(STICKER_GET_URL, "sticker::get_url aka utility::cdn_endpoint_url_sticker", tf_offline);
210 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(EMOJI_GET_URL, "emoji::get_url", tf_offline);
211 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(ROLE_COMPARE, "role::operator<", tf_offline);
212 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(ROLE_COMPARE_CONSIDERING_ID, "role::operator<", tf_offline);
213 DPP_TESTcxx . . $ tf_online.(ROLE_CREATE, "cluster::role_create", tf_online);
214 DPP_TESTcxx . . $ tf_online.(ROLE_EDIT, "cluster::role_edit", tf_online);
215 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(ROLE_DELETE, "cluster::role_delete", tf_online);
216 DPP_TESTcxx . . $ tf_online.(JSON_PARSE_ERROR, "JSON parse error for post_rest", tf_online);
217 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(USER_GET_CACHED_PRESENT, "cluster::user_get_cached_sync() with present member", tf_online);
218 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(USER_GET_CACHED_ABSENT, "cluster::user_get_cached_sync() with not present member", tf_online);
219 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(GET_PARAMETER_WITH_SUBCOMMANDS, "interaction_create_t::get_parameter() with subcommands", tf_offline);
220 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(GET_PARAMETER_WITHOUT_SUBCOMMANDS, "interaction_create_t::get_parameter() without subcommands", tf_offline);
221 DPP_TESTcxx . . $ AUTOMOD_RULE_CREATE.(AUTOMOD_RULE_CREATE, "cluster::automod_rule_create", tf_online);
222 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(AUTOMOD_RULE_GET, "cluster::automod_rule_get", tf_online);
223 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(AUTOMOD_RULE_GET_ALL, "cluster::automod_rules_get", tf_online);
224 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(AUTOMOD_RULE_DELETE, "cluster::automod_rule_delete", tf_online);
225 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(REQUEST_GET_IMAGE, "using the cluster::request method to fetch an image", tf_online);
226 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(EMOJI_CREATE, "cluster::guild_emoji_create", tf_online);
227 DPP_TESTcxx . . $ EMOJI_GET.(EMOJI_GET, "cluster::guild_emoji_get", tf_online);
228 DPP_TESTcxx . . $ EMOJI_DELETE.(EMOJI_DELETE, "cluster::guild_emoji_delete", tf_online);
229 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(INVITE_CREATE_EVENT, "cluster::on_invite_create", tf_online);
230 DPP_TESTcxx . . $ INVITE_DELETE_EVENT.(INVITE_DELETE_EVENT, "cluster::on_invite_delete", tf_online);
231 DPP_TESTcxx . . $ tf_online.(INVITE_CREATE, "cluster::channel_invite_create", tf_online);
232 DPP_TESTcxx . . $ tf_online.(INVITE_GET, "cluster::invite_get", tf_online);
233 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(INVITE_DELETE, "cluster::invite_delete", tf_online);
234
235 /* Extended set -- Less important, skipped on the master branch due to rate limits and GitHub actions limitations */
236 /* To execute, run unittests with "full" command line argument */
237 DPP_TESTcxx . . $ MULTIHEADER.(MULTIHEADER, "multiheader cookie test", tf_online | tf_extended);
238
239 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(VOICECONN, "Connect to voice channel", tf_online | tf_extended);
240 DPP_TESTcxx . . $ tf_extended.(VOICESEND, "Send audio to voice channel", tf_online | tf_extended); // udp unreliable on gitbub
241 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(MESSAGEPIN, "Pinning a channel message", tf_online | tf_extended);
242 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(MESSAGEUNPIN, "Unpinning a channel message", tf_online | tf_extended);
243
244 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(POLL_CREATE, "Creating a poll", tf_online);
245 DPP_TESTcxx . . $ tf_online.(POLL_END, "Ending a poll", tf_online);
246
247 DPP_TESTcxx . . $ THREAD_MEMBER_ADD.(THREAD_MEMBER_ADD, "cluster::thread_member_add", tf_online | tf_extended);
248 DPP_TESTcxx . . $ THREAD_MEMBER_GET.(THREAD_MEMBER_GET, "cluster::thread_member_get", tf_online | tf_extended);
249 DPP_TESTcxx . . $ `src/unittest/test.h:84:9`!(THREAD_MEMBERS_GET, "cluster::thread_members_get", tf_online | tf_extended);
250 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_MEMBER_REMOVE, "cluster::thread_member_remove", tf_online | tf_extended);
251 DPP_TESTcxx . . $ tf_online.(THREAD_MEMBERS_ADD_EVENT, "cluster::on_thread_members_update event with member addition", tf_online | tf_extended);
252 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_MEMBERS_REMOVE_EVENT, "cluster::on_thread_members_update event with member removal", tf_online | tf_extended);
253 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_CREATE_MESSAGE, "cluster::thread_create_with_message", tf_online | tf_extended);
254
255 DPP_TESTcxx . . $ tf_extended.(THREAD_MESSAGE, "message manipulation in thread", tf_online | tf_extended);
256 DPP_TESTcxx . . $ tf_extended.(THREAD_MESSAGE_CREATE_EVENT, "cluster::on_message_create in thread", tf_online | tf_extended);
257 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(THREAD_MESSAGE_EDIT_EVENT, "cluster::on_message_edit in thread", tf_online | tf_extended);
258 DPP_TESTcxx . . $ THREAD_MESSAGE_DELETE_EVENT.(THREAD_MESSAGE_DELETE_EVENT, "cluster::on_message_delete in thread", tf_online | tf_extended);
259 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(THREAD_MESSAGE_REACT_ADD_EVENT, "cluster::on_reaction_add in thread", tf_online | tf_extended);
260 DPP_TESTcxx . . $ tf_online.(THREAD_MESSAGE_REACT_REMOVE_EVENT, "cluster::on_reaction_remove in thread", tf_online | tf_extended);
261
262 DPP_TESTcxx . . $ tf_coro.(CORO_JOB_OFFLINE, "coro: offline job", tf_offline | tf_coro);
263 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(CORO_AWAITABLE_OFFLINE, "coro: offline promise & awaitable", tf_offline | tf_coro);
264 DPP_TESTcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).(CORO_COROUTINE_OFFLINE, "coro: offline coroutine", tf_offline | tf_coro);
265 DPP_TESTcxx . . $ CORO_TASK_OFFLINE.(CORO_TASK_OFFLINE, "coro: offline task", tf_offline | tf_coro);
266 DPP_TESTcxx . . $ tf_coro.(CORO_ASYNC_OFFLINE, "coro: offline async", tf_offline | tf_coro);
267 DPP_TESTcxx . . $ tf_online.(CORO_EVENT_HANDLER, "coro: online event handler", tf_online | tf_coro);
268 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(CORO_API_CALLS, "coro: online api calls", tf_online | tf_coro);
269 DPP_TESTcxx . . $ CORO_MUMBO_JUMBO.(CORO_MUMBO_JUMBO, "coro: online mumbo jumbo in event handler", tf_online | tf_coro | tf_extended);
270
271 DPP_TESTcxx . . $ test_t#test_t(3a7d5cc967913103).(SNOWFLAKE_STD_FORMAT, "snowflake: std::format support", tf_offline);
272
273 void coro_offline_testscxx . . $ coro_offline_tests(49f6e7a06ebc5aa8).();
274 void coro_online_testscxx . . $ coro_online_tests(a8df4c8451c92bc4).(dpp::clustercxx . . $ dpp/cluster# *bot);
275
276 class test_cached_object_tcxx . . $ test_cached_object_t# : public dpp::managedcxx . . $ dpp/managed# {
277 public:
278 test_cached_object_tcxx . . $ test_cached_object_t#test_cached_object_t(1c8aeb7d200965fe).(dpp::snowflakecxx . . $ dpp/snowflake# _id) : dppcxx . . $ dpp/managed#managed(1c8aeb7d200965fe).::managedcxx . . $ dpp/managed#(_idcxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a).) { };
279 virtual ~cxx . . $ test_cached_object_t#`~test_cached_object_t`(ced63f7c635d850d).test_cached_object_tcxx . . $ test_cached_object_t#() = default;
280 stdcxx . . $ std/::stringcxx . . $ std/string# foocxx . . $ test_cached_object_t#foo.;
281 };
282
283 /* How long the unit tests can run for */
284 const int64_tcxx . . $ int64_t# TEST_TIMEOUTcxx . . $ TEST_TIMEOUT. = 60;
285
286 #define SAFE_GETENVcxx . . $ `src/unittest/test.h:286:9`!(var) (getenv(var) && *(getenv(var)) ? getenv(var) : "0")
287
288 /* IDs of various channels and guilds used to test */
289 extern dpp::snowflakecxx . . $ dpp/snowflake# TEST_GUILD_IDcxx . . $ TEST_GUILD_ID.;
290 extern dpp::snowflakecxx . . $ dpp/snowflake# TEST_TEXT_CHANNEL_IDcxx . . $ TEST_TEXT_CHANNEL_ID.;
291 extern dpp::snowflakecxx . . $ dpp/snowflake# TEST_VC_IDcxx . . $ TEST_VC_ID.;
292 extern dpp::snowflakecxx . . $ dpp/snowflake# TEST_USER_IDcxx . . $ TEST_USER_ID.;
293 extern dpp::snowflakecxx . . $ dpp/snowflake# TEST_EVENT_IDcxx . . $ TEST_EVENT_ID.;
294
295 /* True if we skip tt_online tests */
296 extern bool offlinecxx . . $ offline.;
297 /* True if we skip tt_extended tests */
298 extern bool extendedcxx . . $ extended.;
299 #ifndef DPP_NO_CORO
300 inline constexpr bool corocxx . . $ coro. = true;
301 #else
302 inline constexpr bool coro = false;
303 #endif
304
305 /**
306 * @brief Perform a test of a REST base API call with one parameter
307 */
308 #define singleparam_api_testcxx . . $ `src/unittest/test.h:308:9`!(func_name, param, return_type, testname) \
309 set_test(testname, false); \
310 if (!offline) { \
311 bot.func_name (param, [&](const dpp::confirmation_callback_t &cc) { \
312 if (!cc.is_error()) { \
313 return_type g = std::get<return_type>(cc.value); \
314 if (g.id == param) { \
315 set_test(testname, true); \
316 } else { \
317 bot.log(dpp::ll_debug, cc.http_info.body); \
318 set_test(testname, false); \
319 } \
320 } else { \
321 bot.log(dpp::ll_debug, cc.http_info.body); \
322 set_test(testname, false); \
323 } \
324 }); \
325 }
326
327 /**
328 * @brief Perform a test of a REST base API call with one parameter
329 */
330 #define twoparam_api_testcxx . . $ `src/unittest/test.h:330:9`!(func_name, param1, param2, return_type, testname) \
331 set_test(testname, false); \
332 if (!offline) { \
333 bot.func_name (param1, param2, [&](const dpp::confirmation_callback_t &cc) { \
334 if (!cc.is_error()) { \
335 return_type g = std::get<return_type>(cc.value); \
336 if (g.id > 0) { \
337 set_test(testname, true); \
338 } else { \
339 bot.log(dpp::ll_debug, cc.http_info.body); \
340 set_test(testname, false); \
341 } \
342 } else { \
343 bot.log(dpp::ll_debug, cc.http_info.body); \
344 set_test(testname, false); \
345 } \
346 }); \
347 }
348
349 /**
350 * @brief Perform a test of a REST base API call with one parameter that returns a list
351 */
352 #define singleparam_api_test_listcxx . . $ `src/unittest/test.h:352:9`!(func_name, param, return_type, testname) \
353 set_test(testname, false); \
354 if (!offline) { \
355 bot.func_name (param, [&](const dpp::confirmation_callback_t &cc) { \
356 if (!cc.is_error()) { \
357 return_type g = std::get<return_type>(cc.value); \
358 if (g.size() > 0) { \
359 set_test(testname, true); \
360 } else { \
361 set_test(testname, false); \
362 bot.log(dpp::ll_debug, cc.http_info.body); \
363 } \
364 } else { \
365 set_test(testname, false); \
366 bot.log(dpp::ll_debug, cc.http_info.body); \
367 } \
368 }); \
369 }
370
371 /**
372 * @brief Perform a test of a REST base API call with one parameter that returns a list
373 */
374 #define multiparam_api_test_listcxx . . $ `src/unittest/test.h:374:9`!(func_name, param, return_type, testname) \
375 set_test(testname, false); \
376 if (!offline) { \
377 bot.func_name (param, 0, 0, 1000, [&](const dpp::confirmation_callback_t &cc) { \
378 if (!cc.is_error()) { \
379 return_type g = std::get<return_type>(cc.value); \
380 if (g.size() > 0) { \
381 set_test(testname, true); \
382 } else { \
383 set_test(testname, false); \
384 bot.log(dpp::ll_debug, cc.http_info.body); \
385 } \
386 } else { \
387 set_test(testname, false); \
388 bot.log(dpp::ll_debug, cc.http_info.body); \
389 } \
390 }); \
391 }
392
393 /**
394 * @brief Perform a test of a REST base API call with two parameters
395 */
396 #define twoparam_api_test_listcxx . . $ `src/unittest/test.h:396:9`!(func_name, param1, param2, return_type, testname) \
397 set_test(testname, false); \
398 if (!offline) { \
399 bot.func_name (param1, param2, [&](const dpp::confirmation_callback_t &cc) { \
400 if (!cc.is_error()) { \
401 return_type g = std::get<return_type>(cc.value); \
402 if (g.size() > 0) { \
403 set_test(testname, true); \
404 } else { \
405 bot.log(dpp::ll_debug, cc.http_info.body); \
406 set_test(testname, false); \
407 } \
408 } else { \
409 bot.log(dpp::ll_debug, cc.http_info.body); \
410 set_test(testname, false); \
411 } \
412 }); \
413 }
414
415
416 /**
417 * @brief Perform a test of a REST base API call with no parameters
418 */
419 #define noparam_api_testcxx . . $ `src/unittest/test.h:419:9`!(func_name, return_type, testname) \
420 set_test(testname, false); \
421 if (!offline) { \
422 bot.func_name ([&](const dpp::confirmation_callback_t &cc) { \
423 if (!cc.is_error()) { \
424 return_type g = std::get<return_type>(cc.value); \
425 set_test(testname, true); \
426 } else { \
427 bot.log(dpp::ll_debug, cc.http_info.body); \
428 set_test(testname, false); \
429 } \
430 }); \
431 }
432
433 /**
434 * @brief Sets a test's status (legacy)
435 *
436 * @param test The test to set the status of
437 * @param success If set to true, sets success to true, if set to false and called
438 * once, sets executed to true, if called twice, also sets success to false.
439 * This means that before you run the test you should call this function once
440 * with success set to false, then if/wen the test completes call it again with true.
441 * If the test fails, call it a second time with false, or not at all.
442 */
443 void set_testcxx . . $ set_test(c715a584a48bbbaa).(test_tcxx . . $ test_t# &test, bool success = false);
444
445 /**
446 * @brief Sets a test's status
447 *
448 * @param test The test to set the status of
449 * @param status Status to set the test to
450 */
451 void set_statuscxx . . $ set_status(69213411294ab03e).(test_tcxx . . $ test_t# &test, test_status_tcxx . . $ test_status_t# status, stdcxx . . $ std/::string_viewcxx . . $ std/string_view# message =cxx . . $ std/basic_string_view#basic_string_view(ced63f7c635d850d). {});
452
453 /**
454 * @brief Sets a test's status to ts_skipped
455 *
456 * @param test The test to set the status of
457 */
458 void skip_testcxx . . $ skip_test(271d3161c6a64dec).(test_tcxx . . $ test_t# &test);
459
460 /**
461 * @brief Sets a test's status to ts_started
462 *
463 * @param test The test to set the status of
464 */
465 void start_testcxx . . $ start_test(271d3161c6a64dec).(test_tcxx . . $ test_t# &test);
466
467 /**
468 * @brief Check if a test is/should be skipped
469 *
470 * @return bool Whether the test is/should be skipped
471 */
472 bool is_skippedcxx . . $ is_skipped(b88c5c295d724553).(const test_tcxx . . $ test_t# &test);
473
474 /**
475 * @brief Prints a summary of all tests executed
476 * @param tests List of tests executed
477 *
478 * @return int Returns number of failed tests, for use as a return value from the main() function
479 */
480 int test_summarycxx . . $ test_summary(b126dc7c1de90089).();
481
482
483 /**
484 * @brief Load test audio for the voice channel tests
485 *
486 * @return std::vector<uint8_t> data and size for test audio
487 */
488 stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> load_test_audiocxx . . $ load_test_audio(695134cc693f8bd0).();
489
490 /**
491 * @brief Load bytes from file
492 *
493 * @return std::vector<std::byte> File data
494 */
495 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::bytecxx . . $ std/byte#> load_datacxx . . $ load_data(bfcd96bf31b7b509).(const stdcxx . . $ std/::stringcxx . . $ std/string#& file);
496
497 /**
498 * @brief Get the token from the environment variable DPP_UNIT_TEST_TOKEN
499 *
500 * @return std::string token
501 * @note If the environment variable does not exist, this will exit the program.
502 */
503 stdcxx . . $ std/::stringcxx . . $ std/string# get_tokencxx . . $ get_token(efd28698952f529a).();
504
505 /**
506 * @brief Wait for all tests to be completed or test program to time out
507 */
508 void wait_for_testscxx . . $ wait_for_tests(49f6e7a06ebc5aa8).();
509
510 /**
511 * @brief Get the start time of tests
512 *
513 * @return double start time in fractional seconds
514 */
515 double get_start_timecxx . . $ get_start_time(31fa7155c10fdd13).();
516
517 /**
518 * @brief Get the current execution time in seconds
519 *
520 * @return double fractional seconds
521 */
522 double get_timecxx . . $ get_time(31fa7155c10fdd13).();
523
524 /**
525 * @brief A test version of the message collector for use in unit tests
526 */
527 class message_collectorcxx . . $ message_collector# : public dpp::message_collectorcxx . . $ dpp/message_collector# {
528 public:
529 message_collectorcxx . . $ message_collector#message_collector(9c33ec4441d171cb).(dpp::clustercxx . . $ dpp/cluster#* cl, uint64_tcxx . . $ uint64_t# duration) : dppcxx . . $ dpp/message_collector#message_collector(9c33ec4441d171cb).::message_collectorcxx . . $ dpp/message_collector#(cl, duration) { }
530
531 virtual void completedcxx . . $ message_collector#completed(bc38081822471da3).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<dpp::messagecxx . . $ dpp/message#>& list) {
532 set_testcxx . . $ set_test(c715a584a48bbbaa).(MSGCOLLECTcxx . . $ MSGCOLLECT., list.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() > 0);
533 }
534 };
535
536 /**
537 * @brief Convenience functor to get the snowflake of a certain type
538 */
539 struct user_project_id_tcxx . . $ user_project_id_t# {
540 dpp::snowflakecxx . . $ dpp/snowflake# operatorcxx . . $ user_project_id_t#`operator()`(dcd1f9236e423c17).()(const dpp::usercxx . . $ dpp/user# &user) const noexcept {
541 return usercxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a)..idcxx . . $ dpp/managed#id.;
542 }
543
544 dpp::snowflakecxx . . $ dpp/snowflake# operatorcxx . . $ user_project_id_t#`operator()`(c95bfe55bb563de7).()(const dpp::guild_membercxx . . $ dpp/guild_member# &user) const noexcept {
545 return usercxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a)..user_idcxx . . $ dpp/guild_member#user_id.;
546 }
547
548 dpp::snowflakecxx . . $ dpp/snowflake# operatorcxx . . $ user_project_id_t#`operator()`(3dfa1d611becb9d8).()(dpp::snowflakecxx . . $ dpp/snowflake# user) const noexcept {
549 return usercxx . . $ dpp/snowflake#snowflake(e05a5aa9c7d5882c).;
550 }
551
552 dpp::snowflakecxx . . $ dpp/snowflake# operatorcxx . . $ user_project_id_t#`operator()`(aee1ff25e8706783).()(const dpp::thread_membercxx . . $ dpp/thread_member# &user) const noexcept {
553 return usercxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a)..user_idcxx . . $ dpp/thread_member#user_id.;
554 }
555 };
556
557 /**
558 * @brief Convenience lambda to get the user snowflake of a certain user type
559 * @see user_project_id_t
560 */
561 inline constexpr user_project_id_tcxx . . $ user_project_id_t# get_user_snowflakecxx . . $ get_user_snowflake.;
562
563 /**
564 * @brief Convenience lambda to check if a certain user is the owner of the test bot, mostly meant to be passed to standard algorithms
565 * @see get_user_snowflake
566 *
567 * @return bool whether the user is the test bot owner
568 */
569 inline constexpr auto is_ownercxx . . $ is_owner. = [](auto &&user) noexcept {
570 return get_user_snowflakecxx . . $ get_user_snowflake.(user) == TEST_USER_IDcxx . . $ TEST_USER_ID.;
571 };
572
573 #define DPP_RUNTIME_CHECKcxx . . $ `src/unittest/test.h:573:9`!(test, check, var) if (!check) { var = false; set_status(test, ts_failed, "check failed: " #check); }
574 #define DPP_COMPILETIME_CHECKcxx . . $ `src/unittest/test.h:574:9`!(test, check, var) static_assert(check, #test ": " #check)
575
576 #ifndef DPP_STATIC_TEST
577 #define DPP_CHECKcxx . . $ `src/unittest/test.h:577:9`!(test, check, var) DPP_RUNTIME_CHECK(test, check, var)
578 #else
579 #define DPP_CHECK(test, check, var) DPP_COMPILETIME_CHECK(test, check, var)
580 #endif
581
582 #define DPP_CHECK_CONSTRUCT_ASSIGNcxx . . $ `src/unittest/test.h:582:9`!(test, type, var) do { \
583 DPP_CHECK(test, std::is_default_constructible_v<type>, var); \
584 DPP_CHECK(test, std::is_copy_constructible_v<type>, var); \
585 DPP_CHECK(test, std::is_move_constructible_v<type>, var); \
586 DPP_CHECK(test, std::is_copy_assignable_v<type>, var); \
587 DPP_CHECK(test, std::is_move_assignable_v<type>, var); \
588 } while(0)