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