test_style_box_texture.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifndef TEST_STYLE_BOX_TEXTURE_H
  31. #define TEST_STYLE_BOX_TEXTURE_H
  32. #include "scene/resources/style_box_texture.h"
  33. #include "tests/test_macros.h"
  34. namespace TestStyleBoxTexture {
  35. TEST_CASE("[StyleBoxTexture] Constructor") {
  36. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  37. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  38. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  39. CHECK(style_box_texture->is_draw_center_enabled() == true);
  40. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 0);
  41. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 0);
  42. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 0);
  43. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 0);
  44. CHECK(style_box_texture->get_modulate() == Color(1, 1, 1, 1));
  45. CHECK(style_box_texture->get_region_rect() == Rect2(0, 0, 0, 0));
  46. CHECK(style_box_texture->get_texture() == Ref<Texture2D>());
  47. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 0);
  48. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 0);
  49. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 0);
  50. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 0);
  51. }
  52. TEST_CASE("[StyleBoxTexture] set_texture, get_texture") {
  53. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  54. Ref<Texture2D> texture = memnew(Texture2D);
  55. style_box_texture->set_texture(texture);
  56. CHECK(style_box_texture->get_texture() == texture);
  57. }
  58. TEST_CASE("[StyleBoxTexture] set_texture_margin, set_texture_margin_all, set_texture_margin_individual, get_texture_margin") {
  59. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  60. SUBCASE("set_texture_margin, get_texture_margin") {
  61. style_box_texture->set_texture_margin(SIDE_LEFT, 1);
  62. style_box_texture->set_texture_margin(SIDE_TOP, 1);
  63. style_box_texture->set_texture_margin(SIDE_RIGHT, 1);
  64. style_box_texture->set_texture_margin(SIDE_BOTTOM, 1);
  65. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 1);
  66. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 1);
  67. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 1);
  68. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 1);
  69. }
  70. SUBCASE("set_texture_margin_all") {
  71. style_box_texture->set_texture_margin_all(2);
  72. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 2);
  73. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 2);
  74. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 2);
  75. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 2);
  76. }
  77. SUBCASE("set_texture_margin_individual") {
  78. style_box_texture->set_texture_margin_individual(3, 4, 5, 6);
  79. CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 3);
  80. CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 4);
  81. CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 5);
  82. CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 6);
  83. }
  84. }
  85. TEST_CASE("[StyleBoxTexture] set_expand_margin, set_expand_margin_all, set_expand_margin_individual") {
  86. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  87. SUBCASE("set_expand_margin, get_expand_margin") {
  88. style_box_texture->set_expand_margin(SIDE_LEFT, 1);
  89. style_box_texture->set_expand_margin(SIDE_TOP, 1);
  90. style_box_texture->set_expand_margin(SIDE_RIGHT, 1);
  91. style_box_texture->set_expand_margin(SIDE_BOTTOM, 1);
  92. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 1);
  93. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 1);
  94. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 1);
  95. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 1);
  96. }
  97. SUBCASE("set_expand_margin_all") {
  98. style_box_texture->set_expand_margin_all(2);
  99. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 2);
  100. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 2);
  101. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 2);
  102. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 2);
  103. }
  104. SUBCASE("set_expand_margin_individual") {
  105. style_box_texture->set_expand_margin_individual(3, 4, 5, 6);
  106. CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 3);
  107. CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 4);
  108. CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 5);
  109. CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 6);
  110. }
  111. }
  112. TEST_CASE("[StyleBoxTexture] set_region_rect, get_region_rect") {
  113. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  114. style_box_texture->set_region_rect(Rect2(1, 1, 1, 1));
  115. CHECK(style_box_texture->get_region_rect() == Rect2(1, 1, 1, 1));
  116. }
  117. TEST_CASE("[StyleBoxTexture] set_draw_center, get_draw_center") {
  118. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  119. style_box_texture->set_draw_center(false);
  120. CHECK(style_box_texture->is_draw_center_enabled() == false);
  121. }
  122. TEST_CASE("[StyleBoxTexture] set_h_axis_stretch_mode, set_v_axis_stretch_mode, get_h_axis_stretch_mode, get_v_axis_stretch_mode") {
  123. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  124. SUBCASE("set_h_axis_stretch_mode, get_h_axis_stretch_mode") {
  125. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);
  126. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);
  127. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  128. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  129. style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  130. CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  131. }
  132. SUBCASE("set_v_axis_stretch_mode, get_v_axis_stretch_mode") {
  133. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);
  134. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);
  135. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  136. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);
  137. style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  138. CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);
  139. }
  140. }
  141. TEST_CASE("[StyleBoxTexture] set_modulate, get_modulate") {
  142. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  143. style_box_texture->set_modulate(Color(0, 0, 0, 0));
  144. CHECK(style_box_texture->get_modulate() == Color(0, 0, 0, 0));
  145. }
  146. TEST_CASE("[StyleBoxTexture] get_draw_rect") {
  147. Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);
  148. style_box_texture->set_expand_margin_all(5);
  149. CHECK(style_box_texture->get_draw_rect(Rect2(0, 0, 1, 1)) == Rect2(-5, -5, 11, 11));
  150. }
  151. } // namespace TestStyleBoxTexture
  152. #endif // TEST_STYLE_BOX_TEXTURE_H