From d668f7749f0e77a3e67fd080cb34f407c64d69ec Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 8 Aug 2007 15:43:05 +0200 Subject: [PATCH 1/2] use NS_TEST_ASSERT macros --- src/core/default-value.cc | 104 ++++++++------------------------------ 1 file changed, 22 insertions(+), 82 deletions(-) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index 9fad9b6b2..0569a2b18 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -341,84 +341,39 @@ DefaultValueTest::DefaultValueTest () bool DefaultValueTest::RunTests (void) { - bool ok = true; + bool result = true; BooleanDefaultValue a ("bool-a", "help a", true); - if (!a.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (a.GetValue ()); Bind ("bool-a", "false"); - if (a.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (!a.GetValue ()); BooleanDefaultValue b ("bool-b", "help b", false); Bind ("bool-b", "true"); - if (!b.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (b.GetValue ()); Bind ("bool-b", "0"); - if (b.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (!b.GetValue ()); Bind ("bool-b", "1"); - if (!b.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (b.GetValue ()); Bind ("bool-b", "f"); - if (b.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (!b.GetValue ()); Bind ("bool-b", "t"); - if (!b.GetValue ()) - { - ok = false; - } + NS_TEST_ASSERT (b.GetValue ()); Bind ("bool-b", "false"); - if (b.GetValue ()) - { - ok = false; - } - if (BindSafe ("bool-b", "tr") != INVALID_VALUE) - { - ok = false; - } + NS_TEST_ASSERT (!b.GetValue ()); + NS_TEST_ASSERT_EQUAL (BindSafe ("bool-b", "tr"), INVALID_VALUE) NumericDefaultValue i ("test-i", "help-i", -1); - if (i.GetValue () != -1) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (i.GetValue (), -1); Bind ("test-i", "-2"); - if (i.GetValue () != -2) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (i.GetValue (), -2); Bind ("test-i", "+2"); - if (i.GetValue () != 2) - { - ok = false; - } - if (i.GetType () != "int32_t(-2147483648:2147483647)") - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (i.GetValue (), 2); + NS_TEST_ASSERT_EQUAL (i.GetType (), "int32_t(-2147483648:2147483647)"); NumericDefaultValue ui32 ("test-ui32", "help-ui32", 10); - if (ui32.GetType () != "uint32_t(0:4294967295)") - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (ui32.GetType (), "uint32_t(0:4294967295)"); NumericDefaultValue c ("test-c", "help-c", 10); - if (c.GetValue () != 10) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (c.GetValue (), 10); Bind ("test-c", "257"); NumericDefaultValue x ("test-x", "help-x", 10.0); NumericDefaultValue y ("test-y", "help-y", 10.0); @@ -429,19 +384,10 @@ DefaultValueTest::RunTests (void) MY_ENUM_A, "A", MY_ENUM_B, "B", 0, (void*)0); - if (e.GetValue () != MY_ENUM_C) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_C); Bind ("test-e", "B"); - if (e.GetValue () != MY_ENUM_B) - { - ok = false; - } - if (BindSafe ("test-e", "D") != INVALID_VALUE) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_B); + NS_TEST_ASSERT_EQUAL (BindSafe ("test-e", "D"), INVALID_VALUE); class MyEnumSubclass : public EnumDefaultValue { @@ -456,15 +402,9 @@ DefaultValueTest::RunTests (void) AddPossibleValue (MY_ENUM_D, "D"); } } e1 ; - if (e1.GetValue () != MY_ENUM_B) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_B); Bind ("test-e1", "D"); - if (e1.GetValue () != MY_ENUM_D) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_D); DefaultValueList::Remove ("test-e1"); DefaultValueList::Remove ("test-e"); @@ -474,7 +414,7 @@ DefaultValueTest::RunTests (void) DefaultValueList::Remove ("test-c"); DefaultValueList::Remove ("test-ui32"); - return ok; + return result; } static DefaultValueTest g_default_value_tests; From f346815b18e9b108031fbf9a72793d93d2f228ee Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 8 Aug 2007 15:59:08 +0200 Subject: [PATCH 2/2] use fixed-width types to avoid portability problems --- src/core/default-value.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index 0569a2b18..c9f2f6db4 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -363,7 +363,7 @@ DefaultValueTest::RunTests (void) NS_TEST_ASSERT (!b.GetValue ()); NS_TEST_ASSERT_EQUAL (BindSafe ("bool-b", "tr"), INVALID_VALUE) - NumericDefaultValue i ("test-i", "help-i", -1); + NumericDefaultValue i ("test-i", "help-i", -1); NS_TEST_ASSERT_EQUAL (i.GetValue (), -1); Bind ("test-i", "-2"); NS_TEST_ASSERT_EQUAL (i.GetValue (), -2); @@ -372,7 +372,7 @@ DefaultValueTest::RunTests (void) NS_TEST_ASSERT_EQUAL (i.GetType (), "int32_t(-2147483648:2147483647)"); NumericDefaultValue ui32 ("test-ui32", "help-ui32", 10); NS_TEST_ASSERT_EQUAL (ui32.GetType (), "uint32_t(0:4294967295)"); - NumericDefaultValue c ("test-c", "help-c", 10); + NumericDefaultValue c ("test-c", "help-c", 10); NS_TEST_ASSERT_EQUAL (c.GetValue (), 10); Bind ("test-c", "257"); NumericDefaultValue x ("test-x", "help-x", 10.0);