test_macros.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /**************************************************************************/
  2. /* test_macros.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_MACROS_H
  31. #define TEST_MACROS_H
  32. #include "display_server_mock.h"
  33. #include "core/core_globals.h"
  34. #include "core/input/input_map.h"
  35. #include "core/object/message_queue.h"
  36. #include "core/variant/variant.h"
  37. // See documentation for doctest at:
  38. // https://github.com/onqtam/doctest/blob/master/doc/markdown/readme.md#reference
  39. #include "thirdparty/doctest/doctest.h"
  40. // The test is skipped with this, run pending tests with `--test --no-skip`.
  41. #define TEST_CASE_PENDING(name) TEST_CASE(name *doctest::skip())
  42. // The test case is marked as failed, but does not fail the entire test run.
  43. #define TEST_CASE_MAY_FAIL(name) TEST_CASE(name *doctest::may_fail())
  44. // Provide aliases to conform with Godot naming conventions (see error macros).
  45. #define TEST_COND(cond, ...) DOCTEST_CHECK_FALSE_MESSAGE(cond, __VA_ARGS__)
  46. #define TEST_FAIL(cond, ...) DOCTEST_FAIL(cond, __VA_ARGS__)
  47. #define TEST_FAIL_COND(cond, ...) DOCTEST_REQUIRE_FALSE_MESSAGE(cond, __VA_ARGS__)
  48. #define TEST_FAIL_COND_WARN(cond, ...) DOCTEST_WARN_FALSE_MESSAGE(cond, __VA_ARGS__)
  49. // Temporarily disable error prints to test failure paths.
  50. // This allows to avoid polluting the test summary with error messages.
  51. // The `print_error_enabled` boolean is defined in `core/core_globals.cpp` and
  52. // works at global scope. It's used by various loggers in `should_log()` method,
  53. // which are used by error macros which call into `OS::print_error`, effectively
  54. // disabling any error messages to be printed from the engine side (not tests).
  55. #define ERR_PRINT_OFF CoreGlobals::print_error_enabled = false;
  56. #define ERR_PRINT_ON CoreGlobals::print_error_enabled = true;
  57. // Stringify all `Variant` compatible types for doctest output by default.
  58. // https://github.com/onqtam/doctest/blob/master/doc/markdown/stringification.md
  59. #define DOCTEST_STRINGIFY_VARIANT(m_type) \
  60. template <> \
  61. struct doctest::StringMaker<m_type> { \
  62. static doctest::String convert(const m_type &p_val) { \
  63. const Variant val = p_val; \
  64. return val.operator ::String().utf8().get_data(); \
  65. } \
  66. };
  67. #define DOCTEST_STRINGIFY_VARIANT_POINTER(m_type) \
  68. template <> \
  69. struct doctest::StringMaker<m_type> { \
  70. static doctest::String convert(const m_type *p_val) { \
  71. const Variant val = p_val; \
  72. return val.operator ::String().utf8().get_data(); \
  73. } \
  74. };
  75. DOCTEST_STRINGIFY_VARIANT(Variant);
  76. DOCTEST_STRINGIFY_VARIANT(::String); // Disambiguate from `doctest::String`.
  77. DOCTEST_STRINGIFY_VARIANT(Vector2);
  78. DOCTEST_STRINGIFY_VARIANT(Vector2i);
  79. DOCTEST_STRINGIFY_VARIANT(Rect2);
  80. DOCTEST_STRINGIFY_VARIANT(Rect2i);
  81. DOCTEST_STRINGIFY_VARIANT(Vector3);
  82. DOCTEST_STRINGIFY_VARIANT(Vector3i);
  83. DOCTEST_STRINGIFY_VARIANT(Transform2D);
  84. DOCTEST_STRINGIFY_VARIANT(Plane);
  85. DOCTEST_STRINGIFY_VARIANT(Quaternion);
  86. DOCTEST_STRINGIFY_VARIANT(AABB);
  87. DOCTEST_STRINGIFY_VARIANT(Basis);
  88. DOCTEST_STRINGIFY_VARIANT(Transform3D);
  89. DOCTEST_STRINGIFY_VARIANT(::Color); // Disambiguate from `doctest::Color`.
  90. DOCTEST_STRINGIFY_VARIANT(StringName);
  91. DOCTEST_STRINGIFY_VARIANT(NodePath);
  92. DOCTEST_STRINGIFY_VARIANT(RID);
  93. DOCTEST_STRINGIFY_VARIANT_POINTER(Object);
  94. DOCTEST_STRINGIFY_VARIANT(Callable);
  95. DOCTEST_STRINGIFY_VARIANT(Signal);
  96. DOCTEST_STRINGIFY_VARIANT(Dictionary);
  97. DOCTEST_STRINGIFY_VARIANT(Array);
  98. DOCTEST_STRINGIFY_VARIANT(PackedByteArray);
  99. DOCTEST_STRINGIFY_VARIANT(PackedInt32Array);
  100. DOCTEST_STRINGIFY_VARIANT(PackedInt64Array);
  101. DOCTEST_STRINGIFY_VARIANT(PackedFloat32Array);
  102. DOCTEST_STRINGIFY_VARIANT(PackedFloat64Array);
  103. DOCTEST_STRINGIFY_VARIANT(PackedStringArray);
  104. DOCTEST_STRINGIFY_VARIANT(PackedVector2Array);
  105. DOCTEST_STRINGIFY_VARIANT(PackedVector3Array);
  106. DOCTEST_STRINGIFY_VARIANT(PackedColorArray);
  107. DOCTEST_STRINGIFY_VARIANT(PackedVector4Array);
  108. // Register test commands to be launched from the command-line.
  109. // For instance: REGISTER_TEST_COMMAND("gdscript-parser" &test_parser_func).
  110. // Example usage: `godot --test gdscript-parser`.
  111. typedef void (*TestFunc)();
  112. extern HashMap<String, TestFunc> *test_commands;
  113. int register_test_command(String p_command, TestFunc p_function);
  114. #define REGISTER_TEST_COMMAND(m_command, m_function) \
  115. DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), \
  116. register_test_command(m_command, m_function))
  117. // Utility macros to send an event actions to a given object
  118. // Requires Message Queue and InputMap to be setup.
  119. // SEND_GUI_ACTION - takes an input map key. e.g SEND_GUI_ACTION("ui_text_newline").
  120. // SEND_GUI_KEY_EVENT - takes a keycode set. e.g SEND_GUI_KEY_EVENT(Key::A | KeyModifierMask::META).
  121. // SEND_GUI_KEY_UP_EVENT - takes a keycode set. e.g SEND_GUI_KEY_UP_EVENT(Key::A | KeyModifierMask::META).
  122. // SEND_GUI_MOUSE_BUTTON_EVENT - takes a position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_EVENT(Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
  123. // SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT - takes a position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
  124. // SEND_GUI_MOUSE_MOTION_EVENT - takes a position, mouse mask and modifiers e.g SEND_GUI_MOUSE_MOTION_EVENT(Vector2(50, 50), MouseButtonMask::LEFT, KeyModifierMask::META);
  125. // SEND_GUI_DOUBLE_CLICK - takes a position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(Vector2(50, 50), KeyModifierMask::META);
  126. #define _SEND_DISPLAYSERVER_EVENT(m_event) ((DisplayServerMock *)(DisplayServer::get_singleton()))->simulate_event(m_event);
  127. #define SEND_GUI_ACTION(m_action) \
  128. { \
  129. const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(m_action); \
  130. const List<Ref<InputEvent>>::Element *first_event = events->front(); \
  131. Ref<InputEventKey> event = first_event->get()->duplicate(); \
  132. event->set_pressed(true); \
  133. _SEND_DISPLAYSERVER_EVENT(event); \
  134. MessageQueue::get_singleton()->flush(); \
  135. }
  136. #define SEND_GUI_KEY_EVENT(m_input) \
  137. { \
  138. Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
  139. event->set_pressed(true); \
  140. _SEND_DISPLAYSERVER_EVENT(event); \
  141. MessageQueue::get_singleton()->flush(); \
  142. }
  143. #define SEND_GUI_KEY_UP_EVENT(m_input) \
  144. { \
  145. Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
  146. event->set_pressed(false); \
  147. _SEND_DISPLAYSERVER_EVENT(event); \
  148. MessageQueue::get_singleton()->flush(); \
  149. }
  150. #define _UPDATE_EVENT_MODIFERS(m_event, m_modifers) \
  151. m_event->set_shift_pressed(((m_modifers) & KeyModifierMask::SHIFT) != Key::NONE); \
  152. m_event->set_alt_pressed(((m_modifers) & KeyModifierMask::ALT) != Key::NONE); \
  153. m_event->set_ctrl_pressed(((m_modifers) & KeyModifierMask::CTRL) != Key::NONE); \
  154. m_event->set_meta_pressed(((m_modifers) & KeyModifierMask::META) != Key::NONE);
  155. #define _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  156. Ref<InputEventMouseButton> event; \
  157. event.instantiate(); \
  158. event->set_position(m_screen_pos); \
  159. event->set_button_index(m_input); \
  160. event->set_button_mask(m_mask); \
  161. event->set_factor(1); \
  162. _UPDATE_EVENT_MODIFERS(event, m_modifers); \
  163. event->set_pressed(true);
  164. #define _CREATE_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  165. Ref<InputEventScreenTouch> event; \
  166. event.instantiate(); \
  167. event->set_position(m_screen_pos); \
  168. event->set_pressed(m_pressed); \
  169. event->set_double_tap(m_double);
  170. #define SEND_GUI_MOUSE_BUTTON_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  171. { \
  172. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
  173. _SEND_DISPLAYSERVER_EVENT(event); \
  174. MessageQueue::get_singleton()->flush(); \
  175. }
  176. #define SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  177. { \
  178. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
  179. event->set_pressed(false); \
  180. _SEND_DISPLAYSERVER_EVENT(event); \
  181. MessageQueue::get_singleton()->flush(); \
  182. }
  183. #define SEND_GUI_DOUBLE_CLICK(m_screen_pos, m_modifers) \
  184. { \
  185. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, MouseButton::LEFT, 0, m_modifers); \
  186. event->set_double_click(true); \
  187. _SEND_DISPLAYSERVER_EVENT(event); \
  188. MessageQueue::get_singleton()->flush(); \
  189. }
  190. // We toggle _print_error_enabled to prevent display server not supported warnings.
  191. #define SEND_GUI_MOUSE_MOTION_EVENT(m_screen_pos, m_mask, m_modifers) \
  192. { \
  193. bool errors_enabled = CoreGlobals::print_error_enabled; \
  194. CoreGlobals::print_error_enabled = false; \
  195. Ref<InputEventMouseMotion> event; \
  196. event.instantiate(); \
  197. event->set_position(m_screen_pos); \
  198. event->set_button_mask(m_mask); \
  199. _UPDATE_EVENT_MODIFERS(event, m_modifers); \
  200. _SEND_DISPLAYSERVER_EVENT(event); \
  201. MessageQueue::get_singleton()->flush(); \
  202. CoreGlobals::print_error_enabled = errors_enabled; \
  203. }
  204. #define SEND_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  205. { \
  206. _CREATE_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  207. _SEND_DISPLAYSERVER_EVENT(event); \
  208. MessageQueue::get_singleton()->flush(); \
  209. }
  210. // Utility class / macros for testing signals
  211. //
  212. // Use SIGNAL_WATCH(*object, "signal_name") to start watching
  213. // Makes sure to call SIGNAL_UNWATCH(*object, "signal_name") to stop watching in cleanup, this is not done automatically.
  214. //
  215. // The SignalWatcher will capture all signals and their args sent between checks.
  216. //
  217. // Use SIGNAL_CHECK("signal_name"), Vector<Vector<Variant>>), to check the arguments of all fired signals.
  218. // The outer vector is each fired signal, the inner vector the list of arguments for that signal. Order does matter.
  219. //
  220. // Use SIGNAL_CHECK_FALSE("signal_name") to check if a signal was not fired.
  221. //
  222. // Use SIGNAL_DISCARD("signal_name") to discard records all of the given signal, use only in placed you don't need to check.
  223. //
  224. // All signals are automatically discarded between test/sub test cases.
  225. class SignalWatcher : public Object {
  226. private:
  227. inline static SignalWatcher *singleton;
  228. /* Equal to: RBMap<String, Vector<Vector<Variant>>> */
  229. HashMap<String, Array> _signals;
  230. void _add_signal_entry(const Array &p_args, const String &p_name) {
  231. if (!_signals.has(p_name)) {
  232. _signals[p_name] = Array();
  233. }
  234. _signals[p_name].push_back(p_args);
  235. }
  236. void _signal_callback_zero(const String &p_name) {
  237. Array args;
  238. _add_signal_entry(args, p_name);
  239. }
  240. void _signal_callback_one(Variant p_arg1, const String &p_name) {
  241. Array args;
  242. args.push_back(p_arg1);
  243. _add_signal_entry(args, p_name);
  244. }
  245. void _signal_callback_two(Variant p_arg1, Variant p_arg2, const String &p_name) {
  246. Array args;
  247. args.push_back(p_arg1);
  248. args.push_back(p_arg2);
  249. _add_signal_entry(args, p_name);
  250. }
  251. void _signal_callback_three(Variant p_arg1, Variant p_arg2, Variant p_arg3, const String &p_name) {
  252. Array args;
  253. args.push_back(p_arg1);
  254. args.push_back(p_arg2);
  255. args.push_back(p_arg3);
  256. _add_signal_entry(args, p_name);
  257. }
  258. public:
  259. static SignalWatcher *get_singleton() { return singleton; }
  260. void watch_signal(Object *p_object, const String &p_signal) {
  261. MethodInfo method_info;
  262. ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
  263. switch (method_info.arguments.size()) {
  264. case 0: {
  265. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero).bind(p_signal));
  266. } break;
  267. case 1: {
  268. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one).bind(p_signal));
  269. } break;
  270. case 2: {
  271. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two).bind(p_signal));
  272. } break;
  273. case 3: {
  274. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three).bind(p_signal));
  275. } break;
  276. default: {
  277. MESSAGE("Signal ", p_signal, " arg count not supported.");
  278. } break;
  279. }
  280. }
  281. void unwatch_signal(Object *p_object, const String &p_signal) {
  282. MethodInfo method_info;
  283. ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
  284. switch (method_info.arguments.size()) {
  285. case 0: {
  286. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero));
  287. } break;
  288. case 1: {
  289. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one));
  290. } break;
  291. case 2: {
  292. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two));
  293. } break;
  294. case 3: {
  295. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three));
  296. } break;
  297. default: {
  298. MESSAGE("Signal ", p_signal, " arg count not supported.");
  299. } break;
  300. }
  301. }
  302. bool check(const String &p_name, const Array &p_args) {
  303. if (!_signals.has(p_name)) {
  304. MESSAGE("Signal ", p_name, " not emitted");
  305. return false;
  306. }
  307. if (p_args.size() != _signals[p_name].size()) {
  308. MESSAGE("Signal has " << _signals[p_name] << " expected " << p_args);
  309. discard_signal(p_name);
  310. return false;
  311. }
  312. bool match = true;
  313. for (int i = 0; i < p_args.size(); i++) {
  314. if (((Array)p_args[i]).size() != ((Array)_signals[p_name][i]).size()) {
  315. MESSAGE("Signal has " << _signals[p_name][i] << " expected " << p_args[i]);
  316. match = false;
  317. continue;
  318. }
  319. for (int j = 0; j < ((Array)p_args[i]).size(); j++) {
  320. if (((Array)p_args[i])[j] != ((Array)_signals[p_name][i])[j]) {
  321. MESSAGE("Signal has " << _signals[p_name][i] << " expected " << p_args[i]);
  322. match = false;
  323. break;
  324. }
  325. }
  326. }
  327. discard_signal(p_name);
  328. return match;
  329. }
  330. bool check_false(const String &p_name) {
  331. bool has = _signals.has(p_name);
  332. if (has) {
  333. MESSAGE("Signal has " << _signals[p_name] << " expected none.");
  334. }
  335. discard_signal(p_name);
  336. return !has;
  337. }
  338. void discard_signal(const String &p_name) {
  339. if (_signals.has(p_name)) {
  340. _signals.erase(p_name);
  341. }
  342. }
  343. void _clear_signals() {
  344. _signals.clear();
  345. }
  346. SignalWatcher() {
  347. singleton = this;
  348. }
  349. ~SignalWatcher() {
  350. singleton = nullptr;
  351. }
  352. };
  353. #define SIGNAL_WATCH(m_object, m_signal) SignalWatcher::get_singleton()->watch_signal(m_object, m_signal);
  354. #define SIGNAL_UNWATCH(m_object, m_signal) SignalWatcher::get_singleton()->unwatch_signal(m_object, m_signal);
  355. #define SIGNAL_CHECK(m_signal, m_args) CHECK(SignalWatcher::get_singleton()->check(m_signal, m_args));
  356. #define SIGNAL_CHECK_FALSE(m_signal) CHECK(SignalWatcher::get_singleton()->check_false(m_signal));
  357. #define SIGNAL_DISCARD(m_signal) SignalWatcher::get_singleton()->discard_signal(m_signal);
  358. #define MULTICHECK_STRING_EQ(m_obj, m_func, m_param1, m_eq) \
  359. CHECK(m_obj.m_func(m_param1) == m_eq); \
  360. CHECK(m_obj.m_func(U##m_param1) == m_eq); \
  361. CHECK(m_obj.m_func(L##m_param1) == m_eq); \
  362. CHECK(m_obj.m_func(String(m_param1)) == m_eq);
  363. #define MULTICHECK_STRING_INT_EQ(m_obj, m_func, m_param1, m_param2, m_eq) \
  364. CHECK(m_obj.m_func(m_param1, m_param2) == m_eq); \
  365. CHECK(m_obj.m_func(U##m_param1, m_param2) == m_eq); \
  366. CHECK(m_obj.m_func(L##m_param1, m_param2) == m_eq); \
  367. CHECK(m_obj.m_func(String(m_param1), m_param2) == m_eq);
  368. #define MULTICHECK_STRING_INT_INT_EQ(m_obj, m_func, m_param1, m_param2, m_param3, m_eq) \
  369. CHECK(m_obj.m_func(m_param1, m_param2, m_param3) == m_eq); \
  370. CHECK(m_obj.m_func(U##m_param1, m_param2, m_param3) == m_eq); \
  371. CHECK(m_obj.m_func(L##m_param1, m_param2, m_param3) == m_eq); \
  372. CHECK(m_obj.m_func(String(m_param1), m_param2, m_param3) == m_eq);
  373. #define MULTICHECK_STRING_STRING_EQ(m_obj, m_func, m_param1, m_param2, m_eq) \
  374. CHECK(m_obj.m_func(m_param1, m_param2) == m_eq); \
  375. CHECK(m_obj.m_func(U##m_param1, U##m_param2) == m_eq); \
  376. CHECK(m_obj.m_func(L##m_param1, L##m_param2) == m_eq); \
  377. CHECK(m_obj.m_func(String(m_param1), String(m_param2)) == m_eq);
  378. #define MULTICHECK_GET_SLICE(m_obj, m_param1, m_slices) \
  379. for (int i = 0; i < m_obj.get_slice_count(m_param1); ++i) { \
  380. CHECK(m_obj.get_slice(m_param1, i) == m_slices[i]); \
  381. } \
  382. for (int i = 0; i < m_obj.get_slice_count(U##m_param1); ++i) { \
  383. CHECK(m_obj.get_slice(U##m_param1, i) == m_slices[i]); \
  384. } \
  385. for (int i = 0; i < m_obj.get_slice_count(L##m_param1); ++i) { \
  386. CHECK(m_obj.get_slice(L##m_param1, i) == m_slices[i]); \
  387. } \
  388. for (int i = 0; i < m_obj.get_slice_count(String(m_param1)); ++i) { \
  389. CHECK(m_obj.get_slice(String(m_param1), i) == m_slices[i]); \
  390. }
  391. #define MULTICHECK_SPLIT(m_obj, m_func, m_param1, m_param2, m_param3, m_slices, m_expected_size) \
  392. do { \
  393. Vector<String> string_list; \
  394. \
  395. string_list = m_obj.m_func(m_param1, m_param2, m_param3); \
  396. CHECK(m_expected_size == string_list.size()); \
  397. for (int i = 0; i < string_list.size(); ++i) { \
  398. CHECK(string_list[i] == m_slices[i]); \
  399. } \
  400. \
  401. string_list = m_obj.m_func(U##m_param1, m_param2, m_param3); \
  402. CHECK(m_expected_size == string_list.size()); \
  403. for (int i = 0; i < string_list.size(); ++i) { \
  404. CHECK(string_list[i] == m_slices[i]); \
  405. } \
  406. \
  407. string_list = m_obj.m_func(L##m_param1, m_param2, m_param3); \
  408. CHECK(m_expected_size == string_list.size()); \
  409. for (int i = 0; i < string_list.size(); ++i) { \
  410. CHECK(string_list[i] == m_slices[i]); \
  411. } \
  412. \
  413. string_list = m_obj.m_func(String(m_param1), m_param2, m_param3); \
  414. CHECK(m_expected_size == string_list.size()); \
  415. for (int i = 0; i < string_list.size(); ++i) { \
  416. CHECK(string_list[i] == m_slices[i]); \
  417. } \
  418. } while (false)
  419. #endif // TEST_MACROS_H