Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_style_box_empty.cpp
45991 views
1
/**************************************************************************/
2
/* test_style_box_empty.cpp */
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
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_style_box_empty)
34
35
#include "scene/resources/style_box.h"
36
37
namespace TestStyleBoxEmpty {
38
39
TEST_CASE("[StyleBoxEmpty] Constructor") {
40
Ref<StyleBoxEmpty> style_box_empty = memnew(StyleBoxEmpty);
41
42
CHECK(style_box_empty->get_offset() == Point2(0, 0));
43
CHECK(style_box_empty->get_current_item_drawn() == nullptr);
44
}
45
46
TEST_CASE("[StyleBoxEmpty] set_content_margin, set_content_margin_all, set_content_margin_individual, get_content_margin, get_margin") {
47
Ref<StyleBoxEmpty> style_box_empty = memnew(StyleBoxEmpty);
48
49
SUBCASE("set_content_margin, get_content_margin") {
50
style_box_empty->set_content_margin(SIDE_LEFT, 2);
51
style_box_empty->set_content_margin(SIDE_TOP, 3);
52
style_box_empty->set_content_margin(SIDE_RIGHT, 4);
53
style_box_empty->set_content_margin(SIDE_BOTTOM, 5);
54
55
CHECK(style_box_empty->get_content_margin(SIDE_LEFT) == 2);
56
CHECK(style_box_empty->get_content_margin(SIDE_TOP) == 3);
57
CHECK(style_box_empty->get_content_margin(SIDE_RIGHT) == 4);
58
CHECK(style_box_empty->get_content_margin(SIDE_BOTTOM) == 5);
59
}
60
61
SUBCASE("set_content_margin_all, get_content_margin") {
62
style_box_empty->set_content_margin_all(10);
63
64
CHECK(style_box_empty->get_content_margin(SIDE_LEFT) == 10);
65
CHECK(style_box_empty->get_content_margin(SIDE_TOP) == 10);
66
CHECK(style_box_empty->get_content_margin(SIDE_RIGHT) == 10);
67
CHECK(style_box_empty->get_content_margin(SIDE_BOTTOM) == 10);
68
}
69
70
SUBCASE("set_content_margin, get_margin") {
71
style_box_empty->set_content_margin(SIDE_LEFT, -1);
72
style_box_empty->set_content_margin(SIDE_RIGHT, -2);
73
style_box_empty->set_content_margin(SIDE_TOP, 3);
74
style_box_empty->set_content_margin(SIDE_BOTTOM, 4);
75
76
CHECK_MESSAGE(style_box_empty->get_margin(SIDE_LEFT) == 0,
77
"Value is lesser than zero, so it returns 0");
78
CHECK_MESSAGE(style_box_empty->get_margin(SIDE_RIGHT) == 0,
79
"Value is lesser than zero, so it returns 0");
80
CHECK_MESSAGE(style_box_empty->get_margin(SIDE_TOP) == 3,
81
"Value is higher than zero, so it returns value");
82
CHECK_MESSAGE(style_box_empty->get_margin(SIDE_BOTTOM) == 4,
83
"Value is higher than zero, so it returns value");
84
}
85
86
SUBCASE("set_content_margin_individual, get_minimum_size") {
87
style_box_empty->set_content_margin_individual(-1, 2, 5, 15);
88
89
CHECK(style_box_empty->get_minimum_size() == Size2(5, 17));
90
}
91
92
SUBCASE("set_content_margin_individual, get_offset") {
93
style_box_empty->set_content_margin_individual(-3, 5, 1, 2);
94
95
CHECK_MESSAGE(style_box_empty->get_offset() == Point2(0, 5),
96
"Returns Point2 with get_margin of SIDE_LEFT and SIDE_TOP");
97
}
98
}
99
100
} // namespace TestStyleBoxEmpty
101
102