TestsInterface.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 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 0.0;
  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 TestsRenderInterface::RenderGeometry(Rml::Vertex* /*vertices*/, int /*num_vertices*/, int* /*indices*/, int /*num_indices*/, const Rml::TextureHandle /*texture*/, const Rml::Vector2f& /*translation*/)
  73. {
  74. counters.render_calls += 1;
  75. }
  76. void TestsRenderInterface::EnableScissorRegion(bool /*enable*/)
  77. {
  78. counters.enable_scissor += 1;
  79. }
  80. void TestsRenderInterface::SetScissorRegion(int /*x*/, int /*y*/, int /*width*/, int /*height*/)
  81. {
  82. counters.set_scissor += 1;
  83. }
  84. bool TestsRenderInterface::LoadTexture(Rml::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions, const Rml::String& /*source*/)
  85. {
  86. counters.load_texture += 1;
  87. texture_handle = 1;
  88. texture_dimensions.x = 512;
  89. texture_dimensions.y = 256;
  90. return true;
  91. }
  92. bool TestsRenderInterface::GenerateTexture(Rml::TextureHandle& texture_handle, const Rml::byte* /*source*/, const Rml::Vector2i& /*source_dimensions*/)
  93. {
  94. counters.generate_texture += 1;
  95. texture_handle = 1;
  96. return true;
  97. }
  98. void TestsRenderInterface::ReleaseTexture(Rml::TextureHandle /*texture_handle*/)
  99. {
  100. counters.release_texture += 1;
  101. }
  102. void TestsRenderInterface::SetTransform(const Rml::Matrix4f* /*transform*/)
  103. {
  104. counters.set_transform += 1;
  105. }