| 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/gui/option_button.h" |
| 34 |
|
| 35 |
#include "tests/test_macros.h" |
| 36 |
|
| 37 |
namespace TestOptionButton { |
| 38 |
|
| 39 |
TEST_CASE("[SceneTree][OptionButton] Initialization") { |
| 40 |
OptionButton *test_opt = memnew(OptionButton); |
| 41 |
|
| 42 |
SUBCASE("There should be no options right after initialization") { |
| 43 |
CHECK_FALSE(test_opt->has_selectable_items()); |
| 44 |
CHECK(test_opt->get_item_count() == 0); |
| 45 |
} |
| 46 |
|
| 47 |
memdelete(test_opt); |
| 48 |
} |
| 49 |
|
| 50 |
TEST_CASE("[SceneTree][OptionButton] Single item") { |
| 51 |
OptionButton *test_opt = memnew(OptionButton); |
| 52 |
|
| 53 |
SUBCASE("There should a single item after after adding one") { |
| 54 |
test_opt->add_item("single", 1013); |
| 55 |
|
| 56 |
CHECK(test_opt->has_selectable_items()); |
| 57 |
CHECK(test_opt->get_item_count() == 1); |
| 58 |
CHECK(test_opt->get_item_index(1013) == 0); |
| 59 |
CHECK(test_opt->get_item_id(0) == 1013); |
| 60 |
|
| 61 |
test_opt->remove_item(0); |
| 62 |
|
| 63 |
CHECK_FALSE(test_opt->has_selectable_items()); |
| 64 |
CHECK(test_opt->get_item_count() == 0); |
| 65 |
} |
| 66 |
|
| 67 |
SUBCASE("There should a single item after after adding an icon") { |
| 68 |
Ref<Texture2D> test_icon = memnew(Texture2D); |
| 69 |
test_opt->add_icon_item(test_icon, "icon", 345); |
| 70 |
|
| 71 |
CHECK(test_opt->has_selectable_items()); |
| 72 |
CHECK(test_opt->get_item_count() == 1); |
| 73 |
CHECK(test_opt->get_item_index(345) == 0); |
| 74 |
CHECK(test_opt->get_item_id(0) == 345); |
| 75 |
|
| 76 |
test_opt->remove_item(0); |
| 77 |
|
| 78 |
CHECK_FALSE(test_opt->has_selectable_items()); |
| 79 |
CHECK(test_opt->get_item_count() == 0); |
| 80 |
} |
| 81 |
|
| 82 |
memdelete(test_opt); |
| 83 |
} |
| 84 |
|
| 85 |
TEST_CASE("[SceneTree][OptionButton] Many items") { |
| 86 |
OptionButton *test_opt = memnew(OptionButton); |
| 87 |
|
| 88 |
SUBCASE("Creating a complex structure and checking getters") { |
| 89 |
|
| 90 |
Ref<Texture2D> test_icon1 = memnew(Texture2D); |
| 91 |
Ref<Texture2D> test_icon2 = memnew(Texture2D); |
| 92 |
|
| 93 |
Ref<Texture2D> test_icon4 = memnew(Texture2D); |
| 94 |
|
| 95 |
test_opt->add_item("first", 100); |
| 96 |
test_opt->add_icon_item(test_icon1, "second_icon", 101); |
| 97 |
test_opt->add_icon_item(test_icon2, "third_icon", 102); |
| 98 |
test_opt->add_item("fourth", 104); |
| 99 |
test_opt->add_icon_item(test_icon4, "fifth_icon", 104); |
| 100 |
|
| 101 |
|
| 102 |
test_opt->set_item_disabled(4, true); |
| 103 |
|
| 104 |
CHECK(test_opt->has_selectable_items()); |
| 105 |
CHECK(test_opt->get_item_count() == 5); |
| 106 |
|
| 107 |
|
| 108 |
CHECK(test_opt->get_item_index(102) == 2); |
| 109 |
CHECK(test_opt->get_item_id(2) == 102); |
| 110 |
|
| 111 |
|
| 112 |
test_opt->remove_item(3); |
| 113 |
test_opt->remove_item(0); |
| 114 |
|
| 115 |
CHECK(test_opt->has_selectable_items()); |
| 116 |
CHECK(test_opt->get_item_count() == 3); |
| 117 |
|
| 118 |
|
| 119 |
CHECK(test_opt->get_item_index(104) == 2); |
| 120 |
CHECK(test_opt->get_item_id(2) == 104); |
| 121 |
|
| 122 |
|
| 123 |
test_opt->remove_item(1); |
| 124 |
test_opt->remove_item(0); |
| 125 |
|
| 126 |
CHECK_FALSE(test_opt->has_selectable_items()); |
| 127 |
CHECK(test_opt->get_item_count() == 1); |
| 128 |
} |
| 129 |
|
| 130 |
SUBCASE("Getters and setters not related to structure") { |
| 131 |
test_opt->add_item("regular", 2019); |
| 132 |
|
| 133 |
Ref<Texture2D> test_icon = memnew(Texture2D); |
| 134 |
test_opt->add_icon_item(test_icon, "icon", 3092); |
| 135 |
|
| 136 |
|
| 137 |
test_opt->set_item_text(0, "example text"); |
| 138 |
CHECK(test_opt->get_item_text(0) == "example text"); |
| 139 |
|
| 140 |
|
| 141 |
Dictionary m; |
| 142 |
m["bool"] = true; |
| 143 |
m["String"] = "yes"; |
| 144 |
test_opt->set_item_metadata(1, m); |
| 145 |
CHECK(test_opt->get_item_metadata(1) == m); |
| 146 |
|
| 147 |
|
| 148 |
test_opt->set_item_tooltip(0, "tooltip guide"); |
| 149 |
CHECK(test_opt->get_item_tooltip(0) == "tooltip guide"); |
| 150 |
|
| 151 |
test_opt->remove_item(1); |
| 152 |
test_opt->remove_item(0); |
| 153 |
} |
| 154 |
|
| 155 |
memdelete(test_opt); |
| 156 |
} |
| 157 |
|
| 158 |
} |