blob: 6fe93bc985bccee456f27a458426040fa3d37346 [file] [log] [blame]
Shawn McCarney7c5d7b22020-04-03 18:50:13 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include "journal.hpp"
19
20#include <string>
21#include <vector>
22
Shawn McCarney5248b8a2020-07-15 22:59:36 -050023#include <gmock/gmock.h>
24
25namespace phosphor::power::regulators
26{
27
28/**
29 * @class MockJournal
30 *
31 * Mock implementation of the Journal interface.
32 */
33class MockJournal : public Journal
34{
35 public:
36 // Specify which compiler-generated methods we want
37 MockJournal() = default;
38 MockJournal(const MockJournal&) = delete;
39 MockJournal(MockJournal&&) = delete;
40 MockJournal& operator=(const MockJournal&) = delete;
41 MockJournal& operator=(MockJournal&&) = delete;
42 virtual ~MockJournal() = default;
43
44 MOCK_METHOD(void, logDebug, (const std::string& message), (override));
45 MOCK_METHOD(void, logDebug, (const std::vector<std::string>& messages),
46 (override));
47 MOCK_METHOD(void, logError, (const std::string& message), (override));
48 MOCK_METHOD(void, logError, (const std::vector<std::string>& messages),
49 (override));
50 MOCK_METHOD(void, logInfo, (const std::string& message), (override));
51 MOCK_METHOD(void, logInfo, (const std::vector<std::string>& messages),
52 (override));
53};
54
55} // namespace phosphor::power::regulators
56
57// TODO: Remove the functional interface below once all the code has switched to
58// the new Journal interface. Also delete mock_journal.cpp and remove
59// references to it in meson files.
60
Shawn McCarney7c5d7b22020-04-03 18:50:13 -050061/**
62 * Extensions to the systemd journal interface.
63 *
64 * Provides functions to access and clear mock journal messages that have been
65 * logged. These functions should only be used by testcases.
66 */
67namespace phosphor::power::regulators::journal
68{
69
70/**
71 * Clears all mock journal messages.
72 */
73void clear();
74
75/**
76 * Returns all mock journal messages with a priority value of 'ERR'.
77 *
78 * @return mock error messages
79 */
80const std::vector<std::string>& getErrMessages();
81
82/**
83 * Returns all mock journal messages with a priority value of 'INFO'.
84 *
85 * @return mock informational messages
86 */
87const std::vector<std::string>& getInfoMessages();
88
Shawn McCarney9af85552020-04-09 11:43:48 -050089/**
90 * Returns all mock journal messages with a priority value of 'DEBUG'.
91 *
92 * @return mock debug messages
93 */
94const std::vector<std::string>& getDebugMessages();
95
Shawn McCarney7c5d7b22020-04-03 18:50:13 -050096} // namespace phosphor::power::regulators::journal