1+ #ifndef RUNCPP2_UNIT_TESTS_INCLUDE_MANAGER_MOCK_COMPONENTS_HPP
2+ #define RUNCPP2_UNIT_TESTS_INCLUDE_MANAGER_MOCK_COMPONENTS_HPP
3+
4+ #include " ghc/filesystem.hpp"
5+ #include " CppOverride.hpp"
6+
7+ #include < sstream>
8+ #include < type_traits>
9+
10+ extern CO_DECLARE_INSTANCE (OverrideInstance);
11+
12+ namespace ghc
13+ {
14+ namespace filesystem
15+ {
16+ CO_OVERRIDE_METHOD ( OverrideInstance,
17+ bool ,
18+ Mock_exists,
19+ (const path&, std::error_code&),
20+ /* no prepend */ ,
21+ noexcept )
22+
23+ CO_OVERRIDE_METHOD ( OverrideInstance,
24+ bool ,
25+ Mock_create_directories,
26+ (const path&, std::error_code&),
27+ /* no prepend */ ,
28+ noexcept )
29+
30+ CO_OVERRIDE_METHOD ( OverrideInstance,
31+ file_time_type,
32+ Mock_last_write_time,
33+ (const path&, std::error_code&),
34+ /* no prepend */ ,
35+ noexcept )
36+ }
37+ }
38+
39+ namespace std
40+ {
41+ class Mock_ifstream
42+ {
43+ public:
44+ CO_OVERRIDE_MEMBER_METHOD_CTOR (OverrideInstance, Mock_ifstream, const ghc::filesystem::path&)
45+ CO_OVERRIDE_MEMBER_METHOD (OverrideInstance, bool , is_open, ())
46+ };
47+
48+ class Mock_ofstream
49+ {
50+ public:
51+ std::stringstream StringStream;
52+
53+ CO_OVERRIDE_MEMBER_METHOD_CTOR (OverrideInstance, Mock_ofstream, const ghc::filesystem::path&)
54+ CO_OVERRIDE_MEMBER_METHOD (OverrideInstance, bool , is_open, ())
55+ CO_OVERRIDE_MEMBER_METHOD (OverrideInstance, void , close, ())
56+
57+ template <typename T>
58+ friend Mock_ofstream& operator <<(Mock_ofstream&, T const &);
59+ };
60+
61+ template <typename T>
62+ class Mock_hash
63+ {
64+ static_assert (std::is_same<T, std::string>::value, " We are only mocking std string" );
65+ public:
66+ CO_OVERRIDE_MEMBER_METHOD (OverrideInstance, std::size_t , operator (), (T))
67+ };
68+
69+ template <typename T>
70+ inline Mock_ofstream& operator <<(Mock_ofstream& mockStream, T const & value)
71+ {
72+ mockStream.StringStream << value;
73+ return mockStream;
74+ }
75+
76+ inline Mock_ofstream& operator <<(Mock_ofstream& mockStream, std::ostream& (*pf)(std::ostream&))
77+ {
78+ mockStream.StringStream << pf;
79+ return mockStream;
80+ }
81+
82+ inline bool Mock_getline (Mock_ifstream& stream, std::string& line)
83+ {
84+ CO_OVERRIDE_IMPL (OverrideInstance, bool , (stream, line));
85+ return false ;
86+ }
87+ }
88+
89+ #define exists Mock_exists
90+ #define create_directories Mock_create_directories
91+ #define last_write_time Mock_last_write_time
92+ #define ifstream Mock_ifstream
93+ #define ofstream Mock_ofstream
94+ #define hash Mock_hash
95+ #define getline Mock_getline
96+
97+ #if INTERNAL_RUNCPP2_UNDEF_MOCKS
98+ #undef exists
99+ #undef create_directories
100+ #undef last_write_time
101+ #undef ifstream
102+ #undef ofstream
103+ #undef hash
104+ #undef getline
105+ #endif
106+
107+ #endif
0 commit comments