[test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)

This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
This commit is contained in:
Abtin Keshavarzian
2021-06-28 11:38:10 -07:00
committed by GitHub
parent 2db3ddca33
commit 57d072d352
36 changed files with 1733 additions and 1864 deletions
+8 -8
View File
@@ -192,16 +192,16 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons
// Verify that when iterator is done, it points to `nullptr`.
VerifyOrQuit(iter.GetChild() == nullptr, "iterator GetChild() failed");
VerifyOrQuit(iter.GetChild() == nullptr);
iter++;
VerifyOrQuit(iter.IsDone(), "iterator Advance() (after iterator is done) failed");
VerifyOrQuit(iter.GetChild() == nullptr, "iterator GetChild() failed");
VerifyOrQuit(iter.GetChild() == nullptr);
// Verify that the number of children matches the number of entries we get from iterator.
VerifyOrQuit(aTable.GetNumChildren(filter) == numChildren, "GetNumChildren() failed");
VerifyOrQuit(aTable.HasChildren(filter) == (numChildren != 0), "HasChildren() failed");
VerifyOrQuit(aTable.GetNumChildren(filter) == numChildren);
VerifyOrQuit(aTable.HasChildren(filter) == (numChildren != 0));
// Verify that there is no missing or extra entry between the expected list
// and what was observed/returned by the iterator.
@@ -298,7 +298,7 @@ void TestChildTable(void)
Error error;
sInstance = testInitInstance();
VerifyOrQuit(sInstance != nullptr, "Null instance");
VerifyOrQuit(sInstance != nullptr);
table = &sInstance->Get<ChildTable>();
@@ -310,8 +310,8 @@ void TestChildTable(void)
for (Child::StateFilter filter : kAllFilters)
{
VerifyOrQuit(table->HasChildren(filter) == false, "HasChildren() failed after init");
VerifyOrQuit(table->GetNumChildren(filter) == 0, "GetNumChildren() failed after init");
VerifyOrQuit(table->HasChildren(filter) == false);
VerifyOrQuit(table->GetNumChildren(filter) == 0);
}
printf(" -- PASS\n");
@@ -375,7 +375,7 @@ void TestChildTable(void)
error = table->SetMaxChildrenAllowed(testNumAllowedChildren);
VerifyOrQuit(error == kErrorNone, "SetMaxChildrenAllowed() failed");
VerifyOrQuit(table->GetMaxChildrenAllowed() == testNumAllowedChildren, "GetMaxChildrenAllowed() failed");
VerifyOrQuit(table->GetMaxChildrenAllowed() == testNumAllowedChildren);
for (uint16_t num = 0; num < testNumAllowedChildren; num++)
{