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