Change ErrorCode into an enum class.
This change is needed in order for us to be able to import ErrorCode
symbols from chromeos_update_engine into chromeos_update_manager.
Unfortunately, shifting from plain 'enum' into an 'enum class' means
that the compiler treats the new class as a distinct type from int,
which in turn means that plenty of seamless arithmetic/bitwise
operations we used for manipulating error code values throughout the
code needed to be retrofitted with static_cast operators.
In the future, we should consider imposing a proper abstraction on
update engine error codes that'll prevent mingling with value encoding
directly and prevent such nastiness. It'll also make things more
coherent (types, semantics) and safer.
BUG=chromium:358329
TEST=Unit tests.
Change-Id: Ie55fa566b764cdab6c4785d995fb6daee4cb32d3
Reviewed-on: https://chromium-review.googlesource.com/203209
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index e371103..9cd3294 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -147,7 +147,7 @@
public:
OmahaRequestActionTestProcessorDelegate()
: loop_(NULL),
- expected_code_(kErrorCodeSuccess) {}
+ expected_code_(ErrorCode::kSuccess) {}
virtual ~OmahaRequestActionTestProcessorDelegate() {
}
virtual void ProcessingDone(const ActionProcessor* processor,
@@ -163,7 +163,7 @@
if (action->Type() == OmahaRequestAction::StaticType())
EXPECT_EQ(expected_code_, code);
else
- EXPECT_EQ(kErrorCodeSuccess, code);
+ EXPECT_EQ(ErrorCode::kSuccess, code);
}
GMainLoop *loop_;
ErrorCode expected_code_;
@@ -195,7 +195,7 @@
has_input_object_ = HasInputObject();
if (has_input_object_)
omaha_response_ = GetInputObject();
- processor_->ActionComplete(this, kErrorCodeSuccess);
+ processor_->ActionComplete(this, ErrorCode::kSuccess);
}
// Should never be called
void TerminateProcessing() {
@@ -338,7 +338,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -367,7 +367,7 @@
"20101020"), // deadline
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -406,7 +406,7 @@
""), // deadline
-1,
false, // ping_only
- kErrorCodeOmahaUpdateIgnoredPerPolicy,
+ ErrorCode::kOmahaUpdateIgnoredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kIgnored,
metrics::DownloadErrorCode::kUnset,
@@ -447,7 +447,7 @@
""), // deadline
-1,
false, // ping_only
- kErrorCodeOmahaUpdateIgnoredPerPolicy,
+ ErrorCode::kOmahaUpdateIgnoredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kIgnored,
metrics::DownloadErrorCode::kUnset,
@@ -482,7 +482,7 @@
""), // deadline
-1,
false, // ping_only
- kErrorCodeOmahaUpdateIgnoredPerPolicy,
+ ErrorCode::kOmahaUpdateIgnoredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kIgnored,
metrics::DownloadErrorCode::kUnset,
@@ -504,7 +504,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -551,7 +551,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeOmahaUpdateDeferredPerPolicy,
+ ErrorCode::kOmahaUpdateDeferredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kDeferring,
metrics::DownloadErrorCode::kUnset,
@@ -583,7 +583,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -633,7 +633,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -683,7 +683,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -734,7 +734,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -788,7 +788,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeOmahaUpdateDeferredPerPolicy,
+ ErrorCode::kOmahaUpdateDeferredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kDeferring,
metrics::DownloadErrorCode::kUnset,
@@ -824,7 +824,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -876,7 +876,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeOmahaUpdateDeferredPerPolicy,
+ ErrorCode::kOmahaUpdateDeferredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kDeferring,
metrics::DownloadErrorCode::kUnset,
@@ -914,7 +914,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -959,7 +959,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -979,7 +979,7 @@
"",
-1,
false, // ping_only
- kErrorCodeOmahaRequestEmptyResponseError,
+ ErrorCode::kOmahaRequestEmptyResponseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1003,7 +1003,7 @@
"<updatecheck/></app></response>",
-1,
false, // ping_only
- kErrorCodeOmahaResponseInvalid,
+ ErrorCode::kOmahaResponseInvalid,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1027,7 +1027,7 @@
"<updatecheck status=\"InvalidStatusTest\"/></app></response>",
-1,
false, // ping_only
- kErrorCodeOmahaResponseInvalid,
+ ErrorCode::kOmahaResponseInvalid,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1051,7 +1051,7 @@
"</app></response>",
-1,
false, // ping_only
- kErrorCodeOmahaResponseInvalid,
+ ErrorCode::kOmahaResponseInvalid,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1089,7 +1089,7 @@
input_response,
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -1187,7 +1187,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1225,7 +1225,7 @@
"<20110101"), // deadline
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -1258,7 +1258,7 @@
"deadline"),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -1282,7 +1282,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1319,7 +1319,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1361,7 +1361,7 @@
TestEvent(kDefaultTestParams,
new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
OmahaEvent::kResultError,
- kErrorCodeError),
+ ErrorCode::kError),
"invalid xml>",
&post_data);
// convert post_data to string
@@ -1371,7 +1371,7 @@
"errorcode=\"%d\"></event>\n",
OmahaEvent::kTypeDownloadComplete,
OmahaEvent::kResultError,
- kErrorCodeError);
+ static_cast<int>(ErrorCode::kError));
EXPECT_NE(post_str.find(expected_event), string::npos);
EXPECT_EQ(post_str.find("updatecheck"), string::npos);
}
@@ -1435,7 +1435,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1483,7 +1483,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1502,19 +1502,19 @@
OmahaEvent default_event;
EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type);
EXPECT_EQ(OmahaEvent::kResultError, default_event.result);
- EXPECT_EQ(kErrorCodeError, default_event.error_code);
+ EXPECT_EQ(ErrorCode::kError, default_event.error_code);
OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted);
EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type);
EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result);
- EXPECT_EQ(kErrorCodeSuccess, success_event.error_code);
+ EXPECT_EQ(ErrorCode::kSuccess, success_event.error_code);
OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished,
OmahaEvent::kResultError,
- kErrorCodeError);
+ ErrorCode::kError);
EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type);
EXPECT_EQ(OmahaEvent::kResultError, error_event.result);
- EXPECT_EQ(kErrorCodeError, error_event.error_code);
+ EXPECT_EQ(ErrorCode::kError, error_event.error_code);
}
TEST(OmahaRequestActionTest, PingTest) {
@@ -1544,7 +1544,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
ping_only,
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUnset,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1587,7 +1587,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1622,7 +1622,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1658,7 +1658,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1688,7 +1688,7 @@
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
true, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUnset,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1727,7 +1727,7 @@
"<updatecheck status=\"noupdate\"/></app></response>",
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1767,7 +1767,7 @@
"<updatecheck status=\"noupdate\"/></app></response>",
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1793,7 +1793,7 @@
"<updatecheck status=\"noupdate\"/></app></response>",
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1819,7 +1819,7 @@
"<updatecheck status=\"noupdate\"/></app></response>",
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kNoUpdateAvailable,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1837,7 +1837,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -1851,6 +1851,8 @@
TEST(OmahaRequestActionTest, NetworkFailureTest) {
OmahaResponse response;
+ const int http_error_code =
+ static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501;
ASSERT_FALSE(
TestUpdateCheck(NULL, // prefs
NULL, // payload_state
@@ -1860,8 +1862,7 @@
"",
501,
false, // ping_only
- static_cast<ErrorCode>(
- kErrorCodeOmahaRequestHTTPResponseBase + 501),
+ static_cast<ErrorCode>(http_error_code),
metrics::CheckResult::kDownloadError,
metrics::CheckReaction::kUnset,
static_cast<metrics::DownloadErrorCode>(501),
@@ -1872,6 +1873,8 @@
TEST(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
OmahaResponse response;
+ const int http_error_code =
+ static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999;
ASSERT_FALSE(
TestUpdateCheck(NULL, // prefs
NULL, // payload_state
@@ -1881,8 +1884,7 @@
"",
1500,
false, // ping_only
- static_cast<ErrorCode>(
- kErrorCodeOmahaRequestHTTPResponseBase + 999),
+ static_cast<ErrorCode>(http_error_code),
metrics::CheckResult::kDownloadError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kHttpStatusOther,
@@ -1929,7 +1931,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeOmahaUpdateDeferredPerPolicy,
+ ErrorCode::kOmahaUpdateDeferredPerPolicy,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kDeferring,
metrics::DownloadErrorCode::kUnset,
@@ -1965,7 +1967,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -2017,7 +2019,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -2068,7 +2070,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -2119,7 +2121,7 @@
"invalid xml>",
-1,
false, // ping_only
- kErrorCodeOmahaRequestXMLParseError,
+ ErrorCode::kOmahaRequestXMLParseError,
metrics::CheckResult::kParsingError,
metrics::CheckReaction::kUnset,
metrics::DownloadErrorCode::kUnset,
@@ -2183,7 +2185,7 @@
omaha_disable_p2p_for_sharing),
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,
@@ -2308,7 +2310,7 @@
false), // disable_p2p_for sharing
-1,
false, // ping_only
- kErrorCodeSuccess,
+ ErrorCode::kSuccess,
metrics::CheckResult::kUpdateAvailable,
metrics::CheckReaction::kUpdating,
metrics::DownloadErrorCode::kUnset,