diff options
author | Gunnar Mills <gmills@us.ibm.com> | 2017-10-15 17:05:18 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-10-25 00:34:18 +0000 |
commit | 2a6981b9e2e2d5612d51279519c885e7fd42681b (patch) | |
tree | 4488cf3497edc42d17ce9f755bbec58f474d2dd3 | |
parent | 850d5f6b4c01a7e6e3bc93fe4b840d60755d8952 (diff) | |
download | openpower-pnor-code-mgmt-2a6981b9e2e2d5612d51279519c885e7fd42681b.tar.gz openpower-pnor-code-mgmt-2a6981b9e2e2d5612d51279519c885e7fd42681b.zip |
Add Test for getId()
Added a unit test for Version::getId().
A similar test is already in phosphor-bmc-code-mgmt.
Change-Id: I8ead5111017356c6a7063b6e31bee10fada78ade
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
-rwxr-xr-x | test/Makefile.am | 24 | ||||
-rw-r--r-- | test/utest.cpp | 24 |
2 files changed, 44 insertions, 4 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index e2caf4ba6..4f78144c6 100755 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -7,9 +7,25 @@ check_PROGRAMS = utest TESTS = $(check_PROGRAMS) # Build/add utest to test suite -utest_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -utest_CXXFLAGS = $(PTHREAD_CFLAGS) $(PHOSPHOR_LOGGING_CFLAGS) -utest_LDFLAGS = -lgtest_main -lgtest $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS) \ - $(PHOSPHOR_LOGGING_LIBS) +utest_CPPFLAGS = \ + -Igtest \ + $(GTEST_CPPFLAGS) \ + $(AM_CPPFLAGS) + +utest_CXXFLAGS = \ + $(PTHREAD_CFLAGS) \ + $(PHOSPHOR_LOGGING_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) + +utest_LDFLAGS = \ + -lgtest_main \ + -lgtest \ + $(PTHREAD_LIBS) \ + $(OESDK_TESTCASE_FLAGS) \ + $(PHOSPHOR_LOGGING_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + -lssl \ + -lcrypto utest_SOURCES = utest.cpp +utest_LDADD = $(top_builddir)/openpower_update_manager-version.o diff --git a/test/utest.cpp b/test/utest.cpp index 21805333f..7ce738eff 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -1 +1,25 @@ #include <gtest/gtest.h> +#include <openssl/sha.h> +#include <string> +#include "version.hpp" + +using namespace openpower::software::updater; + +/** @brief Make sure we correctly get the Id from getId()*/ +TEST(VersionTest, TestGetId) +{ + auto version = "test-id"; + unsigned char digest[SHA512_DIGEST_LENGTH]; + SHA512_CTX ctx; + SHA512_Init(&ctx); + SHA512_Update(&ctx, version, strlen(version)); + SHA512_Final(digest, &ctx); + char mdString[SHA512_DIGEST_LENGTH*2+1]; + for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) + { + snprintf(&mdString[i*2], 3, "%02x", (unsigned int)digest[i]); + } + std::string hexId = std::string(mdString); + hexId = hexId.substr(0, 8); + EXPECT_EQ(Version::getId(version), hexId); +} |