update_engine: Specifically cast macro param to "bool"

This CL casts TEST_AND_RETURN*** macro params to bool when appropriate.
Without this, a TEST_AND_RETURN(uniq) will fail, even though if (uniq)
succeeds where "uniq" is a std::unique_ptr (or shared_ptr).

BUG=none
TEST=unittest

Change-Id: Icaaf84630ab8133667583bba962068dbad65e626
Reviewed-on: https://chromium-review.googlesource.com/233006
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
diff --git a/utils.h b/utils.h
index 8a6510c..50e5864 100644
--- a/utils.h
+++ b/utils.h
@@ -567,7 +567,7 @@
 
 #define TEST_AND_RETURN_FALSE_ERRNO(_x)                                        \
   do {                                                                         \
-    bool _success = (_x);                                                      \
+    bool _success = static_cast<bool>(_x);                                     \
     if (!_success) {                                                           \
       std::string _msg =                                                       \
           chromeos_update_engine::utils::ErrnoNumberAsString(errno);           \
@@ -578,7 +578,7 @@
 
 #define TEST_AND_RETURN_FALSE(_x)                                              \
   do {                                                                         \
-    bool _success = (_x);                                                      \
+    bool _success = static_cast<bool>(_x);                                     \
     if (!_success) {                                                           \
       LOG(ERROR) << #_x " failed.";                                            \
       return false;                                                            \
@@ -587,7 +587,7 @@
 
 #define TEST_AND_RETURN_ERRNO(_x)                                              \
   do {                                                                         \
-    bool _success = (_x);                                                      \
+    bool _success = static_cast<bool>(_x);                                     \
     if (!_success) {                                                           \
       std::string _msg =                                                       \
           chromeos_update_engine::utils::ErrnoNumberAsString(errno);           \
@@ -598,7 +598,7 @@
 
 #define TEST_AND_RETURN(_x)                                                    \
   do {                                                                         \
-    bool _success = (_x);                                                      \
+    bool _success = static_cast<bool>(_x);                                     \
     if (!_success) {                                                           \
       LOG(ERROR) << #_x " failed.";                                            \
       return;                                                                  \
diff --git a/utils_unittest.cc b/utils_unittest.cc
index d5dd6a9..d216893 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -773,4 +773,52 @@
                                      NetworkTethering::kUnknown));
 }
 
+static bool BoolMacroTestHelper() {
+  int i = 1;
+  unsigned int ui = 1;
+  bool b = 1;
+  std::unique_ptr<char> cptr(new char);
+
+  TEST_AND_RETURN_FALSE(i);
+  TEST_AND_RETURN_FALSE(ui);
+  TEST_AND_RETURN_FALSE(b);
+  TEST_AND_RETURN_FALSE(cptr);
+
+  TEST_AND_RETURN_FALSE_ERRNO(i);
+  TEST_AND_RETURN_FALSE_ERRNO(ui);
+  TEST_AND_RETURN_FALSE_ERRNO(b);
+  TEST_AND_RETURN_FALSE_ERRNO(cptr);
+
+  return true;
+}
+
+static void VoidMacroTestHelper(bool* ret) {
+  int i = 1;
+  unsigned int ui = 1;
+  bool b = 1;
+  std::unique_ptr<char> cptr(new char);
+
+  *ret = false;
+
+  TEST_AND_RETURN(i);
+  TEST_AND_RETURN(ui);
+  TEST_AND_RETURN(b);
+  TEST_AND_RETURN(cptr);
+
+  TEST_AND_RETURN_ERRNO(i);
+  TEST_AND_RETURN_ERRNO(ui);
+  TEST_AND_RETURN_ERRNO(b);
+  TEST_AND_RETURN_ERRNO(cptr);
+
+  *ret = true;
+}
+
+TEST(UtilsTest, TestMacros) {
+  bool void_test = false;
+  VoidMacroTestHelper(&void_test);
+  EXPECT_TRUE(void_test);
+
+  EXPECT_TRUE(BoolMacroTestHelper());
+}
+
 }  // namespace chromeos_update_engine