1 #include "config.h"
2 
3 #include "elog_serialize.hpp"
4 #include "log_manager.hpp"
5 #include "xyz/openbmc_project/Common/error.hpp"
6 
7 #include <phosphor-logging/elog-errors.hpp>
8 #include <phosphor-logging/elog.hpp>
9 #include <phosphor-logging/log.hpp>
10 #include <sdbusplus/bus.hpp>
11 
12 #include <filesystem>
13 
14 #include <gmock/gmock.h>
15 #include <gtest/gtest.h>
16 
17 namespace phosphor
18 {
19 namespace logging
20 {
21 namespace internal
22 {
23 
24 namespace fs = std::filesystem;
25 
26 class journalInterface
27 {
28   public:
29     virtual ~journalInterface() = default;
30 
31     virtual void journalSync() = 0;
32     virtual int sd_journal_open(sd_journal** j, int k) = 0;
33     virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
34                                     const void** data, size_t length) = 0;
35     virtual void sd_journal_close(sd_journal* j) = 0;
36 };
37 
38 class journalImpl : public journalInterface
39 {
40   public:
41     void journalSync() override;
42     int sd_journal_open(sd_journal** j, int k) override;
43     int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
44                             const void** data, size_t length) override;
45     void sd_journal_close(sd_journal* j) override;
46 };
47 
48 int journalImpl::sd_journal_open(sd_journal**, int)
49 {
50     return 1;
51 }
52 
53 void journalImpl::journalSync()
54 {
55     return;
56 }
57 
58 int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**,
59                                      size_t)
60 {
61     return 1;
62 }
63 
64 void journalImpl::sd_journal_close(sd_journal*)
65 {
66     return;
67 }
68 
69 class MockJournal : public Manager
70 {
71   public:
72     MockJournal(sdbusplus::bus_t& bus, const char* objPath) :
73         Manager(bus, objPath){};
74     MOCK_METHOD0(journalSync, void());
75     MOCK_METHOD2(sd_journal_open, int(sd_journal**, int));
76     MOCK_METHOD4(sd_journal_get_data,
77                  int(sd_journal*, const char*, const void**, size_t));
78     MOCK_METHOD1(sd_journal_close, void(sd_journal*));
79 };
80 
81 class TestLogManager : public testing::Test
82 {
83   public:
84     sdbusplus::bus_t bus;
85     MockJournal manager;
86     TestLogManager() :
87         bus(sdbusplus::bus::new_default()),
88         manager(bus, "/xyz/openbmc_test/abc")
89     {
90         fs::create_directories(ERRLOG_PERSIST_PATH);
91     }
92 
93     ~TestLogManager()
94     {
95         // Leave the directory as other testcases use it and they
96         // may be running in parallel from other jobs.
97     }
98 };
99 
100 } // namespace internal
101 } // namespace logging
102 } // namespace phosphor
103