From 935ee1f9718438763a075398897c8ee7c1905bf8 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 13 Apr 2023 11:03:34 -0700 Subject: [PATCH] Added test for parsing bad input Test: fastboot_test Change-Id: I04fc24741987bc88a490b2084189dfd8f3714582 --- fastboot/task_test.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fastboot/task_test.cpp b/fastboot/task_test.cpp index 52d1fc391..145b4d77d 100644 --- a/fastboot/task_test.cpp +++ b/fastboot/task_test.cpp @@ -53,6 +53,11 @@ static std::vector> collectTasks(FlashingPlan* fp, return tasks; } +std::unique_ptr ParseCommand(FlashingPlan* fp, std::string command) { + std::vector vec_command = android::base::Split(command, " "); + return ParseFastbootInfoLine(fp, vec_command); +} + TEST_F(ParseTest, CORRECT_FlASH_TASK_FORMED) { std::vector commands = {"flash dtbo", "flash --slot-other system system_other.img", "flash system", "flash --apply-vbmeta vbmeta"}; @@ -97,4 +102,22 @@ TEST_F(ParseTest, VERSION_CHECK_CORRRECT) { for (auto& version : bad_versions) { ASSERT_FALSE(CheckFastbootInfoRequirements(android::base::Split(version, " "))) << version; } -} \ No newline at end of file +} + +TEST_F(ParseTest, BAD_FASTBOOT_INFO_INPUT) { + ASSERT_EQ(ParseCommand(fp.get(), "flash"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "flash --slot-other --apply-vbmeta"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "flash --apply-vbmeta"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "if-wipe"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "if-wipe flash"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "wipe dtbo"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "update-super dtbo"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "flash system system.img system"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "reboot bootloader fastboot"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), + "flash --slot-other --apply-vbmeta system system_other.img system"), + nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "erase"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "erase dtbo dtbo"), nullptr); + ASSERT_EQ(ParseCommand(fp.get(), "wipe this"), nullptr); +}