test_macros.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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(Vector4);
  84. DOCTEST_STRINGIFY_VARIANT(Vector4i);
  85. DOCTEST_STRINGIFY_VARIANT(Transform2D);
  86. DOCTEST_STRINGIFY_VARIANT(Plane);
  87. DOCTEST_STRINGIFY_VARIANT(Projection);
  88. DOCTEST_STRINGIFY_VARIANT(Quaternion);
  89. DOCTEST_STRINGIFY_VARIANT(AABB);
  90. DOCTEST_STRINGIFY_VARIANT(Basis);
  91. DOCTEST_STRINGIFY_VARIANT(Transform3D);
  92. DOCTEST_STRINGIFY_VARIANT(::Color); // Disambiguate from `doctest::Color`.
  93. DOCTEST_STRINGIFY_VARIANT(StringName);
  94. DOCTEST_STRINGIFY_VARIANT(NodePath);
  95. DOCTEST_STRINGIFY_VARIANT(RID);
  96. DOCTEST_STRINGIFY_VARIANT_POINTER(Object);
  97. DOCTEST_STRINGIFY_VARIANT(Callable);
  98. DOCTEST_STRINGIFY_VARIANT(Signal);
  99. DOCTEST_STRINGIFY_VARIANT(Dictionary);
  100. DOCTEST_STRINGIFY_VARIANT(Array);
  101. DOCTEST_STRINGIFY_VARIANT(PackedByteArray);
  102. DOCTEST_STRINGIFY_VARIANT(PackedInt32Array);
  103. DOCTEST_STRINGIFY_VARIANT(PackedInt64Array);
  104. DOCTEST_STRINGIFY_VARIANT(PackedFloat32Array);
  105. DOCTEST_STRINGIFY_VARIANT(PackedFloat64Array);
  106. DOCTEST_STRINGIFY_VARIANT(PackedStringArray);
  107. DOCTEST_STRINGIFY_VARIANT(PackedVector2Array);
  108. DOCTEST_STRINGIFY_VARIANT(PackedVector3Array);
  109. DOCTEST_STRINGIFY_VARIANT(PackedColorArray);
  110. DOCTEST_STRINGIFY_VARIANT(PackedVector4Array);
  111. // Register test commands to be launched from the command-line.
  112. // For instance: REGISTER_TEST_COMMAND("gdscript-parser" &test_parser_func).
  113. // Example usage: `godot --test gdscript-parser`.
  114. typedef void (*TestFunc)();
  115. extern HashMap<String, TestFunc> *test_commands;
  116. int register_test_command(String p_command, TestFunc p_function);
  117. #define REGISTER_TEST_COMMAND(m_command, m_function) \
  118. DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), \
  119. register_test_command(m_command, m_function))
  120. // Utility macros to send an event actions to a given object
  121. // Requires Message Queue and InputMap to be setup.
  122. // SEND_GUI_ACTION - takes an input map key. e.g SEND_GUI_ACTION("ui_text_newline").
  123. // SEND_GUI_KEY_EVENT - takes a keycode set. e.g SEND_GUI_KEY_EVENT(Key::A | KeyModifierMask::META).
  124. // SEND_GUI_KEY_UP_EVENT - takes a keycode set. e.g SEND_GUI_KEY_UP_EVENT(Key::A | KeyModifierMask::META).
  125. // 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);
  126. // 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);
  127. // 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);
  128. // SEND_GUI_DOUBLE_CLICK - takes a position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(Vector2(50, 50), KeyModifierMask::META);
  129. #define _SEND_DISPLAYSERVER_EVENT(m_event) ((DisplayServerMock *)(DisplayServer::get_singleton()))->simulate_event(m_event);
  130. #define SEND_GUI_ACTION(m_action) \
  131. { \
  132. const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(m_action); \
  133. const List<Ref<InputEvent>>::Element *first_event = events->front(); \
  134. Ref<InputEventKey> event = first_event->get()->duplicate(); \
  135. event->set_pressed(true); \
  136. _SEND_DISPLAYSERVER_EVENT(event); \
  137. MessageQueue::get_singleton()->flush(); \
  138. }
  139. #define SEND_GUI_KEY_EVENT(m_input) \
  140. { \
  141. Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
  142. event->set_pressed(true); \
  143. _SEND_DISPLAYSERVER_EVENT(event); \
  144. MessageQueue::get_singleton()->flush(); \
  145. }
  146. #define SEND_GUI_KEY_UP_EVENT(m_input) \
  147. { \
  148. Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
  149. event->set_pressed(false); \
  150. _SEND_DISPLAYSERVER_EVENT(event); \
  151. MessageQueue::get_singleton()->flush(); \
  152. }
  153. #define _UPDATE_EVENT_MODIFERS(m_event, m_modifers) \
  154. m_event->set_shift_pressed(((m_modifers) & KeyModifierMask::SHIFT) != Key::NONE); \
  155. m_event->set_alt_pressed(((m_modifers) & KeyModifierMask::ALT) != Key::NONE); \
  156. m_event->set_ctrl_pressed(((m_modifers) & KeyModifierMask::CTRL) != Key::NONE); \
  157. m_event->set_meta_pressed(((m_modifers) & KeyModifierMask::META) != Key::NONE);
  158. #define _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  159. Ref<InputEventMouseButton> event; \
  160. event.instantiate(); \
  161. event->set_position(m_screen_pos); \
  162. event->set_button_index(m_input); \
  163. event->set_button_mask(m_mask); \
  164. event->set_factor(1); \
  165. _UPDATE_EVENT_MODIFERS(event, m_modifers); \
  166. event->set_pressed(true);
  167. #define _CREATE_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  168. Ref<InputEventScreenTouch> event; \
  169. event.instantiate(); \
  170. event->set_position(m_screen_pos); \
  171. event->set_pressed(m_pressed); \
  172. event->set_double_tap(m_double);
  173. #define SEND_GUI_MOUSE_BUTTON_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  174. { \
  175. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
  176. _SEND_DISPLAYSERVER_EVENT(event); \
  177. MessageQueue::get_singleton()->flush(); \
  178. }
  179. #define SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(m_screen_pos, m_input, m_mask, m_modifers) \
  180. { \
  181. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, m_input, m_mask, m_modifers); \
  182. event->set_pressed(false); \
  183. _SEND_DISPLAYSERVER_EVENT(event); \
  184. MessageQueue::get_singleton()->flush(); \
  185. }
  186. #define SEND_GUI_DOUBLE_CLICK(m_screen_pos, m_modifers) \
  187. { \
  188. _CREATE_GUI_MOUSE_EVENT(m_screen_pos, MouseButton::LEFT, 0, m_modifers); \
  189. event->set_double_click(true); \
  190. _SEND_DISPLAYSERVER_EVENT(event); \
  191. MessageQueue::get_singleton()->flush(); \
  192. }
  193. // We toggle _print_error_enabled to prevent display server not supported warnings.
  194. #define SEND_GUI_MOUSE_MOTION_EVENT(m_screen_pos, m_mask, m_modifers) \
  195. { \
  196. bool errors_enabled = CoreGlobals::print_error_enabled; \
  197. CoreGlobals::print_error_enabled = false; \
  198. Ref<InputEventMouseMotion> event; \
  199. event.instantiate(); \
  200. event->set_position(m_screen_pos); \
  201. event->set_button_mask(m_mask); \
  202. _UPDATE_EVENT_MODIFERS(event, m_modifers); \
  203. _SEND_DISPLAYSERVER_EVENT(event); \
  204. MessageQueue::get_singleton()->flush(); \
  205. CoreGlobals::print_error_enabled = errors_enabled; \
  206. }
  207. #define SEND_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  208. { \
  209. _CREATE_GUI_TOUCH_EVENT(m_screen_pos, m_pressed, m_double) \
  210. _SEND_DISPLAYSERVER_EVENT(event); \
  211. MessageQueue::get_singleton()->flush(); \
  212. }
  213. // Utility class / macros for testing signals
  214. //
  215. // Use SIGNAL_WATCH(*object, "signal_name") to start watching
  216. // Makes sure to call SIGNAL_UNWATCH(*object, "signal_name") to stop watching in cleanup, this is not done automatically.
  217. //
  218. // The SignalWatcher will capture all signals and their args sent between checks.
  219. //
  220. // Use SIGNAL_CHECK("signal_name"), Vector<Vector<Variant>>), to check the arguments of all fired signals.
  221. // The outer vector is each fired signal, the inner vector the list of arguments for that signal. Order does matter.
  222. //
  223. // Use SIGNAL_CHECK_FALSE("signal_name") to check if a signal was not fired.
  224. //
  225. // Use SIGNAL_DISCARD("signal_name") to discard records all of the given signal, use only in placed you don't need to check.
  226. //
  227. // All signals are automatically discarded between test/sub test cases.
  228. class SignalWatcher : public Object {
  229. private:
  230. inline static SignalWatcher *singleton;
  231. /* Equal to: RBMap<String, Vector<Vector<Variant>>> */
  232. HashMap<String, Array> _signals;
  233. void _add_signal_entry(const Array &p_args, const String &p_name) {
  234. if (!_signals.has(p_name)) {
  235. _signals[p_name] = Array();
  236. }
  237. _signals[p_name].push_back(p_args);
  238. }
  239. void _signal_callback_zero(const String &p_name) {
  240. Array args;
  241. _add_signal_entry(args, p_name);
  242. }
  243. void _signal_callback_one(Variant p_arg1, const String &p_name) {
  244. Array args;
  245. args.push_back(p_arg1);
  246. _add_signal_entry(args, p_name);
  247. }
  248. void _signal_callback_two(Variant p_arg1, Variant p_arg2, const String &p_name) {
  249. Array args;
  250. args.push_back(p_arg1);
  251. args.push_back(p_arg2);
  252. _add_signal_entry(args, p_name);
  253. }
  254. void _signal_callback_three(Variant p_arg1, Variant p_arg2, Variant p_arg3, const String &p_name) {
  255. Array args;
  256. args.push_back(p_arg1);
  257. args.push_back(p_arg2);
  258. args.push_back(p_arg3);
  259. _add_signal_entry(args, p_name);
  260. }
  261. public:
  262. static SignalWatcher *get_singleton() { return singleton; }
  263. void watch_signal(Object *p_object, const String &p_signal) {
  264. MethodInfo method_info;
  265. ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
  266. switch (method_info.arguments.size()) {
  267. case 0: {
  268. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero).bind(p_signal));
  269. } break;
  270. case 1: {
  271. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one).bind(p_signal));
  272. } break;
  273. case 2: {
  274. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two).bind(p_signal));
  275. } break;
  276. case 3: {
  277. p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three).bind(p_signal));
  278. } break;
  279. default: {
  280. MESSAGE("Signal ", p_signal, " arg count not supported.");
  281. } break;
  282. }
  283. }
  284. void unwatch_signal(Object *p_object, const String &p_signal) {
  285. MethodInfo method_info;
  286. ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
  287. switch (method_info.arguments.size()) {
  288. case 0: {
  289. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero));
  290. } break;
  291. case 1: {
  292. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one));
  293. } break;
  294. case 2: {
  295. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two));
  296. } break;
  297. case 3: {
  298. p_object->disconnect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three));
  299. } break;
  300. default: {
  301. MESSAGE("Signal ", p_signal, " arg count not supported.");
  302. } break;
  303. }
  304. }
  305. bool check(const String &p_name, const Array &p_args) {
  306. if (!_signals.has(p_name)) {
  307. MESSAGE("Signal ", p_name, " not emitted");
  308. return false;
  309. }
  310. if (p_args.size() != _signals[p_name].size()) {
  311. MESSAGE("Signal has " << _signals[p_name] << " expected " << p_args);
  312. discard_signal(p_name);
  313. return false;
  314. }
  315. bool match = true;
  316. for (int i = 0; i < p_args.size(); i++) {
  317. if (((Array)p_args[i]).size() != ((Array)_signals[p_name][i]).size()) {
  318. MESSAGE("Signal has " << _signals[p_name][i] << " expected " << p_args[i]);
  319. match = false;
  320. continue;
  321. }
  322. for (int j = 0; j < ((Array)p_args[i]).size(); j++) {
  323. if (((Array)p_args[i])[j] != ((Array)_signals[p_name][i])[j]) {
  324. MESSAGE("Signal has " << _signals[p_name][i] << " expected " << p_args[i]);
  325. match = false;
  326. break;
  327. }
  328. }
  329. }
  330. discard_signal(p_name);
  331. return match;
  332. }
  333. bool check_false(const String &p_name) {
  334. bool has = _signals.has(p_name);
  335. if (has) {
  336. MESSAGE("Signal has " << _signals[p_name] << " expected none.");
  337. }
  338. discard_signal(p_name);
  339. return !has;
  340. }
  341. void discard_signal(const String &p_name) {
  342. if (_signals.has(p_name)) {
  343. _signals.erase(p_name);
  344. }
  345. }
  346. void _clear_signals() {
  347. _signals.clear();
  348. }
  349. SignalWatcher() {
  350. singleton = this;
  351. }
  352. ~SignalWatcher() {
  353. singleton = nullptr;
  354. }
  355. };
  356. #define SIGNAL_WATCH(m_object, m_signal) SignalWatcher::get_singleton()->watch_signal(m_object, m_signal);
  357. #define SIGNAL_UNWATCH(m_object, m_signal) SignalWatcher::get_singleton()->unwatch_signal(m_object, m_signal);
  358. #define SIGNAL_CHECK(m_signal, m_args) CHECK(SignalWatcher::get_singleton()->check(m_signal, m_args));
  359. #define SIGNAL_CHECK_FALSE(m_signal) CHECK(SignalWatcher::get_singleton()->check_false(m_signal));
  360. #define SIGNAL_DISCARD(m_signal) SignalWatcher::get_singleton()->discard_signal(m_signal);
  361. #define MULTICHECK_STRING_EQ(m_obj, m_func, m_param1, m_eq) \
  362. CHECK(m_obj.m_func(m_param1) == m_eq); \
  363. CHECK(m_obj.m_func(U##m_param1) == m_eq); \
  364. CHECK(m_obj.m_func(L##m_param1) == m_eq); \
  365. CHECK(m_obj.m_func(String(m_param1)) == m_eq);
  366. #define MULTICHECK_STRING_INT_EQ(m_obj, m_func, m_param1, m_param2, m_eq) \
  367. CHECK(m_obj.m_func(m_param1, m_param2) == m_eq); \
  368. CHECK(m_obj.m_func(U##m_param1, m_param2) == m_eq); \
  369. CHECK(m_obj.m_func(L##m_param1, m_param2) == m_eq); \
  370. CHECK(m_obj.m_func(String(m_param1), m_param2) == m_eq);
  371. #define MULTICHECK_STRING_INT_INT_EQ(m_obj, m_func, m_param1, m_param2, m_param3, m_eq) \
  372. CHECK(m_obj.m_func(m_param1, m_param2, m_param3) == m_eq); \
  373. CHECK(m_obj.m_func(U##m_param1, m_param2, m_param3) == m_eq); \
  374. CHECK(m_obj.m_func(L##m_param1, m_param2, m_param3) == m_eq); \
  375. CHECK(m_obj.m_func(String(m_param1), m_param2, m_param3) == m_eq);
  376. #define MULTICHECK_STRING_STRING_EQ(m_obj, m_func, m_param1, m_param2, m_eq) \
  377. CHECK(m_obj.m_func(m_param1, m_param2) == m_eq); \
  378. CHECK(m_obj.m_func(U##m_param1, U##m_param2) == m_eq); \
  379. CHECK(m_obj.m_func(L##m_param1, L##m_param2) == m_eq); \
  380. CHECK(m_obj.m_func(String(m_param1), String(m_param2)) == m_eq);
  381. #define MULTICHECK_GET_SLICE(m_obj, m_param1, m_slices) \
  382. for (int i = 0; i < m_obj.get_slice_count(m_param1); ++i) { \
  383. CHECK(m_obj.get_slice(m_param1, i) == m_slices[i]); \
  384. } \
  385. for (int i = 0; i < m_obj.get_slice_count(U##m_param1); ++i) { \
  386. CHECK(m_obj.get_slice(U##m_param1, i) == m_slices[i]); \
  387. } \
  388. for (int i = 0; i < m_obj.get_slice_count(L##m_param1); ++i) { \
  389. CHECK(m_obj.get_slice(L##m_param1, i) == m_slices[i]); \
  390. } \
  391. for (int i = 0; i < m_obj.get_slice_count(String(m_param1)); ++i) { \
  392. CHECK(m_obj.get_slice(String(m_param1), i) == m_slices[i]); \
  393. }
  394. #define MULTICHECK_SPLIT(m_obj, m_func, m_param1, m_param2, m_param3, m_slices, m_expected_size) \
  395. do { \
  396. Vector<String> string_list; \
  397. \
  398. string_list = m_obj.m_func(m_param1, m_param2, m_param3); \
  399. CHECK(m_expected_size == string_list.size()); \
  400. for (int i = 0; i < string_list.size(); ++i) { \
  401. CHECK(string_list[i] == m_slices[i]); \
  402. } \
  403. \
  404. string_list = m_obj.m_func(U##m_param1, m_param2, m_param3); \
  405. CHECK(m_expected_size == string_list.size()); \
  406. for (int i = 0; i < string_list.size(); ++i) { \
  407. CHECK(string_list[i] == m_slices[i]); \
  408. } \
  409. \
  410. string_list = m_obj.m_func(L##m_param1, m_param2, m_param3); \
  411. CHECK(m_expected_size == string_list.size()); \
  412. for (int i = 0; i < string_list.size(); ++i) { \
  413. CHECK(string_list[i] == m_slices[i]); \
  414. } \
  415. \
  416. string_list = m_obj.m_func(String(m_param1), m_param2, m_param3); \
  417. CHECK(m_expected_size == string_list.size()); \
  418. for (int i = 0; i < string_list.size(); ++i) { \
  419. CHECK(string_list[i] == m_slices[i]); \
  420. } \
  421. } while (false)
  422. #endif // TEST_MACROS_H