More missing calls to Result::ok() in apexd tests

Test: m checkbuild
Change-Id: Ibb345f4b1f6b90a38f0e612587e590e8a208781d
diff --git a/apexd/apex_file_test.cpp b/apexd/apex_file_test.cpp
index bba45a0..88de83b 100644
--- a/apexd/apex_file_test.cpp
+++ b/apexd/apex_file_test.cpp
@@ -37,7 +37,7 @@
 TEST(ApexFileTest, GetOffsetOfSimplePackage) {
   const std::string filePath = testDataDir + "apex.apexd_test.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile);
+  ASSERT_TRUE(apexFile.ok());
 
   int32_t zip_image_offset;
   size_t zip_image_size;
@@ -65,7 +65,7 @@
 TEST(ApexFileTest, GetOffsetMissingFile) {
   const std::string filePath = testDataDir + "missing.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_FALSE(apexFile);
+  ASSERT_FALSE(apexFile.ok());
   EXPECT_NE(std::string::npos,
             apexFile.error().message().find("Failed to open package"))
       << apexFile.error();
@@ -74,7 +74,7 @@
 TEST(ApexFileTest, GetApexManifest) {
   const std::string filePath = testDataDir + "apex.apexd_test.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile);
+  ASSERT_RESULT_OK(apexFile);
   EXPECT_EQ("com.android.apex.test_package", apexFile->GetManifest().name());
   EXPECT_EQ(1u, apexFile->GetManifest().version());
 }
@@ -82,10 +82,10 @@
 TEST(ApexFileTest, VerifyApexVerity) {
   const std::string filePath = testDataDir + "apex.apexd_test.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile) << apexFile.error();
+  ASSERT_RESULT_OK(apexFile);
 
   auto verity_or = apexFile->VerifyApexVerity();
-  ASSERT_TRUE(verity_or) << verity_or.error();
+  ASSERT_RESULT_OK(verity_or);
 
   const ApexVerityData& data = *verity_or;
   EXPECT_NE(nullptr, data.desc.get());
@@ -100,10 +100,10 @@
 TEST(ApexFileTest, DISABLED_VerifyApexVerityNoKeyDir) {
   const std::string filePath = testDataDir + "apex.apexd_test.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile) << apexFile.error();
+  ASSERT_RESULT_OK(apexFile);
 
   auto verity_or = apexFile->VerifyApexVerity();
-  ASSERT_FALSE(verity_or);
+  ASSERT_FALSE(verity_or.ok());
 }
 
 // TODO(jiyong): re-enable this test. This test is disabled because the build
@@ -115,16 +115,16 @@
 TEST(ApexFileTest, DISABLED_VerifyApexVerityNoKeyInst) {
   const std::string filePath = testDataDir + "apex.apexd_test_no_inst_key.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile) << apexFile.error();
+  ASSERT_RESULT_OK(apexFile);
 
   auto verity_or = apexFile->VerifyApexVerity();
-  ASSERT_FALSE(verity_or);
+  ASSERT_FALSE(verity_or.ok());
 }
 
 TEST(ApexFileTest, GetBundledPublicKey) {
   const std::string filePath = testDataDir + "apex.apexd_test.apex";
   Result<ApexFile> apexFile = ApexFile::Open(filePath);
-  ASSERT_TRUE(apexFile) << apexFile.error();
+  ASSERT_RESULT_OK(apexFile);
 
   const std::string keyPath =
       testDataDir + "apexd_testdata/com.android.apex.test_package.avbpubkey";
diff --git a/apexd/apex_manifest_test.cpp b/apexd/apex_manifest_test.cpp
index dec6d76..a4844cc 100644
--- a/apexd/apex_manifest_test.cpp
+++ b/apexd/apex_manifest_test.cpp
@@ -28,7 +28,7 @@
 TEST(ApexManifestTest, SimpleTest) {
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_EQ("com.android.example.apex", std::string(apex_manifest->name()));
   EXPECT_EQ(1u, apex_manifest->version());
   EXPECT_FALSE(apex_manifest->nocode());
@@ -36,7 +36,7 @@
 
 TEST(ApexManifestTest, NameMissing) {
   auto apex_manifest = ParseManifestJson("{\"version\": 1}\n");
-  ASSERT_FALSE(apex_manifest);
+  ASSERT_FALSE(apex_manifest.ok());
   EXPECT_EQ(apex_manifest.error().message(),
             std::string("Missing required field \"name\" from APEX manifest."))
       << apex_manifest.error();
@@ -45,7 +45,7 @@
 TEST(ApexManifestTest, VersionMissing) {
   auto apex_manifest =
       ParseManifestJson("{\"name\": \"com.android.example.apex\"}\n");
-  ASSERT_FALSE(apex_manifest);
+  ASSERT_FALSE(apex_manifest.ok());
   EXPECT_EQ(
       apex_manifest.error().message(),
       std::string("Missing required field \"version\" from APEX manifest."))
@@ -56,7 +56,7 @@
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": \"a\"}\n");
 
-  ASSERT_FALSE(apex_manifest);
+  ASSERT_FALSE(apex_manifest.ok());
   EXPECT_EQ(apex_manifest.error().message(),
             std::string("Failed to parse APEX Manifest JSON config: "
                         "(version): invalid value \"a\" for type TYPE_INT64"))
@@ -66,7 +66,7 @@
 TEST(ApexManifestTest, NoPreInstallHook) {
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_EQ("", std::string(apex_manifest->preinstallhook()));
 }
 
@@ -74,14 +74,14 @@
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1, "
       "\"preInstallHook\": \"bin/preInstallHook\"}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_EQ("bin/preInstallHook", std::string(apex_manifest->preinstallhook()));
 }
 
 TEST(ApexManifestTest, NoPostInstallHook) {
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_EQ("", std::string(apex_manifest->postinstallhook()));
 }
 
@@ -89,14 +89,14 @@
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1, "
       "\"postInstallHook\": \"bin/postInstallHook\"}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_EQ("bin/postInstallHook",
             std::string(apex_manifest->postinstallhook()));
 }
 
 TEST(ApexManifestTest, UnparsableManifest) {
   auto apex_manifest = ParseManifestJson("This is an invalid pony");
-  ASSERT_FALSE(apex_manifest);
+  ASSERT_FALSE(apex_manifest.ok());
   EXPECT_EQ(apex_manifest.error().message(),
             std::string("Failed to parse APEX Manifest JSON config: Unexpected "
                         "token.\nThis is an invalid p\n^"))
@@ -107,7 +107,7 @@
   auto apex_manifest = ParseManifestJson(
       "{\"name\": \"com.android.example.apex\", \"version\": 1, "
       "\"noCode\": true}\n");
-  ASSERT_TRUE(apex_manifest) << apex_manifest.error();
+  ASSERT_RESULT_OK(apex_manifest);
   EXPECT_TRUE(apex_manifest->nocode());
 }
 
diff --git a/apexd/apexd_test_utils.h b/apexd/apexd_test_utils.h
index 7a0cd2c..77ed21c 100644
--- a/apexd/apexd_test_utils.h
+++ b/apexd/apexd_test_utils.h
@@ -34,13 +34,11 @@
 using ::testing::Field;
 
 template <typename T>
-inline ::testing::AssertionResult IsOk(
-    const android::base::Result<T>& status_or) {
-  if (status_or) {
+inline ::testing::AssertionResult IsOk(const android::base::Result<T>& result) {
+  if (result.ok()) {
     return ::testing::AssertionSuccess() << " is Ok";
   } else {
-    return ::testing::AssertionFailure()
-           << " failed with " << status_or.error();
+    return ::testing::AssertionFailure() << " failed with " << result.error();
   }
 }
 
diff --git a/apexd/apexservice_test.cpp b/apexd/apexservice_test.cpp
index e8525de..b90af36 100644
--- a/apexd/apexservice_test.cpp
+++ b/apexd/apexservice_test.cpp
@@ -326,7 +326,7 @@
       package = "";  // Explicitly mark as not initialized.
 
       Result<ApexFile> apex_file = ApexFile::Open(test);
-      if (!apex_file) {
+      if (!apex_file.ok()) {
         return;
       }
 
@@ -344,7 +344,7 @@
         auto fail_fn = [&]() {
           Result<ApexFile> apex_file = ApexFile::Open(test_input);
           ASSERT_FALSE(IsOk(apex_file));
-          ASSERT_TRUE(apex_file)
+          ASSERT_TRUE(apex_file.ok())
               << test_input << " failed to load: " << apex_file.error();
         };
         fail_fn();
@@ -1444,7 +1444,7 @@
 #define ASSERT_FIND(type)                   \
   {                                         \
     Result<bool> res = find_fn(package_id); \
-    ASSERT_TRUE(res);                       \
+    ASSERT_RESULT_OK(res);                  \
     ASSERT_##type(*res);                    \
   }