blob: 5fdf50507714b5c5e1070cfba0421d312bbea7e9 [file] [log] [blame]
Adriana Kobylak4772a942018-10-09 15:26:44 -05001#include "msl_verify.hpp"
2
3#include <gtest/gtest.h>
4
5namespace openpower
6{
7namespace software
8{
9namespace image
10{
11
12class MinimumShipLevelTest : public testing::Test
13{
14 protected:
15 std::string minShipLevel = "v.2.2";
16 std::unique_ptr<MinimumShipLevel> minimumShipLevel;
17
18 virtual void SetUp()
19 {
20 minimumShipLevel = std::make_unique<MinimumShipLevel>(minShipLevel);
21 }
22};
23
24TEST_F(MinimumShipLevelTest, compare)
25{
26 MinimumShipLevel::Version min;
27 MinimumShipLevel::Version actual;
28
29 min = {3, 5, 7};
30
31 // actual = min
32 actual = {3, 5, 7};
33 EXPECT_EQ(0, minimumShipLevel->compare(actual, min));
34
35 // actual < min
36 actual = {3, 5, 6};
37 EXPECT_EQ(-1, minimumShipLevel->compare(actual, min));
38 actual = {3, 4, 7};
39 EXPECT_EQ(-1, minimumShipLevel->compare(actual, min));
40 actual = {2, 5, 7};
41 EXPECT_EQ(-1, minimumShipLevel->compare(actual, min));
42
43 // actual > min
44 actual = {3, 5, 8};
45 EXPECT_EQ(1, minimumShipLevel->compare(actual, min));
46 actual = {3, 6, 7};
47 EXPECT_EQ(1, minimumShipLevel->compare(actual, min));
48 actual = {4, 5, 7};
49 EXPECT_EQ(1, minimumShipLevel->compare(actual, min));
50}
51
52TEST_F(MinimumShipLevelTest, parse)
53{
54 MinimumShipLevel::Version version;
55 std::string versionStr;
56
57 versionStr = "nomatch-1.2.3-abc";
58 minimumShipLevel->parse(versionStr, version);
59 EXPECT_EQ(0, version.major);
60 EXPECT_EQ(0, version.minor);
61 EXPECT_EQ(0, version.rev);
62
63 versionStr = "xyzformat-v1.2.3-4.5abc";
64 minimumShipLevel->parse(versionStr, version);
65 EXPECT_EQ(1, version.major);
66 EXPECT_EQ(2, version.minor);
67 EXPECT_EQ(3, version.rev);
68
69 versionStr = "xyformat-system-v6.7-abc";
70 minimumShipLevel->parse(versionStr, version);
71 EXPECT_EQ(6, version.major);
72 EXPECT_EQ(7, version.minor);
73 EXPECT_EQ(0, version.rev);
74}
75
76} // namespace image
77} // namespace software
78} // namespace openpower