8000 CHECK_EQUAL() explodes if actual==NULL · Issue #8 · unittest-cpp/unittest-cpp · GitHub
[go: up one dir, main page]

Skip to content

CHECK_EQUAL() explodes if actual==NULL #8

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

Closed
pjohnmeyer opened this issue Jan 17, 2013 · 0 comments · Fixed by #25
Closed

CHECK_EQUAL() explodes if actual==NULL #8

pjohnmeyer opened this issue Jan 17, 2013 · 0 comments · Fixed by #25
Assignees
Milestone

Comments

@pjohnmeyer
Copy link
Member

Copied from https://sourceforge.net/tracker/?func=detail&aid=1844387&group_id=158151&atid=806684

If the "actual" value passed into CHECK_EQUAL is NULL, std::strcmp() will throw an exception in CheckStringsEqual(). Here's is my simple workaround:

void CheckStringsEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details)
{
  // WAS: if (std::strcmp(expected, actual))
  if (actual == NULL || std::strcmp(expected, actual))
  {
    UnitTest::MemoryOutStream stream;
    // WAS: stream << "Expected " << expected << " but was " << actual;
    stream << "Expected " << expected << " but was " << (actual ? actual : "(null)");
    results.OnTestFailure(details, stream.GetText());
  }
}

There are a few possible patches in the comments of the original bug to consider for incorporation. It should be noted, though, that the test does correctly fail on the CHECK_EQUAL invocation, so I marked this as an enhancement, as opposed to a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0