Browse Source

[2094] use xxx_EQ() instead of FAIL().

this makes the code more concise.  also add comments on why we use ASSERT
for one of the tests.
JINMEI Tatuya 12 years ago
parent
commit
3df27b54fa
1 changed files with 10 additions and 11 deletions
  1. 10 11
      src/lib/util/unittests/wiredata.cc

+ 10 - 11
src/lib/util/unittests/wiredata.cc

@@ -34,18 +34,17 @@ matchWireData(const void* expected_data, size_t expected_len,
     for (size_t i = 0; i < cmplen; ++i) {
         const int ebyte = static_cast<const uint8_t*>(expected_data)[i];
         const int abyte = static_cast<const uint8_t*>(actual_data)[i];
-        if (ebyte != abyte) {
-            FAIL() << "Wire data mismatch at " << i << "th byte\n"
-                   << "  Actual: " << abyte << "\n"
-                   << "Expected: " << ebyte << "\n";
-            return;
-        }
-    }
-    if (expected_len != actual_len) {
-        FAIL() << "Wire data mismatch in length:\n"
-               << "  Actual: " << actual_len << "\n"
-               << "Expected: " << expected_len << "\n";
+        // Once we find a mismatch, it's quite likely that there will be many
+        // mismatches after this point.  So we stop here by using ASSERT not
+        // to be too noisy.
+        ASSERT_EQ(ebyte, abyte) << "Wire data mismatch at " << i << "th byte\n"
+                                << "  Actual: " << abyte << "\n"
+                                << "Expected: " << ebyte << "\n";
     }
+    EXPECT_EQ(expected_len, actual_len)
+        << "Wire data mismatch in length:\n"
+        << "  Actual: " << actual_len << "\n"
+        << "Expected: " << expected_len << "\n";
 }
 
 } // unittests