blob: 7ce738eff7f4d9938f7dd54c61b4b124c9249015 [file] [log] [blame]
Gunnar Mills1ea62e12017-03-27 21:49:16 -05001#include <gtest/gtest.h>
Gunnar Mills2a6981b2017-10-15 17:05:18 -05002#include <openssl/sha.h>
3#include <string>
4#include "version.hpp"
5
6using namespace openpower::software::updater;
7
8/** @brief Make sure we correctly get the Id from getId()*/
9TEST(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}