blob: e27655a7dac936f197b721a424d678e8090aa89d [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);
Adriana Kobylak70dcb632018-02-27 15:46:52 -060017 char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
Gunnar Mills2a6981b2017-10-15 17:05:18 -050018 for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
19 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -060020 snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
Gunnar Mills2a6981b2017-10-15 17:05:18 -050021 }
22 std::string hexId = std::string(mdString);
23 hexId = hexId.substr(0, 8);
24 EXPECT_EQ(Version::getId(version), hexId);
25}