From e02a5b248ba0e1364687c20dd5f2ebe1fe9cf638 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 2 May 2018 15:46:11 -0700 Subject: screen_ui: Merge Menu::Start() into its ctor. Since we instantiate a Menu object each time for a given set of header/items, we don't have a use case of re-populating an existing Menu with different data (which is what Menu::Start() does). Test: mmma -j bootable/recovery Test: Run recovery_unit_test on marlin. Test: Build and boot into recovery image on angler. Check the UI. Change-Id: Iaa2ba9d406ebd74c015e43198c17c5335b38df53 --- tests/unit/screen_ui_test.cpp | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'tests/unit/screen_ui_test.cpp') diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp index be6799f2e..9c123e863 100644 --- a/tests/unit/screen_ui_test.cpp +++ b/tests/unit/screen_ui_test.cpp @@ -24,10 +24,8 @@ constexpr const char* HEADER[] = { "header", nullptr }; constexpr const char* ITEMS[] = { "items1", "items2", "items3", "items4", "1234567890", nullptr }; TEST(ScreenUITest, StartPhoneMenuSmoke) { - Menu menu(false, 10, 20); + Menu menu(false, 10, 20, HEADER, ITEMS, 0); ASSERT_FALSE(menu.scrollable()); - - menu.Start(HEADER, ITEMS, 0); ASSERT_EQ(HEADER[0], menu.text_headers()[0]); ASSERT_EQ(5u, menu.ItemsCount()); @@ -41,10 +39,8 @@ TEST(ScreenUITest, StartPhoneMenuSmoke) { } TEST(ScreenUITest, StartWearMenuSmoke) { - Menu menu(true, 10, 8); + Menu menu(true, 10, 8, HEADER, ITEMS, 1); ASSERT_TRUE(menu.scrollable()); - - menu.Start(HEADER, ITEMS, 1); ASSERT_EQ(HEADER[0], menu.text_headers()[0]); ASSERT_EQ(5u, menu.ItemsCount()); @@ -59,10 +55,8 @@ TEST(ScreenUITest, StartWearMenuSmoke) { } TEST(ScreenUITest, StartPhoneMenuItemsOverflow) { - Menu menu(false, 1, 20); + Menu menu(false, 1, 20, HEADER, ITEMS, 0); ASSERT_FALSE(menu.scrollable()); - - menu.Start(HEADER, ITEMS, 0); ASSERT_EQ(1u, menu.ItemsCount()); std::string message; @@ -76,10 +70,8 @@ TEST(ScreenUITest, StartPhoneMenuItemsOverflow) { } TEST(ScreenUITest, StartWearMenuItemsOverflow) { - Menu menu(true, 1, 20); + Menu menu(true, 1, 20, HEADER, ITEMS, 0); ASSERT_TRUE(menu.scrollable()); - - menu.Start(HEADER, ITEMS, 0); ASSERT_EQ(5u, menu.ItemsCount()); std::string message; @@ -95,10 +87,8 @@ TEST(ScreenUITest, StartWearMenuItemsOverflow) { } TEST(ScreenUITest, PhoneMenuSelectSmoke) { - Menu menu(false, 10, 20); - int sel = 0; - menu.Start(HEADER, ITEMS, sel); + Menu menu(false, 10, 20, HEADER, ITEMS, sel); // Mimic down button 10 times (2 * items size) for (int i = 0; i < 10; i++) { sel = menu.Select(++sel); @@ -126,10 +116,8 @@ TEST(ScreenUITest, PhoneMenuSelectSmoke) { } TEST(ScreenUITest, WearMenuSelectSmoke) { - Menu menu(true, 10, 20); - int sel = 0; - menu.Start(HEADER, ITEMS, sel); + Menu menu(true, 10, 20, HEADER, ITEMS, sel); // Mimic pressing down button 10 times (2 * items size) for (int i = 0; i < 10; i++) { sel = menu.Select(++sel); @@ -157,10 +145,8 @@ TEST(ScreenUITest, WearMenuSelectSmoke) { } TEST(ScreenUITest, WearMenuSelectItemsOverflow) { - Menu menu(true, 3, 20); - int sel = 1; - menu.Start(HEADER, ITEMS, sel); + Menu menu(true, 3, 20, HEADER, ITEMS, sel); ASSERT_EQ(5u, menu.ItemsCount()); // Scroll the menu to the end, and check the start & end of menu. -- cgit v1.2.3 From 1fe1afe863fde957051774cf2d9936c314d342a2 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 1 May 2018 15:56:05 -0700 Subject: Move menu headers/items to std::vector. Test: mmma -j bootable/recovery Test: Run recovery_unit_test on marlin. Test: Build and boot into recovery image on angler. Check the UI that shows menu ('View recovery log', 'Wipe data', 'Run locale test'). Test: Start recovery with '--prompt_and_wipe_data'. Check the UI. Change-Id: If8a4209e0bb4ca64f719f9f9465d3b3589a69cdc --- tests/unit/screen_ui_test.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'tests/unit/screen_ui_test.cpp') diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp index 9c123e863..e47d7054b 100644 --- a/tests/unit/screen_ui_test.cpp +++ b/tests/unit/screen_ui_test.cpp @@ -14,19 +14,22 @@ * limitations under the License. */ -#include "screen_ui.h" +#include #include +#include #include -constexpr const char* HEADER[] = { "header", nullptr }; -constexpr const char* ITEMS[] = { "items1", "items2", "items3", "items4", "1234567890", nullptr }; +#include "screen_ui.h" + +static const std::vector HEADERS{ "header" }; +static const std::vector ITEMS{ "item1", "item2", "item3", "item4", "1234567890" }; TEST(ScreenUITest, StartPhoneMenuSmoke) { - Menu menu(false, 10, 20, HEADER, ITEMS, 0); + Menu menu(false, 10, 20, HEADERS, ITEMS, 0); ASSERT_FALSE(menu.scrollable()); - ASSERT_EQ(HEADER[0], menu.text_headers()[0]); + ASSERT_EQ(HEADERS[0], menu.text_headers()[0]); ASSERT_EQ(5u, menu.ItemsCount()); std::string message; @@ -39,9 +42,9 @@ TEST(ScreenUITest, StartPhoneMenuSmoke) { } TEST(ScreenUITest, StartWearMenuSmoke) { - Menu menu(true, 10, 8, HEADER, ITEMS, 1); + Menu menu(true, 10, 8, HEADERS, ITEMS, 1); ASSERT_TRUE(menu.scrollable()); - ASSERT_EQ(HEADER[0], menu.text_headers()[0]); + ASSERT_EQ(HEADERS[0], menu.text_headers()[0]); ASSERT_EQ(5u, menu.ItemsCount()); std::string message; @@ -55,7 +58,7 @@ TEST(ScreenUITest, StartWearMenuSmoke) { } TEST(ScreenUITest, StartPhoneMenuItemsOverflow) { - Menu menu(false, 1, 20, HEADER, ITEMS, 0); + Menu menu(false, 1, 20, HEADERS, ITEMS, 0); ASSERT_FALSE(menu.scrollable()); ASSERT_EQ(1u, menu.ItemsCount()); @@ -70,7 +73,7 @@ TEST(ScreenUITest, StartPhoneMenuItemsOverflow) { } TEST(ScreenUITest, StartWearMenuItemsOverflow) { - Menu menu(true, 1, 20, HEADER, ITEMS, 0); + Menu menu(true, 1, 20, HEADERS, ITEMS, 0); ASSERT_TRUE(menu.scrollable()); ASSERT_EQ(5u, menu.ItemsCount()); @@ -88,7 +91,7 @@ TEST(ScreenUITest, StartWearMenuItemsOverflow) { TEST(ScreenUITest, PhoneMenuSelectSmoke) { int sel = 0; - Menu menu(false, 10, 20, HEADER, ITEMS, sel); + Menu menu(false, 10, 20, HEADERS, ITEMS, sel); // Mimic down button 10 times (2 * items size) for (int i = 0; i < 10; i++) { sel = menu.Select(++sel); @@ -117,7 +120,7 @@ TEST(ScreenUITest, PhoneMenuSelectSmoke) { TEST(ScreenUITest, WearMenuSelectSmoke) { int sel = 0; - Menu menu(true, 10, 20, HEADER, ITEMS, sel); + Menu menu(true, 10, 20, HEADERS, ITEMS, sel); // Mimic pressing down button 10 times (2 * items size) for (int i = 0; i < 10; i++) { sel = menu.Select(++sel); @@ -146,7 +149,7 @@ TEST(ScreenUITest, WearMenuSelectSmoke) { TEST(ScreenUITest, WearMenuSelectItemsOverflow) { int sel = 1; - Menu menu(true, 3, 20, HEADER, ITEMS, sel); + Menu menu(true, 3, 20, HEADERS, ITEMS, sel); ASSERT_EQ(5u, menu.ItemsCount()); // Scroll the menu to the end, and check the start & end of menu. -- cgit v1.2.3