summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/screen_ui_test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp
index 130a6c161..0014e45f1 100644
--- a/tests/unit/screen_ui_test.cpp
+++ b/tests/unit/screen_ui_test.cpp
@@ -69,6 +69,17 @@ class ScreenUITest : public testing::Test {
MockDrawFunctions draw_funcs_;
};
+// TODO(xunchang) Create a constructor.
+static GRSurface CreateFakeGRSurface(int width, int height, int row_bytes, int pixel_bytes) {
+ GRSurface fake_surface;
+ fake_surface.width = width;
+ fake_surface.height = height;
+ fake_surface.row_bytes = row_bytes;
+ fake_surface.pixel_bytes = pixel_bytes;
+
+ return fake_surface;
+}
+
TEST_F(ScreenUITest, StartPhoneMenuSmoke) {
TextMenu menu(false, 10, 20, HEADERS, ITEMS, 0, 20, draw_funcs_);
ASSERT_FALSE(menu.scrollable());
@@ -229,6 +240,43 @@ TEST_F(ScreenUITest, WearMenuSelectItemsOverflow) {
ASSERT_EQ(3u, menu.MenuEnd());
}
+TEST_F(ScreenUITest, GraphicMenuSelection) {
+ auto fake_surface = CreateFakeGRSurface(50, 50, 50, 1);
+ std::vector<GRSurface*> items = { &fake_surface, &fake_surface, &fake_surface };
+ GraphicMenu menu(&fake_surface, items, 0, draw_funcs_);
+
+ ASSERT_EQ(0, menu.selection());
+
+ int sel = 0;
+ for (int i = 0; i < 3; i++) {
+ sel = menu.Select(++sel);
+ ASSERT_EQ((i + 1) % 3, sel);
+ ASSERT_EQ(sel, menu.selection());
+ }
+
+ sel = 0;
+ for (int i = 0; i < 3; i++) {
+ sel = menu.Select(--sel);
+ ASSERT_EQ(2 - i, sel);
+ ASSERT_EQ(sel, menu.selection());
+ }
+}
+
+TEST_F(ScreenUITest, GraphicMenuValidate) {
+ auto fake_surface = CreateFakeGRSurface(50, 50, 50, 1);
+ std::vector<GRSurface*> items = { &fake_surface, &fake_surface, &fake_surface };
+
+ ASSERT_TRUE(GraphicMenu::Validate(200, 200, &fake_surface, items));
+
+ // Menu exceeds the horizontal boundary.
+ auto wide_surface = CreateFakeGRSurface(300, 50, 300, 1);
+ ASSERT_FALSE(GraphicMenu::Validate(299, 200, &wide_surface, items));
+
+ // Menu exceeds the vertical boundary.
+ items.push_back(&fake_surface);
+ ASSERT_FALSE(GraphicMenu::Validate(200, 249, &fake_surface, items));
+}
+
static constexpr int kMagicAction = 101;
enum class KeyCode : int {