TestsInterface.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. Rml::CompiledGeometryHandle TestsRenderInterface::CompileGeometry(Rml::Span<const Rml::Vertex> /*vertices*/, Rml::Span<const int> /*indices*/)
  83. {
  84. counters.compile_geometry += 1;
  85. return Rml::CompiledGeometryHandle(counters.compile_geometry);
  86. }
  87. void TestsRenderInterface::RenderGeometry(Rml::CompiledGeometryHandle /*geometry*/, Rml::Vector2f /*translation*/, Rml::TextureHandle /*texture*/)
  88. {
  89. counters.render_geometry += 1;
  90. }
  91. void TestsRenderInterface::ReleaseGeometry(Rml::CompiledGeometryHandle /*geometry*/)
  92. {
  93. counters.release_geometry += 1;
  94. }
  95. void TestsRenderInterface::EnableScissorRegion(bool /*enable*/)
  96. {
  97. counters.enable_scissor += 1;
  98. }
  99. void TestsRenderInterface::SetScissorRegion(Rml::Rectanglei /*region*/)
  100. {
  101. counters.set_scissor += 1;
  102. }
  103. void TestsRenderInterface::EnableClipMask(bool /*enable*/)
  104. {
  105. counters.enable_clip_mask += 1;
  106. }
  107. void TestsRenderInterface::RenderToClipMask(Rml::ClipMaskOperation /*mask_operation*/, Rml::CompiledGeometryHandle /*geometry*/,
  108. Rml::Vector2f /*translation*/)
  109. {
  110. counters.render_to_clip_mask += 1;
  111. }
  112. Rml::TextureHandle TestsRenderInterface::LoadTexture(Rml::Vector2i& texture_dimensions, const Rml::String& /*source*/)
  113. {
  114. counters.load_texture += 1;
  115. texture_dimensions.x = 512;
  116. texture_dimensions.y = 256;
  117. return 1;
  118. }
  119. Rml::TextureHandle TestsRenderInterface::GenerateTexture(Rml::Span<const Rml::byte> /*source*/, Rml::Vector2i /*source_dimensions*/)
  120. {
  121. counters.generate_texture += 1;
  122. return 1;
  123. }
  124. void TestsRenderInterface::ReleaseTexture(Rml::TextureHandle /*texture_handle*/)
  125. {
  126. counters.release_texture += 1;
  127. }
  128. void TestsRenderInterface::SetTransform(const Rml::Matrix4f* /*transform*/)
  129. {
  130. counters.set_transform += 1;
  131. }
  132. Rml::CompiledFilterHandle TestsRenderInterface::CompileFilter(const Rml::String& /*name*/, const Rml::Dictionary& /*parameters*/)
  133. {
  134. counters.compile_filter += 1;
  135. return 1;
  136. }
  137. void TestsRenderInterface::ReleaseFilter(Rml::CompiledFilterHandle /*filter*/)
  138. {
  139. counters.release_filter += 1;
  140. }
  141. Rml::CompiledShaderHandle TestsRenderInterface::CompileShader(const Rml::String& /*name*/, const Rml::Dictionary& /*parameters*/)
  142. {
  143. counters.compile_shader += 1;
  144. return 1;
  145. }
  146. void TestsRenderInterface::RenderShader(Rml::CompiledShaderHandle /*shader*/, Rml::CompiledGeometryHandle /*geometry*/, Rml::Vector2f /*translation*/,
  147. Rml::TextureHandle /*texture*/)
  148. {
  149. counters.render_shader += 1;
  150. }
  151. void TestsRenderInterface::ReleaseShader(Rml::CompiledShaderHandle /*shader*/)
  152. {
  153. counters.release_shader += 1;
  154. }
  155. void TestsRenderInterface::ResetCounters()
  156. {
  157. counters_from_previous_reset = std::exchange(counters, Counters());
  158. }
  159. void TestsRenderInterface::Reset()
  160. {
  161. ResetCounters();
  162. }