test_style_box_texture.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**************************************************************************/
  2. /* test_style_box_texture.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/resources/style_box_texture.h"
  32. #include "tests/test_macros.h"
  33. namespace TestStyleBoxTexture {
  34. TEST_CASE("[StyleBoxTexture] Constructor") {
  35. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  36. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  37. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  38. CHECK(style_box_texture->is_draw_center_enabled() == true);
  39. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 0);
  40. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 0);
  41. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 0);
  42. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 0);
  43. CHECK(style_box_texture->get_modulate() == Color(1, 1, 1, 1));
  44. CHECK(style_box_texture->get_region_rect() == Rect2(0, 0, 0, 0));
  45. CHECK(style_box_texture->get_texture() == Ref<Texture2D>());
  46. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 0);
  47. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 0);
  48. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 0);
  49. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 0);
  50. }
  51. TEST_CASE("[StyleBoxTexture] set_texture, get_texture") {
  52. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  53. Ref<Texture2D> texture = memnew(Texture2D);
  54. style_box_texture->set_texture(texture);
  55. CHECK(style_box_texture->get_texture() == texture);
  56. }
  57. TEST_CASE("[StyleBoxTexture] set_texture_margin, set_texture_margin_all, set_texture_margin_individual, get_texture_margin") {
  58. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  59. SUBCASE("set_texture_margin, get_texture_margin") {
  60. style_box_texture->set_texture_margin(SIDE_LEFT, 1);
  61. style_box_texture->set_texture_margin(SIDE_TOP, 1);
  62. style_box_texture->set_texture_margin(SIDE_RIGHT, 1);
  63. style_box_texture->set_texture_margin(SIDE_BOTTOM, 1);
  64. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 1);
  65. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 1);
  66. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 1);
  67. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 1);
  68. }
  69. SUBCASE("set_texture_margin_all") {
  70. style_box_texture->set_texture_margin_all(2);
  71. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 2);
  72. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 2);
  73. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 2);
  74. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 2);
  75. }
  76. SUBCASE("set_texture_margin_individual") {
  77. style_box_texture->set_texture_margin_individual(3, 4, 5, 6);
  78. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 3);
  79. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 4);
  80. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 5);
  81. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 6);
  82. }
  83. }
  84. TEST_CASE("[StyleBoxTexture] set_expand_margin, set_expand_margin_all, set_expand_margin_individual") {
  85. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  86. SUBCASE("set_expand_margin, get_expand_margin") {
  87. style_box_texture->set_expand_margin(SIDE_LEFT, 1);
  88. style_box_texture->set_expand_margin(SIDE_TOP, 1);
  89. style_box_texture->set_expand_margin(SIDE_RIGHT, 1);
  90. style_box_texture->set_expand_margin(SIDE_BOTTOM, 1);
  91. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 1);
  92. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 1);
  93. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 1);
  94. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 1);
  95. }
  96. SUBCASE("set_expand_margin_all") {
  97. style_box_texture->set_expand_margin_all(2);
  98. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 2);
  99. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 2);
  100. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 2);
  101. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 2);
  102. }
  103. SUBCASE("set_expand_margin_individual") {
  104. style_box_texture->set_expand_margin_individual(3, 4, 5, 6);
  105. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 3);
  106. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 4);
  107. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 5);
  108. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 6);
  109. }
  110. }
  111. TEST_CASE("[StyleBoxTexture] set_region_rect, get_region_rect") {
  112. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  113. style_box_texture->set_region_rect(Rect2(1, 1, 1, 1));
  114. CHECK(style_box_texture->get_region_rect() == Rect2(1, 1, 1, 1));
  115. }
  116. TEST_CASE("[StyleBoxTexture] set_draw_center, get_draw_center") {
  117. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  118. style_box_texture->set_draw_center(false);
  119. CHECK(style_box_texture->is_draw_center_enabled() == false);
  120. }
  121. TEST_CASE("[StyleBoxTexture] set_h_axis_stretch_mode, set_v_axis_stretch_mode, get_h_axis_stretch_mode, get_v_axis_stretch_mode") {
  122. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  123. SUBCASE("set_h_axis_stretch_mode, get_h_axis_stretch_mode") {
  124. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);
  125. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);
  126. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  127. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  128. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  129. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  130. }
  131. SUBCASE("set_v_axis_stretch_mode, get_v_axis_stretch_mode") {
  132. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);
  133. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);
  134. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  135. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  136. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  137. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  138. }
  139. }
  140. TEST_CASE("[StyleBoxTexture] set_modulate, get_modulate") {
  141. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  142. style_box_texture->set_modulate(Color(0, 0, 0, 0));
  143. CHECK(style_box_texture->get_modulate() == Color(0, 0, 0, 0));
  144. }
  145. TEST_CASE("[StyleBoxTexture] get_draw_rect") {
  146. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  147. style_box_texture->set_expand_margin_all(5);
  148. CHECK(style_box_texture->get_draw_rect(Rect2(0, 0, 1, 1)) == Rect2(-5, -5, 11, 11));
  149. }
  150. } // namespace TestStyleBoxTexture