blob: a4de09c462aa182a791ba33bb9a5334e04356a4b [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);
John Wangb41a57d2019-09-16 15:40:21 +080074
75 versionStr = "Vendor-Model-v-4.1.01";
76 minimumShipLevel->parse(versionStr, version);
77 EXPECT_EQ(4, version.major);
78 EXPECT_EQ(1, version.minor);
79 EXPECT_EQ(1, version.rev);
80
81 versionStr = "Vendor-Model-v-4.1-abc";
82 minimumShipLevel->parse(versionStr, version);
83 EXPECT_EQ(4, version.major);
84 EXPECT_EQ(1, version.minor);
85 EXPECT_EQ(0, version.rev);
Adriana Kobylak4772a942018-10-09 15:26:44 -050086}
87
88} // namespace image
89} // namespace software
90} // namespace openpower