test_main.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* test_main.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "test_main.h"
  31. #include "core/templates/list.h"
  32. #include "test_aabb.h"
  33. #include "test_array.h"
  34. #include "test_astar.h"
  35. #include "test_basis.h"
  36. #include "test_class_db.h"
  37. #include "test_color.h"
  38. #include "test_command_queue.h"
  39. #include "test_config_file.h"
  40. #include "test_crypto.h"
  41. #include "test_curve.h"
  42. #include "test_dictionary.h"
  43. #include "test_expression.h"
  44. #include "test_file_access.h"
  45. #include "test_geometry_2d.h"
  46. #include "test_geometry_3d.h"
  47. #include "test_gradient.h"
  48. #include "test_gui.h"
  49. #include "test_hashing_context.h"
  50. #include "test_image.h"
  51. #include "test_json.h"
  52. #include "test_list.h"
  53. #include "test_local_vector.h"
  54. #include "test_lru.h"
  55. #include "test_marshalls.h"
  56. #include "test_math.h"
  57. #include "test_method_bind.h"
  58. #include "test_node_path.h"
  59. #include "test_oa_hash_map.h"
  60. #include "test_object.h"
  61. #include "test_ordered_hash_map.h"
  62. #include "test_paged_array.h"
  63. #include "test_path_3d.h"
  64. #include "test_pck_packer.h"
  65. #include "test_physics_2d.h"
  66. #include "test_physics_3d.h"
  67. #include "test_random_number_generator.h"
  68. #include "test_rect2.h"
  69. #include "test_render.h"
  70. #include "test_resource.h"
  71. #include "test_shader_lang.h"
  72. #include "test_string.h"
  73. #include "test_text_server.h"
  74. #include "test_translation.h"
  75. #include "test_validate_testing.h"
  76. #include "test_variant.h"
  77. #include "test_vector.h"
  78. #include "test_xml_parser.h"
  79. #include "modules/modules_tests.gen.h"
  80. #include "tests/test_macros.h"
  81. int test_main(int argc, char *argv[]) {
  82. bool run_tests = true;
  83. // Convert arguments to Godot's command-line.
  84. List<String> args;
  85. for (int i = 0; i < argc; i++) {
  86. args.push_back(String::utf8(argv[i]));
  87. }
  88. OS::get_singleton()->set_cmdline("", args);
  89. // Run custom test tools.
  90. if (test_commands) {
  91. for (Map<String, TestFunc>::Element *E = test_commands->front(); E; E = E->next()) {
  92. if (args.find(E->key())) {
  93. const TestFunc &test_func = E->get();
  94. test_func();
  95. run_tests = false;
  96. break;
  97. }
  98. }
  99. if (!run_tests) {
  100. delete test_commands;
  101. return 0;
  102. }
  103. }
  104. // Doctest runner.
  105. doctest::Context test_context;
  106. List<String> test_args;
  107. // Clean arguments of "--test" from the args.
  108. for (int x = 0; x < argc; x++) {
  109. String arg = String(argv[x]);
  110. if (arg != "--test") {
  111. test_args.push_back(arg);
  112. }
  113. }
  114. if (test_args.size() > 0) {
  115. // Convert Godot command line arguments back to standard arguments.
  116. char **doctest_args = new char *[test_args.size()];
  117. for (int x = 0; x < test_args.size(); x++) {
  118. // Operation to convert Godot string to non wchar string.
  119. CharString cs = test_args[x].utf8();
  120. const char *str = cs.get_data();
  121. // Allocate the string copy.
  122. doctest_args[x] = new char[strlen(str) + 1];
  123. // Copy this into memory.
  124. memcpy(doctest_args[x], str, strlen(str) + 1);
  125. }
  126. test_context.applyCommandLine(test_args.size(), doctest_args);
  127. for (int x = 0; x < test_args.size(); x++) {
  128. delete[] doctest_args[x];
  129. }
  130. delete[] doctest_args;
  131. }
  132. return test_context.run();
  133. }