Add a few more unittest for parsing global_progress.
Postinstall program can occasionally return garbage instead of a
fraction. Add two more test cases.
Bug: None
TEST=unittests still pass.
Change-Id: Ia444acada78eaa124c618b68d3f0880b2348c8f6
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc
index 5a8e950..c3a5120 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -217,15 +217,23 @@
action.accumulated_weight_ = 1;
action.total_weight_ = 8;
- // 50% of the second actions is 2/8 = 0.25 of the total.
+ // 50% of the second action is 2/8 = 0.25 of the total.
EXPECT_CALL(mock_delegate_, ProgressUpdate(0.25));
action.ProcessProgressLine("global_progress 0.5");
testing::Mock::VerifyAndClearExpectations(&mock_delegate_);
+ // 1.5 should be read as 100%, to catch rounding error cases like 1.000001.
+ // 100% of the second is 3/8 of the total.
+ EXPECT_CALL(mock_delegate_, ProgressUpdate(0.375));
+ action.ProcessProgressLine("global_progress 1.5");
+ testing::Mock::VerifyAndClearExpectations(&mock_delegate_);
+
// None of these should trigger a progress update.
action.ProcessProgressLine("foo_bar");
action.ProcessProgressLine("global_progress");
action.ProcessProgressLine("global_progress ");
+ action.ProcessProgressLine("global_progress NaN");
+ action.ProcessProgressLine("global_progress Exception in ... :)");
}
// Test that postinstall succeeds in the simple case of running the default