Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added string compare test utility #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -348,6 +354,21 @@ 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 && needle && strstr(haystack, needle) == NULL)) {
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) && (strstr(haystack, needle) != NULL)) {
CTEST_ERR("%s:%d '%s', does contain '%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) {
Expand Down