From 152e0eb20b16c2854ca9690b1cc3b64fbb8962fe Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Sun, 13 May 2018 00:34:45 -0700 Subject: wear_ui: Address a TODO regarding {intro,loop}_frames. Also add tests for LoadAnimation that cover the change. Test: Run `recovery_unit_test` on marlin. Change-Id: I0380a5cdd0d85d55baecf7759eb647b6a9f3a085 --- tests/unit/screen_ui_test.cpp | 56 ++++++++++++++++++++++++++++++++++++++++--- wear_ui.cpp | 5 ---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp index 03e23ca42..269222faa 100644 --- a/tests/unit/screen_ui_test.cpp +++ b/tests/unit/screen_ui_test.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -23,6 +24,8 @@ #include #include +#include +#include #include #include "common/test_constants.h" @@ -224,6 +227,19 @@ class TestableScreenRecoveryUI : public ScreenRecoveryUI { int KeyHandler(int key, bool visible) const; + // The following functions expose the protected members for test purpose. + void RunLoadAnimation() { + LoadAnimation(); + } + + size_t GetLoopFrames() const { + return loop_frames; + } + + size_t GetIntroFrames() const { + return intro_frames; + } + bool GetRtlLocale() const { return rtl_locale_; } @@ -260,14 +276,15 @@ class ScreenRecoveryUITest : public ::testing::Test { void SetUp() override { ui_ = std::make_unique(); - std::string testdata_dir = from_testdata_base(""); - Paths::Get().set_resource_dir(testdata_dir); - res_set_resource_dir(testdata_dir); + testdata_dir_ = from_testdata_base(""); + Paths::Get().set_resource_dir(testdata_dir_); + res_set_resource_dir(testdata_dir_); ASSERT_TRUE(ui_->Init(kTestLocale)); } std::unique_ptr ui_; + std::string testdata_dir_; }; TEST_F(ScreenRecoveryUITest, Init) { @@ -352,3 +369,36 @@ TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut_TextWasEverVisible) { std::bind(&TestableScreenRecoveryUI::KeyHandler, ui_.get(), std::placeholders::_1, std::placeholders::_2))); } + +TEST_F(ScreenRecoveryUITest, LoadAnimation) { + // Make a few copies of loop00000.png from testdata. + std::string image_data; + ASSERT_TRUE(android::base::ReadFileToString(testdata_dir_ + "/loop00000.png", &image_data)); + + std::vector tempfiles; + TemporaryDir resource_dir; + for (const auto& name : { "00002", "00100", "00050" }) { + tempfiles.push_back(android::base::StringPrintf("%s/loop%s.png", resource_dir.path, name)); + ASSERT_TRUE(android::base::WriteStringToFile(image_data, tempfiles.back())); + } + for (const auto& name : { "00", "01" }) { + tempfiles.push_back(android::base::StringPrintf("%s/intro%s.png", resource_dir.path, name)); + ASSERT_TRUE(android::base::WriteStringToFile(image_data, tempfiles.back())); + } + Paths::Get().set_resource_dir(resource_dir.path); + + ui_->RunLoadAnimation(); + + ASSERT_EQ(2u, ui_->GetIntroFrames()); + ASSERT_EQ(3u, ui_->GetLoopFrames()); + + for (const auto& name : tempfiles) { + ASSERT_EQ(0, unlink(name.c_str())); + } +} + +TEST_F(ScreenRecoveryUITest, LoadAnimation_MissingAnimation) { + TemporaryDir resource_dir; + Paths::Get().set_resource_dir(resource_dir.path); + ASSERT_EXIT(ui_->RunLoadAnimation(), ::testing::KilledBySignal(SIGABRT), ""); +} diff --git a/wear_ui.cpp b/wear_ui.cpp index f157d3ca3..f4a839923 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -32,11 +32,6 @@ WearRecoveryUI::WearRecoveryUI() kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) { // TODO: kMenuUnusableRows should be computed based on the lines in draw_screen_locked(). - // TODO: The following three variables are likely not needed. The first two are detected - // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device. - intro_frames = 22; - loop_frames = 60; - touch_screen_allowed_ = true; } -- cgit v1.2.3