summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-01-06 18:58:31 +0100
committerandroid-build-merger <android-build-merger@google.com>2017-01-06 18:58:31 +0100
commit7b5992fa51422fbbcc8148c192b1156529bc0481 (patch)
treee8e2f41cb6478db414534b913dadef6a9b512aa2 /tests
parentMerge "updater: Clean up CreateStash()." am: 91f74c82cd am: 719a15b187 am: fbb5dbb471 (diff)
parentMerge "tests: Add testcase for show_progress() and set_progress()." am: 478a5ec9c7 am: 179fc8a82b (diff)
downloadandroid_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar.gz
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar.bz2
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar.lz
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar.xz
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.tar.zst
android_bootable_recovery-7b5992fa51422fbbcc8148c192b1156529bc0481.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/component/updater_test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index f31f1f82a..fa5f03134 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -22,6 +23,8 @@
#include <android-base/file.h>
#include <android-base/properties.h>
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
#include <android-base/test_utils.h>
#include <bootloader_message/bootloader_message.h>
#include <gtest/gtest.h>
@@ -510,3 +513,50 @@ TEST_F(UpdaterTest, set_stage) {
script = "set_stage(\"/dev/full\", \"1/3\")";
expect("", script.c_str(), kNoCause);
}
+
+TEST_F(UpdaterTest, set_progress) {
+ // set_progress() expects one argument.
+ expect(nullptr, "set_progress()", kArgsParsingFailure);
+ expect(nullptr, "set_progress(\"arg1\", \"arg2\")", kArgsParsingFailure);
+
+ // Invalid progress argument.
+ expect(nullptr, "set_progress(\"arg1\")", kArgsParsingFailure);
+ expect(nullptr, "set_progress(\"3x+5\")", kArgsParsingFailure);
+ expect(nullptr, "set_progress(\".3.5\")", kArgsParsingFailure);
+
+ TemporaryFile tf;
+ UpdaterInfo updater_info;
+ updater_info.cmd_pipe = fdopen(tf.fd, "w");
+ expect(".52", "set_progress(\".52\")", kNoCause, &updater_info);
+ fflush(updater_info.cmd_pipe);
+
+ std::string cmd;
+ ASSERT_TRUE(android::base::ReadFileToString(tf.path, &cmd));
+ ASSERT_EQ(android::base::StringPrintf("set_progress %f\n", .52), cmd);
+ // recovery-updater protocol expects 2 tokens ("set_progress <frac>").
+ ASSERT_EQ(2U, android::base::Split(cmd, " ").size());
+}
+
+TEST_F(UpdaterTest, show_progress) {
+ // show_progress() expects two arguments.
+ expect(nullptr, "show_progress()", kArgsParsingFailure);
+ expect(nullptr, "show_progress(\"arg1\")", kArgsParsingFailure);
+ expect(nullptr, "show_progress(\"arg1\", \"arg2\", \"arg3\")", kArgsParsingFailure);
+
+ // Invalid progress arguments.
+ expect(nullptr, "show_progress(\"arg1\", \"arg2\")", kArgsParsingFailure);
+ expect(nullptr, "show_progress(\"3x+5\", \"10\")", kArgsParsingFailure);
+ expect(nullptr, "show_progress(\".3\", \"5a\")", kArgsParsingFailure);
+
+ TemporaryFile tf;
+ UpdaterInfo updater_info;
+ updater_info.cmd_pipe = fdopen(tf.fd, "w");
+ expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_info);
+ fflush(updater_info.cmd_pipe);
+
+ std::string cmd;
+ ASSERT_TRUE(android::base::ReadFileToString(tf.path, &cmd));
+ ASSERT_EQ(android::base::StringPrintf("progress %f %d\n", .52, 10), cmd);
+ // recovery-updater protocol expects 3 tokens ("progress <frac> <secs>").
+ ASSERT_EQ(3U, android::base::Split(cmd, " ").size());
+}