TestsInterface.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "TestsInterface.h"
  29. #include <RmlUi/Core/Log.h>
  30. #include <RmlUi/Core/StringUtilities.h>
  31. #include <doctest.h>
  32. TestsSystemInterface::~TestsSystemInterface()
  33. {
  34. SetNumExpectedWarnings(0);
  35. }
  36. double TestsSystemInterface::GetElapsedTime()
  37. {
  38. return elapsed_time;
  39. }
  40. bool TestsSystemInterface::LogMessage(Rml::Log::Type type, const Rml::String& message)
  41. {
  42. static const char* message_type_str[Rml::Log::Type::LT_MAX] = {"Always", "Error", "Assert", "Warning", "Info", "Debug"};
  43. const bool result = Rml::SystemInterface::LogMessage(type, message);
  44. if (type <= Rml::Log::Type::LT_WARNING)
  45. {
  46. const Rml::String warning = "RmlUi " + Rml::String(message_type_str[type]) + ": " + message;
  47. if (num_expected_warnings > 0)
  48. {
  49. num_logged_warnings += 1;
  50. warnings.push_back(warning);
  51. }
  52. else
  53. {
  54. FAIL_CHECK(warning);
  55. }
  56. }
  57. return result;
  58. }
  59. void TestsSystemInterface::SetNumExpectedWarnings(int in_num_expected_warnings)
  60. {
  61. if (num_expected_warnings > 0)
  62. {
  63. // Check and clear previous warnings
  64. if (num_logged_warnings != num_expected_warnings)
  65. {
  66. Rml::String str = "Got unexpected number of warnings: \n";
  67. Rml::StringUtilities::JoinString(str, warnings, '\n');
  68. if (warnings.empty())
  69. str += "(no warnings logged)";
  70. CHECK_MESSAGE(num_logged_warnings == num_expected_warnings, str);
  71. }
  72. num_expected_warnings = 0;
  73. num_logged_warnings = 0;
  74. warnings.clear();
  75. }
  76. num_expected_warnings = in_num_expected_warnings;
  77. }
  78. void TestsSystemInterface::SetTime(double t)
  79. {
  80. elapsed_time = t;
  81. }
  82. void TestsRenderInterface::RenderGeometry(Rml::Vertex* /*vertices*/, int /*num_vertices*/, int* /*indices*/, int /*num_indices*/,
  83. const Rml::TextureHandle /*texture*/, const Rml::Vector2f& /*translation*/)
  84. {
  85. counters.render_calls += 1;
  86. }
  87. void TestsRenderInterface::EnableScissorRegion(bool /*enable*/)
  88. {
  89. counters.enable_scissor += 1;
  90. }
  91. void TestsRenderInterface::SetScissorRegion(int /*x*/, int /*y*/, int /*width*/, int /*height*/)
  92. {
  93. counters.set_scissor += 1;
  94. }
  95. bool TestsRenderInterface::LoadTexture(Rml::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions, const Rml::String& /*source*/)
  96. {
  97. counters.load_texture += 1;
  98. texture_handle = 1;
  99. texture_dimensions.x = 512;
  100. texture_dimensions.y = 256;
  101. return true;
  102. }
  103. bool TestsRenderInterface::GenerateTexture(Rml::TextureHandle& texture_handle, const Rml::byte* /*source*/,
  104. const Rml::Vector2i& /*source_dimensions*/)
  105. {
  106. counters.generate_texture += 1;
  107. texture_handle = 1;
  108. return true;
  109. }
  110. void TestsRenderInterface::ReleaseTexture(Rml::TextureHandle /*texture_handle*/)
  111. {
  112. counters.release_texture += 1;
  113. }
  114. void TestsRenderInterface::SetTransform(const Rml::Matrix4f* /*transform*/)
  115. {
  116. counters.set_transform += 1;
  117. }