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 common_options() const40 boost::program_options::options_description const& common_options() const 41 { 42 return desc_options; 43 } 44 set_debuglevel(int debuglevel_)45 void set_debuglevel(int debuglevel_) 46 { 47 debuglevel = debuglevel_; 48 } get_debuglevel() const49 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 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 extract_expected_output(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 extract_options(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 bool preprocess_file(std::string filename, std::string const& instr, 90 std::string& result, std::string& error, std::string& hooks, 91 std::string const& expected_cfg_macro, bool single_line = false); 92 93 // Add special predefined macros to the context object 94 template <typename Context> 95 bool add_predefined_macros(Context& ctx); 96 97 // This function compares the real result and the expected one but first 98 // replaces all occurrences in the expected result of 99 // $E: to the result of preprocessing the given expression 100 // $F: to the passed full filepath 101 // $P: to the full path 102 // $R: to the relative path 103 // $V: to the current Boost version number 104 bool got_expected_result(std::string const& filename, 105 std::string const& result, std::string& expected); 106 107 // construct a SIZEOF macro definition string and predefine this macro 108 template <typename Context> 109 bool add_sizeof_definition(Context& ctx, char const *name, int value); 110 111 // construct a MIN macro definition string and predefine this macro 112 template <typename T, typename Context> 113 bool add_min_definition(Context& ctx, char const *name); 114 115 // construct a MAX macro definition string and predefine this macro 116 template <typename T, typename Context> 117 bool add_max_definition(Context& ctx, char const *name); 118 119 // Predefine __TESTWAVE_HAS_STRICT_LEXER__ 120 template <typename Context> 121 bool add_strict_lexer_definition(Context& ctx); 122 123 #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS 124 // Predefine __TESTWAVE_SUPPORT_MS_EXTENSIONS__ 125 template <typename Context> 126 bool add_support_ms_extensions_definition(Context& ctx); 127 #endif 128 129 private: 130 int debuglevel; 131 boost::program_options::options_description desc_options; 132 boost::program_options::variables_map const& global_vm; 133 }; 134 135 #endif // !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP) 136