1 #include "async_resp.hpp"
2 #include "manager_logservices_journal.hpp"
3 
4 #include <systemd/sd-id128.h>
5 
6 #include <cstdint>
7 #include <format>
8 #include <memory>
9 #include <string>
10 
11 #include <gtest/gtest.h>
12 
13 namespace redfish
14 {
15 namespace
16 {
17 
TEST(LogServicesBMCJouralTest,LogServicesBMCJouralGetReturnsError)18 TEST(LogServicesBMCJouralTest, LogServicesBMCJouralGetReturnsError)
19 {
20     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
21     sd_id128_t bootIDOut{};
22     uint64_t timestampOut = 0;
23     uint64_t indexOut = 0;
24     uint64_t timestampIn = 1740970301UL;
25     std::string badBootIDStr = "78770392794344a29f81507f3ce5e";
26     std::string goodBootIDStr = "78770392794344a29f81507f3ce5e78c";
27     sd_id128_t goodBootID{};
28 
29     // invalid test cases
30     EXPECT_FALSE(getTimestampFromID(shareAsyncResp, "", bootIDOut, timestampOut,
31                                     indexOut));
32     EXPECT_FALSE(getTimestampFromID(shareAsyncResp, badBootIDStr, bootIDOut,
33                                     timestampOut, indexOut));
34     EXPECT_FALSE(getTimestampFromID(
35         shareAsyncResp, std::format("{}_{}", badBootIDStr, timestampIn),
36         bootIDOut, timestampOut, indexOut));
37     EXPECT_FALSE(getTimestampFromID(
38         shareAsyncResp, std::format("{}_{}", badBootIDStr, timestampIn),
39         bootIDOut, timestampOut, indexOut));
40 
41     // obtain a goodBootID
42     EXPECT_GE(sd_id128_from_string(goodBootIDStr.c_str(), &goodBootID), 0);
43 
44     EXPECT_FALSE(getTimestampFromID(
45         shareAsyncResp, std::format("{}_{}", goodBootIDStr, "InvalidNum"),
46         bootIDOut, timestampOut, indexOut));
47 
48     // Success cases
49     EXPECT_TRUE(getTimestampFromID(
50         shareAsyncResp, std::format("{}_{}", goodBootIDStr, timestampIn),
51         bootIDOut, timestampOut, indexOut));
52     EXPECT_NE(sd_id128_equal(goodBootID, bootIDOut), 0);
53     EXPECT_EQ(timestampIn, timestampOut);
54     EXPECT_EQ(indexOut, 0);
55 
56     // Index of _1 is invalid. First index is omitted
57     EXPECT_FALSE(getTimestampFromID(
58         shareAsyncResp, std::format("{}_{}_1", goodBootIDStr, timestampIn),
59         bootIDOut, timestampOut, indexOut));
60 
61     // Index of _2 is valid, and should return a zero index (1)
62     EXPECT_TRUE(getTimestampFromID(
63         shareAsyncResp, std::format("{}_{}_2", goodBootIDStr, timestampIn),
64         bootIDOut, timestampOut, indexOut));
65     EXPECT_NE(sd_id128_equal(goodBootID, bootIDOut), 0);
66     EXPECT_EQ(timestampIn, timestampOut);
67     EXPECT_EQ(indexOut, 1);
68 }
69 
70 } // namespace
71 } // namespace redfish
72