From 68b84df9949983d8a0e55183749f1f6d2a0bb670 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 13 Apr 2023 11:39:26 -0700 Subject: [PATCH] Added test for version check Test: fastboot_test Bug: 194686221 Change-Id: I886c0a91be3b4f4bf7f2b8c76704aa30a352ee5b --- fastboot/fastboot.h | 1 + fastboot/task_test.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index b3dc67dc2..d6afb9ed8 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -133,6 +133,7 @@ void syntax_error(const char* fmt, ...); std::string get_current_slot(); // Code for Parsing fastboot-info.txt +bool CheckFastbootInfoRequirements(const std::vector& command); std::unique_ptr ParseFlashCommand(const FlashingPlan* fp, const std::vector& parts); std::unique_ptr ParseRebootCommand(const FlashingPlan* fp, diff --git a/fastboot/task_test.cpp b/fastboot/task_test.cpp index 400e27f74..52d1fc391 100644 --- a/fastboot/task_test.cpp +++ b/fastboot/task_test.cpp @@ -80,3 +80,21 @@ TEST_F(ParseTest, CORRECT_FlASH_TASK_FORMED) { ASSERT_EQ(task->GetImageName(), expected_values[i][3]); } } + +TEST_F(ParseTest, VERSION_CHECK_CORRRECT) { + std::vector correct_versions = { + "version 1.0", + "version 22.00", + }; + + std::vector bad_versions = {"version", "version .01", "version x1", + "version 1.0.1", "version 1.", "s 1.0", + "version 1.0 2.0"}; + + for (auto& version : correct_versions) { + ASSERT_TRUE(CheckFastbootInfoRequirements(android::base::Split(version, " "))) << version; + } + for (auto& version : bad_versions) { + ASSERT_FALSE(CheckFastbootInfoRequirements(android::base::Split(version, " "))) << version; + } +} \ No newline at end of file