Merge pull request #390 from mstorsjo/gtest-strcmp

Use gtest functions for comparing hash strings
This commit is contained in:
Ethan Hugg 2014-03-03 07:52:56 -08:00
commit 22a127332e
4 changed files with 6 additions and 5 deletions

View File

@ -99,7 +99,7 @@ TEST_P(DecodeEncodeTest, CompareOutput) {
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
ASSERT_TRUE(CompareHash(digest, p.hashStr));
CompareHash(digest, p.hashStr);
}
}

View File

@ -57,7 +57,7 @@ TEST_P(DecoderOutputTest, CompareOutput) {
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
ASSERT_TRUE(CompareHash(digest, p.hashStr));
CompareHash(digest, p.hashStr);
}
}

View File

@ -58,7 +58,7 @@ TEST_P(EncoderOutputTest, CompareOutput) {
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
ASSERT_TRUE(CompareHash(digest, p.hashStr));
CompareHash(digest, p.hashStr);
}
}

View File

@ -3,15 +3,16 @@
#include <stdio.h>
#include <string.h>
#include <gtest/gtest.h>
#include "../sha1.h"
static bool CompareHash(const unsigned char* digest, const char* hashStr) {
static void CompareHash(const unsigned char* digest, const char* hashStr) {
char hashStrCmp[SHA_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < SHA_DIGEST_LENGTH; ++i) {
sprintf(&hashStrCmp[i*2], "%.2x", digest[i]);
}
hashStrCmp[SHA_DIGEST_LENGTH * 2] = '\0';
return strncmp(hashStr, hashStrCmp, SHA_DIGEST_LENGTH * 2) == 0;
EXPECT_STREQ(hashStr, hashStrCmp);
}
#endif //__HASHFUNCTIONS_H__