summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-05-13 09:34:45 +0200
committerTao Bao <tbao@google.com>2018-05-14 20:14:00 +0200
commit152e0eb20b16c2854ca9690b1cc3b64fbb8962fe (patch)
tree229360257b48faafc6e99ba725683827f053a026 /tests
parentMerge "Clean up the Makefile for recovery and tests." (diff)
downloadandroid_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar.gz
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar.bz2
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar.lz
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar.xz
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.tar.zst
android_bootable_recovery-152e0eb20b16c2854ca9690b1cc3b64fbb8962fe.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/screen_ui_test.cpp56
1 files changed, 53 insertions, 3 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 <stddef.h>
+#include <stdio.h>
#include <functional>
#include <map>
@@ -23,6 +24,8 @@
#include <vector>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#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<TestableScreenRecoveryUI>();
- 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<TestableScreenRecoveryUI> 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<std::string> 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), "");
+}