TestsInterface.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. double TestsSystemInterface::GetElapsedTime()
  33. {
  34. return elapsed_time;
  35. }
  36. bool TestsSystemInterface::LogMessage(Rml::Log::Type type, const Rml::String& message)
  37. {
  38. static const char* message_type_str[Rml::Log::Type::LT_MAX] = {"Always", "Error", "Assert", "Warning", "Info", "Debug"};
  39. const bool result = Rml::SystemInterface::LogMessage(type, message);
  40. if (type <= Rml::Log::Type::LT_WARNING)
  41. {
  42. const Rml::String warning = "RmlUi " + Rml::String(message_type_str[type]) + ": " + message;
  43. if (num_expected_warnings > 0)
  44. {
  45. num_logged_warnings += 1;
  46. warnings.push_back(warning);
  47. }
  48. else
  49. {
  50. FAIL_CHECK(warning);
  51. }
  52. }
  53. return result;
  54. }
  55. void TestsSystemInterface::SetNumExpectedWarnings(int in_num_expected_warnings)
  56. {
  57. if (num_expected_warnings > 0)
  58. {
  59. // Check and clear previous warnings
  60. if (num_logged_warnings != num_expected_warnings)
  61. {
  62. Rml::String str = "Got unexpected number of warnings: \n";
  63. Rml::StringUtilities::JoinString(str, warnings, '\n');
  64. CHECK_MESSAGE(num_logged_warnings == num_expected_warnings, str);
  65. }
  66. num_expected_warnings = 0;
  67. num_logged_warnings = 0;
  68. warnings.clear();
  69. }
  70. num_expected_warnings = in_num_expected_warnings;
  71. }
  72. void TestsSystemInterface::SetTime(double t)
  73. {
  74. elapsed_time = t;
  75. }
  76. Rml::CompiledGeometryHandle TestsRenderInterface::CompileGeometry(Rml::Span<const Rml::Vertex> /*vertices*/, Rml::Span<const int> /*indices*/)
  77. {
  78. counters.compile_geometry += 1;
  79. return Rml::CompiledGeometryHandle(counters.compile_geometry);
  80. }
  81. void TestsRenderInterface::RenderGeometry(Rml::CompiledGeometryHandle /*geometry*/, Rml::Vector2f /*translation*/, Rml::TextureHandle /*texture*/)
  82. {
  83. counters.render_geometry += 1;
  84. }
  85. void TestsRenderInterface::ReleaseGeometry(Rml::CompiledGeometryHandle /*geometry*/)
  86. {
  87. counters.release_geometry += 1;
  88. }
  89. void TestsRenderInterface::EnableScissorRegion(bool /*enable*/)
  90. {
  91. counters.enable_scissor += 1;
  92. }
  93. void TestsRenderInterface::SetScissorRegion(Rml::Rectanglei /*region*/)
  94. {
  95. counters.set_scissor += 1;
  96. }
  97. void TestsRenderInterface::EnableClipMask(bool /*enable*/)
  98. {
  99. counters.enable_clip_mask += 1;
  100. }
  101. void TestsRenderInterface::RenderToClipMask(Rml::ClipMaskOperation /*mask_operation*/, Rml::CompiledGeometryHandle /*geometry*/, Rml::Vector2f /*translation*/)
  102. {
  103. counters.render_to_clip_mask += 1;
  104. }
  105. Rml::TextureHandle TestsRenderInterface::LoadTexture(Rml::Vector2i& texture_dimensions, const Rml::String& /*source*/)
  106. {
  107. counters.load_texture += 1;
  108. texture_dimensions.x = 512;
  109. texture_dimensions.y = 256;
  110. return 1;
  111. }
  112. Rml::TextureHandle TestsRenderInterface::GenerateTexture(Rml::Span<const Rml::byte> /*source*/, Rml::Vector2i /*source_dimensions*/)
  113. {
  114. counters.generate_texture += 1;
  115. return 1;
  116. }
  117. void TestsRenderInterface::ReleaseTexture(Rml::TextureHandle /*texture_handle*/)
  118. {
  119. counters.release_texture += 1;
  120. }
  121. void TestsRenderInterface::SetTransform(const Rml::Matrix4f* /*transform*/)
  122. {
  123. counters.set_transform += 1;
  124. }