Switch OmahaEvent's error_code to ActionExitCode.
Also, emit the errorcode attribute only for non-success events.
Added explicit unit tests for OmahaEvent.
BUG=560
TEST=unit tests, gmerged on device, forced update, looked at logs.
Review URL: http://codereview.chromium.org/3035007
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index e801f40..97c1ea9 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -69,10 +69,15 @@
" <o:ping active=\"0\"></o:ping>\n"
" <o:updatecheck></o:updatecheck>\n");
} else {
+ // The error code is an optional attribute so append it only if
+ // the result is not success.
+ string error_code;
+ if (event->result != OmahaEvent::kResultSuccess) {
+ error_code = StringPrintf(" errorcode=\"%d\"", event->error_code);
+ }
body = StringPrintf(
- " <o:event eventtype=\"%d\" eventresult=\"%d\" "
- "errorcode=\"%d\"></o:event>\n",
- event->type, event->result, event->error_code);
+ " <o:event eventtype=\"%d\" eventresult=\"%d\"%s></o:event>\n",
+ event->type, event->result, error_code.c_str());
}
return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "