Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / inipp / repo / inipp / unittest / test.h
1 #include "inipp.h"
2
3 #include <fstream>
4 #include <sstream>
5
6 using namespace inipp;
7
8 template <class CharT>
9 static inline auto read_all(const std::string & filename) {
10         std::basic_ifstream<CharT> is(filename);
11         std::basic_stringstream<CharT> sstr;
12         sstr << is.rdbuf();
13         return sstr.str();
14 }
15
16 template <class CharT>
17 static inline auto parse(const std::string & filename, Ini<CharT> & ini) {
18         std::basic_ifstream<CharT> is(filename);
19         ini.parse(is);
20 }
21
22 template <class CharT>
23 static inline void errors(std::basic_ostream<CharT> & os, const Ini<CharT> & ini) {
24         for (auto const & err : ini.errors) {
25                 os << err << std::endl;
26         }
27 }
28
29 template <class CharT>
30 static inline auto test(const std::string & inifile, Ini<CharT> & ini) {
31         std::basic_ostringstream<CharT> os;
32         parse(inifile, ini);
33         os << ">>> ERRORS <<<" << std::endl;
34         errors(os, ini);
35         os << ">>> GENERATE <<<" << std::endl;
36         ini.generate(os);
37         os << ">>> INTERPOLATE <<<" << std::endl;
38         ini.interpolate();
39         ini.generate(os);
40         return os.str();
41 }
42
43 template <class CharT>
44 static inline auto runtest(const char *inifile, const char *expectedfile, std::basic_ostream<CharT> & os) {
45         Ini<CharT> ini;
46         auto actual = test(inifile, ini);
47         auto expected = read_all<CharT>(expectedfile);
48         os << actual;
49         return (actual == expected);
50 }