String Assertions 🔗

Compare strings.

Assert Macros 🔗

Assert macros fail and abort the test case.

#define ASSERT_STR_EQ(
X, Y, ...)

Check two strings to determine if X == Y.

#define ASSERT_STR_NE(
X, Y, ...)

Check two strings to determine if X != Y.

#define ASSERT_STR_LT(
X, Y, ...)

Check two strings to determine if X < Y.

X, Y, ...)

Check two strings to determine if X <= Y.

#define ASSERT_STR_GT(
X, Y, ...)

Check two strings to determine if X > Y.

X, Y, ...)

Check two strings to determine if X >= Y.

Expect Macros 🔗

Expect macros fail but do not abort the test case.

#define EXPECT_STR_EQ(
X, Y, ...)

Check two strings to determine if X == Y.

#define EXPECT_STR_NE(
X, Y, ...)

Check two strings to determine if X != Y.

#define EXPECT_STR_LT(
X, Y, ...)

Check two strings to determine if X < Y.

X, Y, ...)

Check two strings to determine if X <= Y.

#define EXPECT_STR_GT(
X, Y, ...)

Check two strings to determine if X > Y.

X, Y, ...)

Check two strings to determine if X >= Y.

Discussion 🔗

Null-terminated C strings are compared with the special string assertion macros defined by this module. These macros can compare strings with character type char, char8_t, char16_t, and char32_t.

All string assertion macros accept two Unicode encoded strings and performs a binary comparison between them. With a binary comparison the code points are compared. If a mismatching pair of code points is encountered, then their lexicographical distance is computed. The result is checked against the relational operation the assertion macro represents.

Strings must be well-formed; they cannot contain malformed code point sequences. An example of a malformed sequence would be a truncated code point sequence in a UTF-8 encoded string. If Audition encounters a malformed encoded string, then the assertion immediately fails with an error that indicates the index of the malformed code unit.

In situations where malformed strings or strings encoded with an encoding other than ASCII or Unicode must be compared, then users should rely on the memory assertion macros or perform a manual test and call ABORT or FAIL. These techniques are demonstrated in the subsequent example:

ASSERT_MEM_EQ("foo", "bar", 3, 3);

// or

ASSERT_TRUE(strcmp("foo","bar") == 0);

// or

if (strcmp("foo","bar") == 0) {
    ABORT("strings not equal");
}

Audition does not perform Unicode normalization. Strings are compared for binary equivalence only. Computing the normalization form (if desired) is the callers responsibility.