blob: 971416fe0179792dbba099ce17617fd6eb2adfc7 [file] [log] [blame]
John Wang72136232019-11-14 15:33:42 +08001#include <cstring>
John Wangd8702f62019-10-31 10:06:35 +08002#include <vector>
3
4#include "libpldm/utils.h"
5
6#include <gtest/gtest.h>
7
8TEST(Crc32, CheckSumTest)
9{
10 const char* password = "123456789";
11 auto checksum = crc32(password, 9);
12 EXPECT_EQ(checksum, 0xcbf43926);
John Wang72136232019-11-14 15:33:42 +080013}
14
15TEST(Ver2string, Ver2string)
16{
17 ver32_t version{0xf3, 0xf7, 0x10, 0x61};
18 const char* vstr = "3.7.10a";
19 char buffer[1024];
20 auto rc = ver2str(&version, buffer, sizeof(buffer));
21 EXPECT_EQ(rc, std::strlen(vstr));
22 EXPECT_STREQ(vstr, buffer);
23
24 version = {0x10, 0x01, 0xf7, 0x00};
25 vstr = "10.01.7";
26 rc = ver2str(&version, buffer, sizeof(buffer));
27 EXPECT_EQ(rc, std::strlen(vstr));
28 EXPECT_STREQ(vstr, buffer);
29
30 version = {0xf3, 0xf1, 0xff, 0x00};
31 vstr = "3.1";
32 rc = ver2str(&version, buffer, sizeof(buffer));
33 EXPECT_EQ(rc, std::strlen(vstr));
34 EXPECT_STREQ(vstr, buffer);
35
36 version = {0xf1, 0xf0, 0xff, 0x61};
37 vstr = "1.0a";
38 rc = ver2str(&version, buffer, sizeof(buffer));
39 EXPECT_EQ(rc, std::strlen(vstr));
40 EXPECT_STREQ(vstr, buffer);
41
42 rc = ver2str(&version, buffer, 3);
43 EXPECT_EQ(rc, 2);
44 EXPECT_STREQ("1.", buffer);
45
46 rc = ver2str(&version, buffer, 1);
47 EXPECT_EQ(rc, 0);
48
49 rc = ver2str(&version, buffer, 0);
50 EXPECT_EQ(rc, -1);
John Wangd8702f62019-10-31 10:06:35 +080051}