ref: 22a127332e5fd85ff7e3a92542f057eb87f5fe01
parent: c7d98a8fa331e5331a5c115c915cb5094f504cb4
parent: b6dd41ebc34e09838849acbeda6418e9286409a2
author: Ethan Hugg <[email protected]>
date: Mon Mar 3 02:52:56 EST 2014
Merge pull request #390 from mstorsjo/gtest-strcmp Use gtest functions for comparing hash strings
--- a/test/decode_encode_test.cpp
+++ b/test/decode_encode_test.cpp
@@ -99,7 +99,7 @@
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
- ASSERT_TRUE(CompareHash(digest, p.hashStr));
+ CompareHash(digest, p.hashStr);
}
}
--- a/test/decoder_test.cpp
+++ b/test/decoder_test.cpp
@@ -57,7 +57,7 @@
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
- ASSERT_TRUE(CompareHash(digest, p.hashStr));
+ CompareHash(digest, p.hashStr);
}
}
--- a/test/encoder_test.cpp
+++ b/test/encoder_test.cpp
@@ -58,7 +58,7 @@
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
- ASSERT_TRUE(CompareHash(digest, p.hashStr));
+ CompareHash(digest, p.hashStr);
}
}
--- a/test/utils/HashFunctions.h
+++ b/test/utils/HashFunctions.h
@@ -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__