test_main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*************************************************************************/
  2. /* test_main.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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_gradient.h"
  43. #include "test_gui.h"
  44. #include "test_json.h"
  45. #include "test_list.h"
  46. #include "test_math.h"
  47. #include "test_method_bind.h"
  48. #include "test_node_path.h"
  49. #include "test_oa_hash_map.h"
  50. #include "test_object.h"
  51. #include "test_ordered_hash_map.h"
  52. #include "test_pck_packer.h"
  53. #include "test_physics_2d.h"
  54. #include "test_physics_3d.h"
  55. #include "test_rect2.h"
  56. #include "test_render.h"
  57. #include "test_shader_lang.h"
  58. #include "test_string.h"
  59. #include "test_validate_testing.h"
  60. #include "test_variant.h"
  61. #include "modules/modules_tests.gen.h"
  62. #include "tests/test_macros.h"
  63. int test_main(int argc, char *argv[]) {
  64. bool run_tests = true;
  65. // Convert arguments to Godot's command-line.
  66. List<String> args;
  67. for (int i = 0; i < argc; i++) {
  68. args.push_back(String::utf8(argv[i]));
  69. }
  70. OS::get_singleton()->set_cmdline("", args);
  71. // Run custom test tools.
  72. if (test_commands) {
  73. for (Map<String, TestFunc>::Element *E = test_commands->front(); E; E = E->next()) {
  74. if (args.find(E->key())) {
  75. const TestFunc &test_func = E->get();
  76. test_func();
  77. run_tests = false;
  78. break;
  79. }
  80. }
  81. if (!run_tests) {
  82. delete test_commands;
  83. return 0;
  84. }
  85. }
  86. // Doctest runner.
  87. doctest::Context test_context;
  88. List<String> test_args;
  89. // Clean arguments of "--test" from the args.
  90. for (int x = 0; x < argc; x++) {
  91. String arg = String(argv[x]);
  92. if (arg != "--test") {
  93. test_args.push_back(arg);
  94. }
  95. }
  96. // Convert Godot command line arguments back to standard arguments.
  97. char **doctest_args = new char *[test_args.size()];
  98. for (int x = 0; x < test_args.size(); x++) {
  99. // Operation to convert Godot string to non wchar string.
  100. CharString cs = test_args[x].utf8();
  101. const char *str = cs.get_data();
  102. // Allocate the string copy.
  103. doctest_args[x] = new char[strlen(str) + 1];
  104. // Copy this into memory.
  105. memcpy(doctest_args[x], str, strlen(str) + 1);
  106. }
  107. test_context.applyCommandLine(test_args.size(), doctest_args);
  108. for (int x = 0; x < test_args.size(); x++) {
  109. delete[] doctest_args[x];
  110. }
  111. delete[] doctest_args;
  112. return test_context.run();
  113. }