Properties.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/TestsInterface.h"
  29. #include <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Core.h>
  31. #include <RmlUi/Core/Element.h>
  32. #include <RmlUi/Core/ElementDocument.h>
  33. #include <doctest.h>
  34. using namespace Rml;
  35. TEST_CASE("Properties")
  36. {
  37. const Vector2i window_size(1024, 768);
  38. TestsSystemInterface system_interface;
  39. TestsRenderInterface render_interface;
  40. SetRenderInterface(&render_interface);
  41. SetSystemInterface(&system_interface);
  42. Rml::Initialise();
  43. Context* context = Rml::CreateContext("main", window_size);
  44. ElementDocument* document = context->CreateDocument();
  45. struct FlexTestCase {
  46. String flex_value;
  47. struct ExpectedValues {
  48. float flex_grow;
  49. float flex_shrink;
  50. String flex_basis;
  51. } expected;
  52. };
  53. FlexTestCase tests[] = {
  54. {"", {0.f, 1.f, "auto"}},
  55. {"none", {0.f, 0.f, "auto"}},
  56. {"auto", {1.f, 1.f, "auto"}},
  57. {"1", {1.f, 1.f, "0px"}},
  58. {"2", {2.f, 1.f, "0px"}},
  59. {"2 0", {2.f, 0.f, "0px"}},
  60. {"2 3", {2.f, 3.f, "0px"}},
  61. {"2 auto", {2.f, 1.f, "auto"}},
  62. {"2 0 auto", {2.f, 0.f, "auto"}},
  63. {"0 0 auto", {0.f, 0.f, "auto"}},
  64. {"0 0 50px", {0.f, 0.f, "50px"}},
  65. {"0 0 50px", {0.f, 0.f, "50px"}},
  66. {"0 0 0", {0.f, 0.f, "0px"}},
  67. };
  68. for (const FlexTestCase& test : tests)
  69. {
  70. if (!test.flex_value.empty())
  71. {
  72. CHECK(document->SetProperty("flex", test.flex_value));
  73. }
  74. CHECK(document->GetProperty<float>("flex-grow") == test.expected.flex_grow);
  75. CHECK(document->GetProperty<float>("flex-shrink") == test.expected.flex_shrink);
  76. CHECK(document->GetProperty("flex-basis")->ToString() == test.expected.flex_basis);
  77. }
  78. Rml::Shutdown();
  79. }