| 1 | /*============================================================================= |
|---|
| 2 | Boost.Wave: A Standard compliant C++ preprocessor library |
|---|
| 3 | http://www.boost.org/ |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 2001-2005 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 extract_special_information(std::string const& filename, |
|---|
| 60 | std::string const& instr, char flag, std::string& content); |
|---|
| 61 | |
|---|
| 62 | // Extract the expected output from the given input data |
|---|
| 63 | // The expected output has to be provided inside of special comments which |
|---|
| 64 | // start with a capital 'R'. All such comments are concatenated and |
|---|
| 65 | // returned through the parameter 'expected'. |
|---|
| 66 | bool extract_expected_output(std::string const& filename, |
|---|
| 67 | std::string const& instr, std::string& expected); |
|---|
| 68 | |
|---|
| 69 | // Extracts the required preprocessing options from the given input data |
|---|
| 70 | // and initialises the given Wave context object accordingly. |
|---|
| 71 | // We allow the same (applicable) options to be used as are valid for the |
|---|
| 72 | // wave driver executable. |
|---|
| 73 | template <typename Context> |
|---|
| 74 | bool extract_options(std::string const& filename, |
|---|
| 75 | std::string const& instr, Context& ctx); |
|---|
| 76 | |
|---|
| 77 | // transfers the options collected in the vm parameter into the given |
|---|
| 78 | // context |
|---|
| 79 | template <typename Context> |
|---|
| 80 | bool initialise_options(Context& ctx, |
|---|
| 81 | boost::program_options::variables_map const& vm); |
|---|
| 82 | |
|---|
| 83 | // Preprocess the given input data and return the generated output through |
|---|
| 84 | // the parameter 'result'. |
|---|
| 85 | bool preprocess_file(std::string filename, std::string const& instr, |
|---|
| 86 | std::string& result, std::string& error); |
|---|
| 87 | |
|---|
| 88 | // Add special predefined macros to the context object |
|---|
| 89 | template <typename Context> |
|---|
| 90 | bool add_predefined_macros(Context& ctx); |
|---|
| 91 | |
|---|
| 92 | // This function compares the real result and the expected one but first |
|---|
| 93 | // replaces all occurences in the expected result of |
|---|
| 94 | // $E: to the result of preprocessing the given expression |
|---|
| 95 | // $F: to the passed full filepath |
|---|
| 96 | // $P: to the full path |
|---|
| 97 | // $V: to the current Boost version number |
|---|
| 98 | bool got_expected_result(std::string const& filename, |
|---|
| 99 | std::string const& result, std::string& expected); |
|---|
| 100 | |
|---|
| 101 | // construct a SIZEOF macro definition string and predefine this macro |
|---|
| 102 | template <typename Context> |
|---|
| 103 | bool add_sizeof_definition(Context& ctx, char const *name, int value); |
|---|
| 104 | |
|---|
| 105 | // construct a MIN macro definition string and predefine this macro |
|---|
| 106 | template <typename T, typename Context> |
|---|
| 107 | bool add_min_definition(Context& ctx, char const *name); |
|---|
| 108 | |
|---|
| 109 | // construct a MAX macro definition string and predefine this macro |
|---|
| 110 | template <typename T, typename Context> |
|---|
| 111 | bool add_max_definition(Context& ctx, char const *name); |
|---|
| 112 | |
|---|
| 113 | private: |
|---|
| 114 | int debuglevel; |
|---|
| 115 | boost::program_options::options_description desc_options; |
|---|
| 116 | boost::program_options::variables_map const& global_vm; |
|---|
| 117 | }; |
|---|
| 118 | |
|---|
| 119 | #endif // !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP) |
|---|