From 1413ea409d9ced6ac66c4b5ba4ab220f06effbe6 Mon Sep 17 00:00:00 2001 From: g1n93r Date: Wed, 31 Mar 2021 13:26:36 -0400 Subject: [PATCH 1/2] Added string compare test using strstr funciton --- ctest.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ctest.h b/ctest.h index b1b52fa..d88e38c 100644 --- a/ctest.h +++ b/ctest.h @@ -179,6 +179,12 @@ void assert_str(const char* exp, const char* real, const char* caller, int line) void assert_wstr(const wchar_t *exp, const wchar_t *real, const char* caller, int line); #define ASSERT_WSTR(exp, real) assert_wstr(exp, real, __FILE__, __LINE__) +void assert_strstr(const char* haystack, const char* needle, const char* caller, int line); +#define ASSERT_STRSTR(haystack, needle) assert_strstr(haystack, needle, __FILE__, __LINE__) + +void assert_not_strstr(const char* haystack, const char* needle, const char* caller, int line); +#define ASSERT_NOT_STRSTR(haystack, needle) assert_not_strstr(haystack, needle, __FILE__, __LINE__) + void assert_data(const unsigned char* exp, size_t expsize, const unsigned char* real, size_t realsize, const char* caller, int line); @@ -348,6 +354,24 @@ void assert_wstr(const wchar_t *exp, const wchar_t *real, const char* caller, in } } +void assert_strstr(const char* haystack, const char* needle, const char* caller, int line) +{ + if ((haystack == NULL && needle != NULL) || + (haystack != NULL && needle == NULL) || + (haystack && needle && strstr(haystack, needle) == NULL)) { + CTEST_ERR("%s:%d '%s', doesn't cointain '%s'", caller, line, haystack, needle); + } +} + +void assert_not_strstr(const char* haystack, const char* needle, const char* caller, int line) +{ + if ((haystack == NULL && needle != NULL) || + (haystack != NULL && needle == NULL) || + (haystack && needle && strstr(haystack, needle) != NULL)) { + CTEST_ERR("%s:%d '%s', does cointain '%s'", caller, line, haystack, needle); + } +} + void assert_data(const unsigned char* exp, size_t expsize, const unsigned char* real, size_t realsize, const char* caller, int line) { From 431f98bd4e6c3a4f4568c7f53151f0dff7aa0320 Mon Sep 17 00:00:00 2001 From: g1n93r Date: Thu, 1 Apr 2021 14:42:55 -0400 Subject: [PATCH 2/2] Fixed null rules for both assert_strstr and assert_not_strstr --- ctest.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ctest.h b/ctest.h index d88e38c..14d7e50 100644 --- a/ctest.h +++ b/ctest.h @@ -356,19 +356,16 @@ void assert_wstr(const wchar_t *exp, const wchar_t *real, const char* caller, in void assert_strstr(const char* haystack, const char* needle, const char* caller, int line) { - if ((haystack == NULL && needle != NULL) || - (haystack != NULL && needle == NULL) || + if ((haystack == NULL) || (needle == NULL) || (haystack && needle && strstr(haystack, needle) == NULL)) { - CTEST_ERR("%s:%d '%s', doesn't cointain '%s'", caller, line, haystack, needle); + CTEST_ERR("%s:%d '%s', doesn't contain '%s'", caller, line, haystack, needle); } } void assert_not_strstr(const char* haystack, const char* needle, const char* caller, int line) { - if ((haystack == NULL && needle != NULL) || - (haystack != NULL && needle == NULL) || - (haystack && needle && strstr(haystack, needle) != NULL)) { - CTEST_ERR("%s:%d '%s', does cointain '%s'", caller, line, haystack, needle); + if ((haystack != NULL) && (needle != NULL) && (strstr(haystack, needle) != NULL)) { + CTEST_ERR("%s:%d '%s', does contain '%s'", caller, line, haystack, needle); } }