Debugger.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 "../../../Source/Debugger/ElementInfo.h"
  29. #include "../Common/TestsShell.h"
  30. #include <RmlUi/Core/Context.h>
  31. #include <RmlUi/Core/Core.h>
  32. #include <RmlUi/Core/ElementDocument.h>
  33. #include <RmlUi/Debugger.h>
  34. #include <algorithm>
  35. #include <doctest.h>
  36. using namespace Rml;
  37. static void SimulateClick(Context* context, Vector2i position)
  38. {
  39. context->Update();
  40. context->ProcessMouseMove(position.x, position.y, 0);
  41. context->Update();
  42. context->ProcessMouseButtonDown(0, 0);
  43. context->Update();
  44. context->ProcessMouseButtonUp(0, 0);
  45. context->Update();
  46. }
  47. TEST_CASE("debugger")
  48. {
  49. Context* context = TestsShell::GetContext(false);
  50. SUBCASE("no_shutdown")
  51. {
  52. Rml::Debugger::Initialise(context);
  53. ElementDocument* document = context->LoadDocument("assets/demo.rml");
  54. TestsShell::RenderLoop();
  55. document->Close();
  56. TestsShell::RenderLoop();
  57. }
  58. SUBCASE("shutdown")
  59. {
  60. Rml::Debugger::Initialise(context);
  61. ElementDocument* document = context->LoadDocument("assets/demo.rml");
  62. TestsShell::RenderLoop();
  63. document->Close();
  64. TestsShell::RenderLoop();
  65. Rml::Debugger::Shutdown();
  66. TestsShell::RenderLoop();
  67. }
  68. SUBCASE("shutdown_early")
  69. {
  70. ElementDocument* document = context->LoadDocument("assets/demo.rml");
  71. TestsShell::RenderLoop();
  72. Rml::Debugger::Initialise(context);
  73. TestsShell::RenderLoop();
  74. Rml::Debugger::Shutdown();
  75. TestsShell::RenderLoop();
  76. document->Close();
  77. TestsShell::RenderLoop();
  78. }
  79. TestsShell::ShutdownShell();
  80. }
  81. TEST_CASE("debugger.unload_documents")
  82. {
  83. Context* context = TestsShell::GetContext(false);
  84. Rml::Debugger::Initialise(context);
  85. context->LoadDocument("assets/demo.rml");
  86. TestsShell::RenderLoop();
  87. // Closing documents from the debugger plugin is not allowed.
  88. TestsShell::SetNumExpectedWarnings(1);
  89. SUBCASE("UnloadDocument")
  90. {
  91. context->GetDocument("rmlui-debug-menu")->Close();
  92. }
  93. SUBCASE("UnloadAllDocuments")
  94. {
  95. context->UnloadAllDocuments();
  96. }
  97. context->Update();
  98. TestsShell::ShutdownShell();
  99. }
  100. TEST_CASE("debugger.focus")
  101. {
  102. Context* context = TestsShell::GetContext(false);
  103. Rml::Debugger::Initialise(context);
  104. ElementDocument* document = context->LoadDocument("assets/demo.rml");
  105. SUBCASE("Normal")
  106. {
  107. document->Show();
  108. }
  109. SUBCASE("Modal")
  110. {
  111. document->Show(ModalFlag::Modal);
  112. }
  113. Rml::Debugger::SetVisible(true);
  114. SimulateClick(context, {200, 20});
  115. TestsShell::RenderLoop();
  116. Element* info_element = context->GetRootElement()->GetElementById("rmlui-debug-info");
  117. CHECK(info_element->IsVisible());
  118. auto info_document = rmlui_dynamic_cast<Rml::Debugger::ElementInfo*>(info_element);
  119. REQUIRE(info_document);
  120. SimulateClick(context, context->GetDimensions() / 2);
  121. Element* source_element = info_document->GetSourceElement();
  122. REQUIRE(source_element);
  123. CHECK(source_element->GetId() == "content");
  124. document->Close();
  125. TestsShell::ShutdownShell();
  126. }