rewrite Object tests with test.h macros
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 12 Aug 2007 18:43:15 +0200
changeset 1349 11562f6b73aa
parent 1348 b77625f55e90
child 1350 7088f670a858
rewrite Object tests with test.h macros
src/core/object.cc
--- a/src/core/object.cc	Sun Aug 12 18:37:38 2007 +0200
+++ b/src/core/object.cc	Sun Aug 12 18:43:15 2007 +0200
@@ -368,112 +368,43 @@
 bool 
 ObjectTest::RunTests (void)
 {
-  bool ok = true;
+  bool result = true;
 
   Ptr<BaseA> baseA = Create<BaseA> ();
-  if (baseA->QueryInterface<BaseA> (BaseA::iid) != baseA)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<BaseA> (DerivedA::iid) != 0)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<DerivedA> (DerivedA::iid) != 0)
-    {
-      ok = false;
-    }
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<BaseA> (BaseA::iid), baseA);
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<BaseA> (DerivedA::iid), 0);
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<DerivedA> (DerivedA::iid), 0);
   baseA = Create<DerivedA> (10);
-  if (baseA->QueryInterface<BaseA> (BaseA::iid) != baseA)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<BaseA> (DerivedA::iid) != baseA)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<DerivedA> (DerivedA::iid) == 0)
-    {
-      ok = false;
-    }
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<BaseA> (BaseA::iid), baseA);
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<BaseA> (DerivedA::iid), baseA);
+  NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface<DerivedA> (DerivedA::iid), 0);
 
   baseA = Create<BaseA> ();
   Ptr<BaseB> baseB = Create<BaseB> ();
   Ptr<BaseB> baseBCopy = baseB;
   baseA->AddInterface (baseB);
-  if (baseA->QueryInterface<BaseA> (BaseA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<DerivedA> (DerivedA::iid) != 0)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<BaseB> (BaseB::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<DerivedB> (DerivedB::iid) != 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<BaseB> (BaseB::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<DerivedB> (DerivedB::iid) != 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<BaseA> (BaseA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<DerivedA> (DerivedA::iid) != 0)
-    {
-      ok = false;
-    }
-  if (baseBCopy->QueryInterface<BaseA> (BaseA::iid) == 0)
-    {
-      ok = false;
-    }
+  NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface<BaseA> (BaseA::iid), 0);
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<DerivedA> (DerivedA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface<BaseB> (BaseB::iid), 0);
+  NS_TEST_ASSERT_EQUAL (baseA->QueryInterface<DerivedB> (DerivedB::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<BaseB> (BaseB::iid), 0);
+  NS_TEST_ASSERT_EQUAL (baseB->QueryInterface<DerivedB> (DerivedB::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<BaseA> (BaseA::iid), 0);
+  NS_TEST_ASSERT_EQUAL (baseB->QueryInterface<DerivedA> (DerivedA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface<BaseA> (BaseA::iid), 0);
 
   baseA = Create<DerivedA> (1);
   baseB = Create<DerivedB> (1);
   baseBCopy = baseB;
   baseA->AddInterface (baseB);
-  if (baseA->QueryInterface<DerivedB> (DerivedB::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseA->QueryInterface<BaseB> (BaseB::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<DerivedA> (DerivedA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<BaseA> (BaseA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseBCopy->QueryInterface<DerivedA> (DerivedA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseBCopy->QueryInterface<BaseA> (BaseA::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<DerivedB> (DerivedB::iid) == 0)
-    {
-      ok = false;
-    }
-  if (baseB->QueryInterface<BaseB> (BaseB::iid) == 0)
-    {
-      ok = false;
-    }
+  NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface<DerivedB> (DerivedB::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface<BaseB> (BaseB::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<DerivedA> (DerivedA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<BaseA> (BaseA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface<DerivedA> (DerivedA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface<BaseA> (BaseA::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<DerivedB> (DerivedB::iid), 0);
+  NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface<BaseB> (BaseB::iid), 0)
 
   baseA = Create<BaseA> ();
   baseB = Create<BaseB> ();
@@ -481,7 +412,7 @@
   baseA = 0;
   baseA = baseB->QueryInterface<BaseA> (BaseA::iid);
 
-  return ok;
+  return result;
 }
 
 static ObjectTest g_interfaceObjectTests;