blob: 4da45a5f46cd541bf1b75cb494c7d455c138d604 [file] [log] [blame]
Gunnar Mills1ea62e12017-03-27 21:49:16 -05001#include "version_host_software_manager.hpp"
2#include <gtest/gtest.h>
3#include <experimental/filesystem>
4#include <stdlib.h>
5#include <fstream>
6#include <iostream>
7#include <sstream>
8#include <string>
9
10using namespace openpower::software::manager;
11namespace fs = std::experimental::filesystem;
12
13
14class VersionTest : public testing::Test
15{
16 protected:
17
18 virtual void SetUp()
19 {
20 char versionDir[] = "./versionXXXXXX";
21 _directory = mkdtemp(versionDir);
22
23 if (_directory.empty())
24 {
25 throw std::bad_alloc();
26 }
27 }
28
29 virtual void TearDown()
30 {
31 fs::remove_all(_directory);
32 }
33
34 std::string _directory;
35};
36
37/** @brief Make sure we correctly get the version from getVersion()*/
38TEST_F(VersionTest, TestGetVersion)
39{
40 auto tocFilePath = _directory + "/" + "pnor.toc";
41 auto version = "test-version";
42
43 std::ofstream file;
44 file.open(tocFilePath, std::ofstream::out);
45 ASSERT_TRUE(file.is_open());
46
47 file << "version=" << version << std::endl;
48 file.close();
49
50 EXPECT_EQ(Version::getVersion(tocFilePath), version);
51}
52
53/** @brief Make sure we correctly get the Id from getId()*/
54TEST_F(VersionTest, TestGetId)
55{
56 std::stringstream hexId;
57 auto version = "test-id";
58
59 hexId << std::hex << ((std::hash<std::string> {}(
60 version)) & 0xFFFFFFFF);
61
62 EXPECT_EQ(Version::getId(version), hexId.str());
63
64}