test: Add TEST_STR_NEQ

TEST_STR_NES can be used to check the returned string is not what it
shouldn't be.

BUG=none
BRANCH=tot
TEST=make runtests

Change-Id: I09d5a63334e9b8365a44bb96ed31db8155d95e21
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/343120
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Daisuke Nojiri
2016-05-06 13:53:32 -07:00
committed by chrome-bot
parent 85dbb34420
commit 111c59b567
2 changed files with 25 additions and 0 deletions

View File

@@ -93,6 +93,26 @@ int TEST_STR_EQ(const char* result, const char* expected_result,
}
int TEST_STR_NEQ(const char* result, const char* not_expected,
const char* testname) {
if (!result || !not_expected) {
fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname);
fprintf(stderr, " String compare with NULL\n");
gTestSuccess = 0;
return 0;
} else if (strcmp(result, not_expected)) {
fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname);
return 1;
} else {
fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname);
fprintf(stderr, " Didn't expect: \"%s\", but got it\n", not_expected);
gTestSuccess = 0;
return 0;
}
}
int TEST_SUCC(int result, const char* testname) {
if (result == 0) {
fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname);

View File

@@ -34,6 +34,11 @@ int TEST_PTR_NEQ(const void* result, const void* expected_result,
int TEST_STR_EQ(const char* result, const char* expected_result,
const char* testname);
/* Return 1 if result string is not equal to not_expected_result string,
* else return 0. Also update the global gTestSuccess flag if test fails. */
int TEST_STR_NEQ(const char* result, const char* not_expected_result,
const char* testname);
/* Return 1 if the result is true, else return 0.
* Also update the global gTestSuccess flag if test fails. */
int TEST_TRUE(int result, const char* testname);