Don't highlight excess when comparing unequal length strings.
Clean up the NULL / empty string display.
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3514)
| !TEST(0, TEST_str_eq("\1\2\3\4\5", "\1x\3\6\5"))
| !TEST(0, TEST_str_ne("abc", buf))
| !TEST(1, TEST_str_ne("abc", NULL))
| !TEST(0, TEST_str_eq("\1\2\3\4\5", "\1x\3\6\5"))
| !TEST(0, TEST_str_ne("abc", buf))
| !TEST(1, TEST_str_ne("abc", NULL))
- | !TEST(1, TEST_str_ne(NULL, buf)))
+ | !TEST(1, TEST_str_ne(NULL, buf))
+ | !TEST(0, TEST_str_eq("abcdef", "abcdefghijk")))
+static void test_string_null_empty(const char *m, int indent, char c)
+{
+ if (m == NULL)
+ test_printf_stderr("%*s# % 4s %c NULL\n", indent, "", "", c);
+ else
+ test_printf_stderr("%*s# % 4u:%c ''\n", indent, "", 0u, c);
+}
+
static void test_fail_string_message(const char *prefix, const char *file,
int line, const char *type,
const char *left, const char *right,
static void test_fail_string_message(const char *prefix, const char *file,
int line, const char *type,
const char *left, const char *right,
l2 = 0;
if (l1 == 0 && l2 == 0) {
if ((m1 == NULL) == (m2 == NULL)) {
l2 = 0;
if (l1 == 0 && l2 == 0) {
if ((m1 == NULL) == (m2 == NULL)) {
- test_printf_stderr("%*s# % 4s %s\n", indent, "", "",
- m1 == NULL ? "NULL" : "''");
+ test_string_null_empty(m1, indent, ' ');
} else {
test_diff_header(left, right);
} else {
test_diff_header(left, right);
- test_printf_stderr("%*s# % 4s - %s\n", indent, "", "",
- m1 == NULL ? "NULL" : "''");
- test_printf_stderr("%*s# % 4s + %s\n", indent, "", "",
- m2 == NULL ? "NULL" : "''");
+ test_string_null_empty(m1, indent, '-');
+ test_string_null_empty(m2, indent, '+');
for (i = 0; i < n2; i++)
b2[i] = isprint(m2[i]) ? m2[i] : '.';
}
for (i = 0; i < n2; i++)
b2[i] = isprint(m2[i]) ? m2[i] : '.';
}
i = 0;
if (n1 > 0 && n2 > 0) {
const size_t j = n1 < n2 ? n1 : n2;
i = 0;
if (n1 > 0 && n2 > 0) {
const size_t j = n1 < n2 ? n1 : n2;
- const size_t k = n1 > n2 ? n1 : n2;
for (; i < j; i++)
if (m1[i] == m2[i]) {
for (; i < j; i++)
if (m1[i] == m2[i]) {
bdiff[i] = '^';
diff = 1;
}
bdiff[i] = '^';
diff = 1;
}
- for (; i < k; i++)
- bdiff[i] = '^';
- if (!diff) {
- test_printf_stderr("%*s# % 4u: '%s'\n", indent, "", cnt, b1);
+ if (n1 == n2 && !diff) {
+ test_printf_stderr("%*s# % 4u: '%s'\n", indent, "", cnt,
+ n2 > n1 ? b2 : b1);
- if (cnt == 0 && m1 == NULL)
- test_printf_stderr("%*s# % 4s - NULL\n", indent, "", "");
- else if (cnt == 0 && *m1 == '\0')
- test_printf_stderr("%*s# % 4s - ''\n", indent, "", "");
+ if (cnt == 0 && (m1 == NULL || *m1 == '\0'))
+ test_string_null_empty(m1, indent, '-');
else if (n1 > 0)
test_printf_stderr("%*s# % 4u:- '%s'\n", indent, "", cnt, b1);
else if (n1 > 0)
test_printf_stderr("%*s# % 4u:- '%s'\n", indent, "", cnt, b1);
- if (cnt == 0 && m2 == NULL)
- test_printf_stderr("%*s# % 4s + NULL\n", indent, "", "");
- else if (cnt == 0 && *m2 == '\0')
- test_printf_stderr("%*s# % 4s + ''\n", indent, "", "");
+ if (cnt == 0 && (m2 == NULL || *m2 == '\0'))
+ test_string_null_empty(m2, indent, '+');
else if (n2 > 0)
test_printf_stderr("%*s# % 4u:+ '%s'\n", indent, "", cnt, b2);
else if (n2 > 0)
test_printf_stderr("%*s# % 4u:+ '%s'\n", indent, "", cnt, b2);
test_printf_stderr("%*s# % 4s %s\n", indent, "", "", bdiff);
}
m1 += n1;
test_printf_stderr("%*s# % 4s %s\n", indent, "", "", bdiff);
}
m1 += n1;