Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 1 | /** |
| 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 McCarney | 5248b8a | 2020-07-15 22:59:36 -0500 | [diff] [blame] | 23 | #include <gmock/gmock.h> |
| 24 | |
| 25 | namespace phosphor::power::regulators |
| 26 | { |
| 27 | |
| 28 | /** |
| 29 | * @class MockJournal |
| 30 | * |
| 31 | * Mock implementation of the Journal interface. |
| 32 | */ |
| 33 | class 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 McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 61 | /** |
| 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 | */ |
| 67 | namespace phosphor::power::regulators::journal |
| 68 | { |
| 69 | |
| 70 | /** |
| 71 | * Clears all mock journal messages. |
| 72 | */ |
| 73 | void clear(); |
| 74 | |
| 75 | /** |
| 76 | * Returns all mock journal messages with a priority value of 'ERR'. |
| 77 | * |
| 78 | * @return mock error messages |
| 79 | */ |
| 80 | const 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 | */ |
| 87 | const std::vector<std::string>& getInfoMessages(); |
| 88 | |
Shawn McCarney | 9af8555 | 2020-04-09 11:43:48 -0500 | [diff] [blame] | 89 | /** |
| 90 | * Returns all mock journal messages with a priority value of 'DEBUG'. |
| 91 | * |
| 92 | * @return mock debug messages |
| 93 | */ |
| 94 | const std::vector<std::string>& getDebugMessages(); |
| 95 | |
Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 96 | } // namespace phosphor::power::regulators::journal |