1 | /*============================================================================= |
2 | Boost.Wave: A Standard compliant C++ preprocessor library |
3 | http://www.boost.org/ |
4 | |
5 | Copyright (c) 2001-2013 Hartmut Kaiser. Distributed under the Boost |
6 | Software License, Version 1.0. (See accompanying file |
7 | LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
8 | =============================================================================*/ |
9 | |
10 | #if !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP) |
11 | #define BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP |
12 | |
13 | #include <string> |
14 | #include <vector> |
15 | |
16 | // include boost |
17 | #include <boost/config.hpp> |
18 | |
19 | #include "cmd_line_utils.hpp" |
20 | |
21 | /////////////////////////////////////////////////////////////////////////////// |
22 | class testwave_app |
23 | { |
24 | public: |
25 | testwave_app(boost::program_options::variables_map const& vm); |
26 | |
27 | // Test the given file (i.e. preprocess the file and compare the result |
28 | // against the embedded 'R' comments, if an error occurs compare the error |
29 | // message against the given 'E' comments). |
30 | bool test_a_file(std::string filename); |
31 | |
32 | // print the current version of this program |
33 | int print_version(); |
34 | |
35 | // print the copyright statement |
36 | int print_copyright(); |
37 | |
38 | // access the common options used for the command line and the config |
39 | // options inside the test files |
40 | boost::program_options::options_description const& common_options() const |
41 | { |
42 | return desc_options; |
43 | } |
44 | |
45 | void set_debuglevel(int debuglevel_) |
46 | { |
47 | debuglevel = debuglevel_; |
48 | } |
49 | int get_debuglevel() const |
50 | { |
51 | return debuglevel; |
52 | } |
53 | |
54 | protected: |
55 | // Read the given file into a string |
56 | bool read_file(std::string const& filename, std::string& instr); |
57 | |
58 | // Extract special information from comments marked with the given letter |
59 | bool (std::string const& filename, |
60 | std::string const& instr, char flag, std::string& content); |
61 | |
62 | // Extract the expected output and expected hooks information from the |
63 | // given input data. |
64 | // The expected output has to be provided inside of special comments which |
65 | // start with a capital 'R' ('H' for the hooks information). All such |
66 | // comments are concatenated and returned through the parameter 'expected' |
67 | // ('expectedhooks' for hooks information). |
68 | bool (std::string const& filename, |
69 | std::string const& instr, std::string& expected, |
70 | std::string& expectedhooks); |
71 | |
72 | // Extracts the required preprocessing options from the given input data |
73 | // and initializes the given Wave context object accordingly. |
74 | // We allow the same (applicable) options to be used as are valid for the |
75 | // wave driver executable. |
76 | template <typename Context> |
77 | bool (std::string const& filename, |
78 | std::string const& instr, Context& ctx, bool single_line, |
79 | boost::program_options::variables_map& vm); |
80 | |
81 | // transfers the options collected in the vm parameter into the given |
82 | // context |
83 | template <typename Context> |
84 | bool initialise_options(Context& ctx, |
85 | boost::program_options::variables_map const& vm, bool single_line); |
86 | |
87 | // Preprocess the given input data and return the generated output through |
88 | // the parameter 'result'. |
89 | std::tuple<bool, bool> // pass/fail, suppressed by cfg macro (or not) |
90 | preprocess_file(std::string filename, std::string const& instr, |
91 | std::string& result, std::string& error, std::string& hooks, |
92 | std::string const& expected_cfg_macro, bool single_line = false); |
93 | |
94 | // Add special predefined macros to the context object |
95 | template <typename Context> |
96 | bool add_predefined_macros(Context& ctx); |
97 | |
98 | // This function compares the real result and the expected one but first |
99 | // replaces all occurrences in the expected result of |
100 | // $E: to the result of preprocessing the given expression |
101 | // $F: to the passed full filepath |
102 | // $P: to the full path |
103 | // $R: to the relative path |
104 | // $V: to the current Boost version number |
105 | bool got_expected_result(std::string const& filename, |
106 | std::string const& result, std::string& expected); |
107 | |
108 | // construct a SIZEOF macro definition string and predefine this macro |
109 | template <typename Context> |
110 | bool add_sizeof_definition(Context& ctx, char const *name, int value); |
111 | |
112 | // construct a MIN macro definition string and predefine this macro |
113 | template <typename T, typename Context> |
114 | bool add_min_definition(Context& ctx, char const *name); |
115 | |
116 | // construct a MAX macro definition string and predefine this macro |
117 | template <typename T, typename Context> |
118 | bool add_max_definition(Context& ctx, char const *name); |
119 | |
120 | // Predefine __TESTWAVE_HAS_STRICT_LEXER__ |
121 | template <typename Context> |
122 | bool add_strict_lexer_definition(Context& ctx); |
123 | |
124 | #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS |
125 | // Predefine __TESTWAVE_SUPPORT_MS_EXTENSIONS__ |
126 | template <typename Context> |
127 | bool add_support_ms_extensions_definition(Context& ctx); |
128 | #endif |
129 | |
130 | private: |
131 | int debuglevel; |
132 | boost::program_options::options_description desc_options; |
133 | boost::program_options::variables_map const& global_vm; |
134 | }; |
135 | |
136 | #endif // !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP) |
137 | |