}
/* Implementation detail of ASSERT_STREQ.
- Compare val_expected and val_actual with strcmp. They ought
- to be non-NULL; fail gracefully if either are NULL. */
+ Compare val1 and val2 with strcmp. They ought
+ to be non-NULL; fail gracefully if either or both are NULL. */
void
assert_streq (const location &loc,
- const char *desc_expected, const char *desc_actual,
- const char *val_expected, const char *val_actual)
+ const char *desc_val1, const char *desc_val2,
+ const char *val1, const char *val2)
{
- /* If val_expected is NULL, the test is buggy. Fail gracefully. */
- if (val_expected == NULL)
- fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=NULL",
- desc_expected, desc_actual);
- /* If val_actual is NULL, fail with a custom error message. */
- if (val_actual == NULL)
- fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL",
- desc_expected, desc_actual, val_expected);
- if (strcmp (val_expected, val_actual) == 0)
- pass (loc, "ASSERT_STREQ");
+ /* If val1 or val2 are NULL, fail with a custom error message. */
+ if (val1 == NULL)
+ if (val2 == NULL)
+ fail_formatted (loc, "ASSERT_STREQ (%s, %s) val1=NULL val2=NULL",
+ desc_val1, desc_val2);
+ else
+ fail_formatted (loc, "ASSERT_STREQ (%s, %s) val1=NULL val2=\"%s\"",
+ desc_val1, desc_val2, val2);
else
- fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"",
- desc_expected, desc_actual, val_expected, val_actual);
+ if (val2 == NULL)
+ fail_formatted (loc, "ASSERT_STREQ (%s, %s) val1=\"%s\" val2=NULL",
+ desc_val1, desc_val2, val1);
+ else
+ {
+ if (strcmp (val1, val2) == 0)
+ pass (loc, "ASSERT_STREQ");
+ else
+ fail_formatted (loc, "ASSERT_STREQ (%s, %s) val1=\"%s\" val2=\"%s\"",
+ desc_val1, desc_val2, val1, val2);
+ }
}
/* Implementation detail of ASSERT_STR_CONTAINS.
/* Implementation detail of ASSERT_STREQ. */
extern void assert_streq (const location &loc,
- const char *desc_expected, const char *desc_actual,
- const char *val_expected, const char *val_actual);
+ const char *desc_val1, const char *desc_val2,
+ const char *val1, const char *val2);
/* Implementation detail of ASSERT_STR_CONTAINS. */
::selftest::pass ((LOC), desc_); \
SELFTEST_END_STMT
-/* Evaluate EXPECTED and ACTUAL and compare them with ==, calling
+/* Evaluate VAL1 and VAL2 and compare them with ==, calling
::selftest::pass if they are equal,
::selftest::fail if they are non-equal. */
-#define ASSERT_EQ(EXPECTED, ACTUAL) \
- ASSERT_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
+#define ASSERT_EQ(VAL1, VAL2) \
+ ASSERT_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
/* Like ASSERT_EQ, but treat LOC as the effective location of the
selftest. */
-#define ASSERT_EQ_AT(LOC, EXPECTED, ACTUAL) \
+#define ASSERT_EQ_AT(LOC, VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- const char *desc_ = "ASSERT_EQ (" #EXPECTED ", " #ACTUAL ")"; \
- if ((EXPECTED) == (ACTUAL)) \
+ const char *desc_ = "ASSERT_EQ (" #VAL1 ", " #VAL2 ")"; \
+ if ((VAL1) == (VAL2)) \
::selftest::pass ((LOC), desc_); \
else \
::selftest::fail ((LOC), desc_); \
SELFTEST_END_STMT
-/* Evaluate EXPECTED and ACTUAL and compare them with known_eq, calling
+/* Evaluate VAL1 and VAL2 and compare them with known_eq, calling
::selftest::pass if they are always equal,
::selftest::fail if they might be non-equal. */
-#define ASSERT_KNOWN_EQ(EXPECTED, ACTUAL) \
- ASSERT_KNOWN_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
+#define ASSERT_KNOWN_EQ(VAL1, VAL2) \
+ ASSERT_KNOWN_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
/* Like ASSERT_KNOWN_EQ, but treat LOC as the effective location of the
selftest. */
-#define ASSERT_KNOWN_EQ_AT(LOC, EXPECTED, ACTUAL) \
+#define ASSERT_KNOWN_EQ_AT(LOC, VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- const char *desc = "ASSERT_KNOWN_EQ (" #EXPECTED ", " #ACTUAL ")"; \
- if (known_eq (EXPECTED, ACTUAL)) \
+ const char *desc = "ASSERT_KNOWN_EQ (" #VAL1 ", " #VAL2 ")"; \
+ if (known_eq (VAL1, VAL2)) \
::selftest::pass ((LOC), desc); \
else \
::selftest::fail ((LOC), desc); \
SELFTEST_END_STMT
-/* Evaluate EXPECTED and ACTUAL and compare them with !=, calling
+/* Evaluate VAL1 and VAL2 and compare them with !=, calling
::selftest::pass if they are non-equal,
::selftest::fail if they are equal. */
-#define ASSERT_NE(EXPECTED, ACTUAL) \
+#define ASSERT_NE(VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- const char *desc_ = "ASSERT_NE (" #EXPECTED ", " #ACTUAL ")"; \
- if ((EXPECTED) != (ACTUAL)) \
+ const char *desc_ = "ASSERT_NE (" #VAL1 ", " #VAL2 ")"; \
+ if ((VAL1) != (VAL2)) \
::selftest::pass (SELFTEST_LOCATION, desc_); \
else \
::selftest::fail (SELFTEST_LOCATION, desc_); \
SELFTEST_END_STMT
-/* Evaluate EXPECTED and ACTUAL and compare them with maybe_ne, calling
+/* Evaluate VAL1 and VAL2 and compare them with maybe_ne, calling
::selftest::pass if they might be non-equal,
::selftest::fail if they are known to be equal. */
-#define ASSERT_MAYBE_NE(EXPECTED, ACTUAL) \
- ASSERT_MAYBE_NE_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
+#define ASSERT_MAYBE_NE(VAL1, VAL2) \
+ ASSERT_MAYBE_NE_AT ((SELFTEST_LOCATION), (VAL1), (VAL2))
/* Like ASSERT_MAYBE_NE, but treat LOC as the effective location of the
selftest. */
-#define ASSERT_MAYBE_NE_AT(LOC, EXPECTED, ACTUAL) \
+#define ASSERT_MAYBE_NE_AT(LOC, VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- const char *desc = "ASSERT_MAYBE_NE (" #EXPECTED ", " #ACTUAL ")"; \
- if (maybe_ne (EXPECTED, ACTUAL)) \
+ const char *desc = "ASSERT_MAYBE_NE (" #VAL1 ", " #VAL2 ")"; \
+ if (maybe_ne (VAL1, VAL2)) \
::selftest::pass ((LOC), desc); \
else \
::selftest::fail ((LOC), desc); \
::selftest::fail ((LOC), desc_); \
SELFTEST_END_STMT
-/* Evaluate EXPECTED and ACTUAL and compare them with strcmp, calling
- ::selftest::pass if they are equal,
- ::selftest::fail if they are non-equal. */
+/* Evaluate VAL1 and VAL2 and compare them with strcmp, calling
+ ::selftest::pass if they are equal (and both are non-NULL),
+ ::selftest::fail if they are non-equal, or are both NULL. */
-#define ASSERT_STREQ(EXPECTED, ACTUAL) \
+#define ASSERT_STREQ(VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- ::selftest::assert_streq (SELFTEST_LOCATION, #EXPECTED, #ACTUAL, \
- (EXPECTED), (ACTUAL)); \
+ ::selftest::assert_streq (SELFTEST_LOCATION, #VAL1, #VAL2, \
+ (VAL1), (VAL2)); \
SELFTEST_END_STMT
/* Like ASSERT_STREQ, but treat LOC as the effective location of the
selftest. */
-#define ASSERT_STREQ_AT(LOC, EXPECTED, ACTUAL) \
+#define ASSERT_STREQ_AT(LOC, VAL1, VAL2) \
SELFTEST_BEGIN_STMT \
- ::selftest::assert_streq ((LOC), #EXPECTED, #ACTUAL, \
- (EXPECTED), (ACTUAL)); \
+ ::selftest::assert_streq ((LOC), #VAL1, #VAL2, \
+ (VAL1), (VAL2)); \
SELFTEST_END_STMT
/* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE