2
0

Template.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "../Common/TestsShell.h"
  29. #include <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Element.h>
  31. #include <RmlUi/Core/ElementDocument.h>
  32. #include <doctest.h>
  33. #include <algorithm>
  34. using namespace Rml;
  35. static const String document_template_rml = R"(
  36. <rml>
  37. <head>
  38. <link type="text/rcss" href="/assets/rml.rcss"/>
  39. <link type="text/template" href="/assets/window.rml"/>
  40. <style>
  41. body.window
  42. {
  43. top: 100px;
  44. left: 200px;
  45. width: 1300px;
  46. height: 450px;
  47. }
  48. </style>
  49. </head>
  50. <body id="body" template="window">
  51. <p id="p">A paragraph</p>
  52. </body>
  53. </rml>
  54. )";
  55. static const String p_address_template = "p#p < div#content < div#window < body#body.window < #root#main";
  56. static const String document_include_rml = R"(
  57. <rml>
  58. <head>
  59. <link type="text/rcss" href="/assets/rml.rcss"/>
  60. <link type="text/template" href="/assets/window.rml"/>
  61. <style>
  62. body.window
  63. {
  64. top: 100px;
  65. left: 200px;
  66. width: 1300px;
  67. height: 450px;
  68. }
  69. </style>
  70. </head>
  71. <body id="body">
  72. <p>Paragraph outside the window.</p>
  73. <div id="include">
  74. <include template="window">
  75. <p id="p">A paragraph</p>
  76. </include>
  77. </div>
  78. </body>
  79. </rml>
  80. )";
  81. static const String p_address_include = "p#p < div#content < div#window < div#include < body#body < #root#main";
  82. TEST_CASE("template.body")
  83. {
  84. Context* context = TestsShell::GetContext();
  85. REQUIRE(context);
  86. SUBCASE("body")
  87. {
  88. ElementDocument* document = context->LoadDocumentFromMemory(document_template_rml);
  89. REQUIRE(document);
  90. document->Show();
  91. context->Update();
  92. context->Render();
  93. TestsShell::RenderLoop();
  94. Element* el_p = document->GetElementById("p");
  95. REQUIRE(el_p);
  96. CHECK(el_p->GetAddress() == p_address_template);
  97. document->Close();
  98. }
  99. SUBCASE("include")
  100. {
  101. ElementDocument* document = context->LoadDocumentFromMemory(document_include_rml);
  102. REQUIRE(document);
  103. document->Show();
  104. context->Update();
  105. context->Render();
  106. TestsShell::RenderLoop();
  107. Element* el_p = document->GetElementById("p");
  108. REQUIRE(el_p);
  109. CHECK(el_p->GetAddress() == p_address_include);
  110. document->Close();
  111. }
  112. TestsShell::ShutdownShell();
  113. }