| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/style_box_texture.h" |
| 34 |
|
| 35 |
#include "tests/test_macros.h" |
| 36 |
|
| 37 |
namespace TestStyleBoxTexture { |
| 38 |
|
| 39 |
TEST_CASE("[StyleBoxTexture] Constructor") { |
| 40 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 41 |
|
| 42 |
CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 43 |
CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 44 |
CHECK(style_box_texture->is_draw_center_enabled() == true); |
| 45 |
|
| 46 |
CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 0); |
| 47 |
CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 0); |
| 48 |
CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 0); |
| 49 |
CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 0); |
| 50 |
|
| 51 |
CHECK(style_box_texture->get_modulate() == Color(1, 1, 1, 1)); |
| 52 |
CHECK(style_box_texture->get_region_rect() == Rect2(0, 0, 0, 0)); |
| 53 |
CHECK(style_box_texture->get_texture() == Ref<Texture2D>()); |
| 54 |
|
| 55 |
CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 0); |
| 56 |
CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 0); |
| 57 |
CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 0); |
| 58 |
CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 0); |
| 59 |
} |
| 60 |
|
| 61 |
TEST_CASE("[StyleBoxTexture] set_texture, get_texture") { |
| 62 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 63 |
Ref<Texture2D> texture = memnew(Texture2D); |
| 64 |
|
| 65 |
style_box_texture->set_texture(texture); |
| 66 |
CHECK(style_box_texture->get_texture() == texture); |
| 67 |
} |
| 68 |
|
| 69 |
TEST_CASE("[StyleBoxTexture] set_texture_margin, set_texture_margin_all, set_texture_margin_individual, get_texture_margin") { |
| 70 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 71 |
|
| 72 |
SUBCASE("set_texture_margin, get_texture_margin") { |
| 73 |
style_box_texture->set_texture_margin(SIDE_LEFT, 1); |
| 74 |
style_box_texture->set_texture_margin(SIDE_TOP, 1); |
| 75 |
style_box_texture->set_texture_margin(SIDE_RIGHT, 1); |
| 76 |
style_box_texture->set_texture_margin(SIDE_BOTTOM, 1); |
| 77 |
|
| 78 |
CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 1); |
| 79 |
CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 1); |
| 80 |
CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 1); |
| 81 |
CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 1); |
| 82 |
} |
| 83 |
|
| 84 |
SUBCASE("set_texture_margin_all") { |
| 85 |
style_box_texture->set_texture_margin_all(2); |
| 86 |
|
| 87 |
CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 2); |
| 88 |
CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 2); |
| 89 |
CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 2); |
| 90 |
CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 2); |
| 91 |
} |
| 92 |
|
| 93 |
SUBCASE("set_texture_margin_individual") { |
| 94 |
style_box_texture->set_texture_margin_individual(3, 4, 5, 6); |
| 95 |
|
| 96 |
CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 3); |
| 97 |
CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 4); |
| 98 |
CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 5); |
| 99 |
CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 6); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
TEST_CASE("[StyleBoxTexture] set_expand_margin, set_expand_margin_all, set_expand_margin_individual") { |
| 104 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 105 |
|
| 106 |
SUBCASE("set_expand_margin, get_expand_margin") { |
| 107 |
style_box_texture->set_expand_margin(SIDE_LEFT, 1); |
| 108 |
style_box_texture->set_expand_margin(SIDE_TOP, 1); |
| 109 |
style_box_texture->set_expand_margin(SIDE_RIGHT, 1); |
| 110 |
style_box_texture->set_expand_margin(SIDE_BOTTOM, 1); |
| 111 |
|
| 112 |
CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 1); |
| 113 |
CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 1); |
| 114 |
CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 1); |
| 115 |
CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 1); |
| 116 |
} |
| 117 |
|
| 118 |
SUBCASE("set_expand_margin_all") { |
| 119 |
style_box_texture->set_expand_margin_all(2); |
| 120 |
|
| 121 |
CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 2); |
| 122 |
CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 2); |
| 123 |
CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 2); |
| 124 |
CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 2); |
| 125 |
} |
| 126 |
|
| 127 |
SUBCASE("set_expand_margin_individual") { |
| 128 |
style_box_texture->set_expand_margin_individual(3, 4, 5, 6); |
| 129 |
|
| 130 |
CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 3); |
| 131 |
CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 4); |
| 132 |
CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 5); |
| 133 |
CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 6); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
TEST_CASE("[StyleBoxTexture] set_region_rect, get_region_rect") { |
| 138 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 139 |
|
| 140 |
style_box_texture->set_region_rect(Rect2(1, 1, 1, 1)); |
| 141 |
CHECK(style_box_texture->get_region_rect() == Rect2(1, 1, 1, 1)); |
| 142 |
} |
| 143 |
|
| 144 |
TEST_CASE("[StyleBoxTexture] set_draw_center, get_draw_center") { |
| 145 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 146 |
|
| 147 |
style_box_texture->set_draw_center(false); |
| 148 |
CHECK(style_box_texture->is_draw_center_enabled() == false); |
| 149 |
} |
| 150 |
|
| 151 |
TEST_CASE("[StyleBoxTexture] set_h_axis_stretch_mode, set_v_axis_stretch_mode, get_h_axis_stretch_mode, get_v_axis_stretch_mode") { |
| 152 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 153 |
|
| 154 |
SUBCASE("set_h_axis_stretch_mode, get_h_axis_stretch_mode") { |
| 155 |
style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE); |
| 156 |
CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE); |
| 157 |
|
| 158 |
style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT); |
| 159 |
CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT); |
| 160 |
|
| 161 |
style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 162 |
CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 163 |
} |
| 164 |
|
| 165 |
SUBCASE("set_v_axis_stretch_mode, get_v_axis_stretch_mode") { |
| 166 |
style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE); |
| 167 |
CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE); |
| 168 |
|
| 169 |
style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT); |
| 170 |
CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT); |
| 171 |
|
| 172 |
style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 173 |
CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
TEST_CASE("[StyleBoxTexture] set_modulate, get_modulate") { |
| 178 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 179 |
|
| 180 |
style_box_texture->set_modulate(Color(0, 0, 0, 0)); |
| 181 |
CHECK(style_box_texture->get_modulate() == Color(0, 0, 0, 0)); |
| 182 |
} |
| 183 |
|
| 184 |
TEST_CASE("[StyleBoxTexture] get_draw_rect") { |
| 185 |
Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture); |
| 186 |
|
| 187 |
style_box_texture->set_expand_margin_all(5); |
| 188 |
CHECK(style_box_texture->get_draw_rect(Rect2(0, 0, 1, 1)) == Rect2(-5, -5, 11, 11)); |
| 189 |
} |
| 190 |
|
| 191 |
} |