Core.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/Core.h>
  30. #include <RmlUi/Core/Context.h>
  31. #include <RmlUi/Core/Element.h>
  32. #include <RmlUi/Core/ElementDocument.h>
  33. #include <doctest.h>
  34. #include <algorithm>
  35. using namespace Rml;
  36. static const String document_textures_rml = R"(
  37. <rml>
  38. <head>
  39. <title>Test</title>
  40. <link type="text/rcss" href="/assets/rml.rcss"/>
  41. <style>
  42. body {
  43. left: 0;
  44. top: 0;
  45. right: 0;
  46. bottom: 0;
  47. }
  48. div.file {
  49. height: 100px;
  50. decorator: image(/assets/high_scores_alien_2.tga);
  51. }
  52. @spritesheet aliens {
  53. src: /assets/high_scores_alien_3.tga;
  54. alien3: 0px 0px 64px 64px;
  55. }
  56. div.sprite {
  57. height: 100px;
  58. decorator: image(alien3);
  59. }
  60. progress {
  61. display: block;
  62. width: 50px;
  63. height: 50px;
  64. background: #333;
  65. fill-image: /assets/high_scores_defender.tga;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <div style="display: block">
  71. <img src="/assets/high_scores_alien_1.tga"/>
  72. <div class="file"/>
  73. <div class="sprite"/>
  74. <progress direction="clockwise" start-edge="bottom" value="0.5"/>
  75. </div>
  76. </body>
  77. </rml>
  78. )";
  79. static inline StringList GetSortedTextureSourceList()
  80. {
  81. StringList list = Rml::GetTextureSourceList();
  82. std::sort(list.begin(), list.end());
  83. return list;
  84. }
  85. TEST_CASE("core.texture_source_list")
  86. {
  87. Context* context = TestsShell::GetContext();
  88. REQUIRE(context);
  89. REQUIRE(GetSortedTextureSourceList().size() == 0);
  90. // We should be able to detect all sources even though they are hidden.
  91. const StringList list_expected = {
  92. "assets/high_scores_alien_1.tga",
  93. "assets/high_scores_alien_2.tga",
  94. "assets/high_scores_alien_3.tga",
  95. "assets/high_scores_defender.tga",
  96. };
  97. ElementDocument* document = context->LoadDocumentFromMemory(document_textures_rml);
  98. REQUIRE(document);
  99. CHECK(GetSortedTextureSourceList() == list_expected);
  100. document->Show();
  101. CHECK(GetSortedTextureSourceList() == list_expected);
  102. context->Update();
  103. CHECK(GetSortedTextureSourceList() == list_expected);
  104. context->Render();
  105. CHECK(GetSortedTextureSourceList() == list_expected);
  106. TestsShell::RenderLoop();
  107. document->Close();
  108. TestsShell::ShutdownShell();
  109. }