66#include " simplecpp.h"
77
88#include < cctype>
9+ #include < cstdint>
910#include < cstdlib>
1011#include < cstring>
1112#include < exception>
2526#define STRINGIZE (x ) STRINGIZE_(x)
2627
2728static const std::string testSourceDir = SIMPLECPP_TEST_SOURCE_DIR;
29+
30+ namespace {
31+ enum class Input : std::uint8_t {
32+ Stringstream,
33+ CharBuffer
34+ };
35+ }
36+
37+ static Input USE_INPUT = Input::Stringstream;
2838static int numberOfFailedAssertions = 0 ;
2939
3040#define ASSERT_EQUALS (expected, actual ) (assertEquals((expected), (actual), __LINE__))
@@ -41,11 +51,21 @@ static std::string pprint(const std::string &in)
4151 return ret;
4252}
4353
54+ static const char * inputString (Input input) {
55+ switch (input) {
56+ case Input::Stringstream:
57+ return " Stringstream" ;
58+ case Input::CharBuffer:
59+ return " CharBuffer" ;
60+ }
61+ return " " ; // unreachable - needed for GCC and Visual Studio
62+ }
63+
4464static int assertEquals (const std::string &expected, const std::string &actual, int line)
4565{
4666 if (expected != actual) {
4767 numberOfFailedAssertions++;
48- std::cerr << " ------ assertion failed ---------" << std::endl;
68+ std::cerr << " ------ assertion failed ( " << inputString (USE_INPUT) << " ) ---------" << std::endl;
4969 std::cerr << " line test.cpp:" << line << std::endl;
5070 std::cerr << " expected:" << pprint (expected) << std::endl;
5171 std::cerr << " actual:" << pprint (actual) << std::endl;
@@ -83,8 +103,16 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
83103
84104static simplecpp::TokenList makeTokenList (const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
85105{
86- std::istringstream istr (std::string (code, size));
87- return {istr,filenames,filename,outputList};
106+ switch (USE_INPUT) {
107+ case Input::Stringstream: {
108+ std::istringstream istr (std::string (code, size));
109+ return {istr,filenames,filename,outputList};
110+ }
111+ case Input::CharBuffer:
112+ return {{code, size}, filenames, filename, outputList};
113+ }
114+
115+ return simplecpp::TokenList{filenames}; // unreachable - needed for GCC and Visual Studio
88116}
89117
90118static simplecpp::TokenList makeTokenList (const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
@@ -3619,8 +3647,10 @@ static void leak()
36193647 }
36203648}
36213649
3622- int main (int argc, char **argv)
3650+ static void runTests (int argc, char **argv, Input input )
36233651{
3652+ USE_INPUT = input;
3653+
36243654 TEST_CASE (backslash);
36253655
36263656 TEST_CASE (builtin);
@@ -3892,6 +3922,11 @@ int main(int argc, char **argv)
38923922 TEST_CASE (fuzz_crash);
38933923
38943924 TEST_CASE (leak);
3925+ }
38953926
3927+ int main (int argc, char **argv)
3928+ {
3929+ runTests (argc, argv, Input::Stringstream);
3930+ runTests (argc, argv, Input::CharBuffer);
38963931 return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
38973932}
0 commit comments