1 #include "async_resp.hpp" 2 #include "log_services.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 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 uint64_t indexIn = 1; 57 EXPECT_TRUE(getTimestampFromID( 58 shareAsyncResp, 59 std::format("{}_{}_{}", goodBootIDStr, timestampIn, indexIn), bootIDOut, 60 timestampOut, indexOut)); 61 EXPECT_NE(sd_id128_equal(goodBootID, bootIDOut), 0); 62 EXPECT_EQ(timestampIn, timestampOut); 63 EXPECT_EQ(indexOut, indexIn); 64 } 65 66 } // namespace 67 } // namespace redfish 68