Gunnar Mills | 1ea62e1 | 2017-03-27 21:49:16 -0500 | [diff] [blame] | 1 | #include <gtest/gtest.h> |
Gunnar Mills | 2a6981b | 2017-10-15 17:05:18 -0500 | [diff] [blame] | 2 | #include <openssl/sha.h> |
| 3 | #include <string> |
| 4 | #include "version.hpp" |
| 5 | |
| 6 | using namespace openpower::software::updater; |
| 7 | |
| 8 | /** @brief Make sure we correctly get the Id from getId()*/ |
| 9 | TEST(VersionTest, TestGetId) |
| 10 | { |
| 11 | auto version = "test-id"; |
| 12 | unsigned char digest[SHA512_DIGEST_LENGTH]; |
| 13 | SHA512_CTX ctx; |
| 14 | SHA512_Init(&ctx); |
| 15 | SHA512_Update(&ctx, version, strlen(version)); |
| 16 | SHA512_Final(digest, &ctx); |
| 17 | char mdString[SHA512_DIGEST_LENGTH*2+1]; |
| 18 | for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) |
| 19 | { |
| 20 | snprintf(&mdString[i*2], 3, "%02x", (unsigned int)digest[i]); |
| 21 | } |
| 22 | std::string hexId = std::string(mdString); |
| 23 | hexId = hexId.substr(0, 8); |
| 24 | EXPECT_EQ(Version::getId(version), hexId); |
| 25 | } |