PropertySpecification.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/Core.h>
  30. #include <RmlUi/Core/PropertyDefinition.h>
  31. #include <RmlUi/Core/PropertyDictionary.h>
  32. #include <RmlUi/Core/PropertySpecification.h>
  33. #include <doctest.h>
  34. using namespace Rml;
  35. TEST_CASE("PropertySpecification")
  36. {
  37. TestsSystemInterface system_interface;
  38. TestsRenderInterface render_interface;
  39. SetRenderInterface(&render_interface);
  40. SetSystemInterface(&system_interface);
  41. Rml::Initialise();
  42. PropertySpecification specification(1, 0);
  43. const PropertyId id = specification.RegisterProperty("name", "", false, false).AddParser("string").GetId();
  44. // Parse value into the <string> property.
  45. auto Parse = [&](const String& test_value, const String& expected) {
  46. PropertyDictionary properties;
  47. const bool parse_success = specification.ParsePropertyDeclaration(properties, id, test_value);
  48. const auto num_properties = properties.GetProperties().size();
  49. CHECK(parse_success);
  50. CHECK(num_properties == 1);
  51. CHECK(properties.GetProperty(id));
  52. if (const Property* property = properties.GetProperty(id))
  53. {
  54. const String parsed_value = property->Get<String>();
  55. CHECK_MESSAGE(parsed_value == expected, "Test value: ", test_value);
  56. }
  57. };
  58. Parse("a", "a");
  59. Parse(" a ", "a");
  60. Parse("green", "green");
  61. Parse("image(ress:///.ress#/images/a.png)", "image(ress:///.ress#/images/a.png)");
  62. Parse(R"(image("ress:///.ress#/images/a.png"))", R"(image("ress:///.ress#/images/a.png"))");
  63. Parse(R"("ress:///.ress#/images/a.png")", R"(ress:///.ress#/images/a.png)");
  64. Parse(R"("escaped\"quotes")", R"(escaped"quotes)");
  65. Parse(R"("escaped\\backslash")", R"(escaped\backslash)");
  66. Parse(R"("bad_\escape")", R"(bad_\escape)");
  67. Parse(R"(C:\Windows\test.png)", R"(C:\Windows\test.png)");
  68. Parse(R"("C:\Windows\test.png")", R"(C:\Windows\test.png)");
  69. Parse(R"(C:\\Windows\\test.png)", R"(C:\\Windows\\test.png)");
  70. Parse(R"("C:\\Windows\\test.png")", R"(C:\Windows\test.png)");
  71. Parse(R"(\\host\test.png)", R"(\\host\test.png)");
  72. Parse(R"(\\\host\test.png)", R"(\\\host\test.png)");
  73. Parse(R"("\\host\\test.png")", R"(\host\test.png)");
  74. Parse("image(a)", "image(a)");
  75. Parse(R"(image(a))", R"(image(a))");
  76. Parse(R"(image(a, "b"))", R"(image(a, "b"))");
  77. Parse(R"V("image(a, \"b\")")V", R"V(image(a, "b"))V");
  78. Parse(R"(image( ))", R"(image( ))");
  79. Parse(R"(image( a\)b ))", R"(image( a)b ))");
  80. Parse(R"(image("a\)b"))", R"(image("a)b"))");
  81. Parse(R"(image( a\\b ))", R"(image( a\b ))");
  82. Parse(R"(image( a\\\b ))", R"(image( a\\b ))");
  83. Parse(R"(image( a\\\\b ))", R"(image( a\\b ))");
  84. Rml::Shutdown();
  85. }