Improve tests for InterfaceController add/remove address methods

Currently the tests for InterfaceController add/remove address
methods check that invalid IP addresses cause failures, but do
not check the actual error message returned. Fix this.

Test: test passes on topic
Change-Id: I9a2691dcb61179624956ba9bbee2e0298b440f0f
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index 7be8e55..5474654 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -797,35 +797,39 @@
     static const struct TestData {
         const char *addrString;
         const int   prefixLength;
-        const bool  expectSuccess;
+        const int expectAddResult;
+        const int expectRemoveResult;
     } kTestData[] = {
-        { "192.0.2.1", 24, true },
-        { "192.0.2.2", 25, true },
-        { "192.0.2.3", 32, true },
-        { "192.0.2.4", 33, false },
-        { "192.not.an.ip", 24, false },
-        { "2001:db8::1", 64, true },
-        { "2001:db8::2", 65, true },
-        { "2001:db8::3", 128, true },
-        { "2001:db8::4", 129, false },
-        { "foo:bar::bad", 64, false },
+            {"192.0.2.1", 24, 0, 0},
+            {"192.0.2.2", 25, 0, 0},
+            {"192.0.2.3", 32, 0, 0},
+            {"192.0.2.4", 33, EINVAL, EADDRNOTAVAIL},
+            {"192.not.an.ip", 24, EINVAL, EINVAL},
+            {"2001:db8::1", 64, 0, 0},
+            {"2001:db8::2", 65, 0, 0},
+            {"2001:db8::3", 128, 0, 0},
+            {"2001:db8::4", 129, EINVAL, EINVAL},
+            {"foo:bar::bad", 64, EINVAL, EINVAL},
+            {"2001:db8::1/64", 64, EINVAL, EINVAL},
     };
 
     for (size_t i = 0; i < std::size(kTestData); i++) {
         const auto &td = kTestData[i];
 
+        SCOPED_TRACE(String8::format("Offending IP address %s/%d", td.addrString, td.prefixLength));
+
         // [1.a] Add the address.
         binder::Status status = mNetd->interfaceAddAddress(
                 sTun.name(), td.addrString, td.prefixLength);
-        if (td.expectSuccess) {
+        if (td.expectAddResult == 0) {
             EXPECT_TRUE(status.isOk()) << status.exceptionMessage();
         } else {
             ASSERT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode());
-            ASSERT_NE(0, status.serviceSpecificErrorCode());
+            ASSERT_EQ(td.expectAddResult, status.serviceSpecificErrorCode());
         }
 
         // [1.b] Verify the addition meets the expectation.
-        if (td.expectSuccess) {
+        if (td.expectAddResult == 0) {
             EXPECT_TRUE(interfaceHasAddress(sTun.name(), td.addrString, td.prefixLength));
         } else {
             EXPECT_FALSE(interfaceHasAddress(sTun.name(), td.addrString, -1));
@@ -833,11 +837,11 @@
 
         // [2.a] Try to remove the address.  If it was not previously added, removing it fails.
         status = mNetd->interfaceDelAddress(sTun.name(), td.addrString, td.prefixLength);
-        if (td.expectSuccess) {
+        if (td.expectRemoveResult == 0) {
             EXPECT_TRUE(status.isOk()) << status.exceptionMessage();
         } else {
             ASSERT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode());
-            ASSERT_NE(0, status.serviceSpecificErrorCode());
+            ASSERT_EQ(td.expectRemoveResult, status.serviceSpecificErrorCode());
         }
 
         // [2.b] No matter what, the address should not be present.