Antares Simulator
Power System Simulator
logs.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 
22 #ifndef __TESTS_ANTARES_LIBS_LOGS_FAKE_H__
23 #define __TESTS_ANTARES_LIBS_LOGS_FAKE_H__
24 
25 #include <string>
26 
27 #include <yuni/core/string/string.h>
28 
29 namespace Antares
30 {
31 namespace UnitTests
32 {
33 
34 class fakeLogger;
35 
36 class Buffer
37 {
38 public:
39  Buffer() = default;
40 
41  template<typename U>
42  Buffer& operator<<(const U& u)
43  {
44  // Appending the piece of message to the buffer
45  buffer_.append(u);
46  return *this;
47  }
48 
49  void clear()
50  {
51  buffer_.clear();
52  }
53 
54  std::string content() const
55  {
56  return buffer_.to<std::string>();
57  }
58 
59  bool contains(const std::string sub_string) const
60  {
61  return buffer_.contains(sub_string);
62  }
63 
64  bool empty()
65  {
66  return buffer_.empty();
67  }
68 
69 private:
70  Yuni::CString<1024> buffer_;
71 };
72 
74 {
75 public:
76  fakeLogger() = default;
77 
78  Buffer& error()
79  {
80  return error_buffer_;
81  }
82 
83  Buffer& info()
84  {
85  return info_buffer_;
86  }
87 
88  Buffer& debug()
89  {
90  return debug_buffer_;
91  }
92 
93  Buffer& warning()
94  {
95  return warning_buffer_;
96  }
97 
98 private:
99  Buffer error_buffer_;
100  Buffer info_buffer_;
101  Buffer debug_buffer_;
102  Buffer warning_buffer_;
103 };
104 
105 } // namespace UnitTests
106 
107 extern UnitTests::fakeLogger logs;
108 
109 } // namespace Antares
110 
111 #endif // __TESTS_ANTARES_LIBS_LOGS_FAKE_H__
Definition: logs.h:37
Definition: logs.h:74