test_main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_astar.h"
  34. #include "test_basis.h"
  35. #include "test_class_db.h"
  36. #include "test_color.h"
  37. #include "test_command_queue.h"
  38. #include "test_config_file.h"
  39. #include "test_crypto.h"
  40. #include "test_curve.h"
  41. #include "test_expression.h"
  42. #include "test_file_access.h"
  43. #include "test_geometry_2d.h"
  44. #include "test_gradient.h"
  45. #include "test_gui.h"
  46. #include "test_json.h"
  47. #include "test_list.h"
  48. #include "test_local_vector.h"
  49. #include "test_lru.h"
  50. #include "test_marshalls.h"
  51. #include "test_math.h"
  52. #include "test_method_bind.h"
  53. #include "test_node_path.h"
  54. #include "test_oa_hash_map.h"
  55. #include "test_object.h"
  56. #include "test_ordered_hash_map.h"
  57. #include "test_paged_array.h"
  58. #include "test_pck_packer.h"
  59. #include "test_physics_2d.h"
  60. #include "test_physics_3d.h"
  61. #include "test_random_number_generator.h"
  62. #include "test_rect2.h"
  63. #include "test_render.h"
  64. #include "test_shader_lang.h"
  65. #include "test_string.h"
  66. #include "test_text_server.h"
  67. #include "test_validate_testing.h"
  68. #include "test_variant.h"
  69. #include "modules/modules_tests.gen.h"
  70. #include "tests/test_macros.h"
  71. int test_main(int argc, char *argv[]) {
  72. bool run_tests = true;
  73. // Convert arguments to Godot's command-line.
  74. List<String> args;
  75. for (int i = 0; i < argc; i++) {
  76. args.push_back(String::utf8(argv[i]));
  77. }
  78. OS::get_singleton()->set_cmdline("", args);
  79. // Run custom test tools.
  80. if (test_commands) {
  81. for (Map<String, TestFunc>::Element *E = test_commands->front(); E; E = E->next()) {
  82. if (args.find(E->key())) {
  83. const TestFunc &test_func = E->get();
  84. test_func();
  85. run_tests = false;
  86. break;
  87. }
  88. }
  89. if (!run_tests) {
  90. delete test_commands;
  91. return 0;
  92. }
  93. }
  94. // Doctest runner.
  95. doctest::Context test_context;
  96. List<String> test_args;
  97. // Clean arguments of "--test" from the args.
  98. for (int x = 0; x < argc; x++) {
  99. String arg = String(argv[x]);
  100. if (arg != "--test") {
  101. test_args.push_back(arg);
  102. }
  103. }
  104. // Convert Godot command line arguments back to standard arguments.
  105. char **doctest_args = new char *[test_args.size()];
  106. for (int x = 0; x < test_args.size(); x++) {
  107. // Operation to convert Godot string to non wchar string.
  108. CharString cs = test_args[x].utf8();
  109. const char *str = cs.get_data();
  110. // Allocate the string copy.
  111. doctest_args[x] = new char[strlen(str) + 1];
  112. // Copy this into memory.
  113. memcpy(doctest_args[x], str, strlen(str) + 1);
  114. }
  115. test_context.applyCommandLine(test_args.size(), doctest_args);
  116. for (int x = 0; x < test_args.size(); x++) {
  117. delete[] doctest_args[x];
  118. }
  119. delete[] doctest_args;
  120. return test_context.run();
  121. }