From f792bf4a0d92fccc18448f413175abc3bd47ff2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Oct 2008 12:19:19 +0000 Subject: [PATCH] preprocessor: Created a simple test. But it fails currently. --- preprocessor.cpp | 12 ++++++++++++ preprocessor.h | 5 +++++ testpreprocessor.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/preprocessor.cpp b/preprocessor.cpp index 2365096e4..5df013a6a 100644 --- a/preprocessor.cpp +++ b/preprocessor.cpp @@ -17,5 +17,17 @@ */ +#include "preprocessor.h" + +#include + +void preprocess(std::istream &istr, std::map &result) +{ + std::ostringstream ostr; + std::string line; + while ( getline(istr, line) ) + ostr << line << "\n"; + +} diff --git a/preprocessor.h b/preprocessor.h index 08a48c3b6..a349aba64 100644 --- a/preprocessor.h +++ b/preprocessor.h @@ -21,8 +21,13 @@ #define preprocessorH //--------------------------------------------------------------------------- +#include +#include +#include +void preprocess(std::istream &istr, std::map &result); + //--------------------------------------------------------------------------- #endif diff --git a/testpreprocessor.cpp b/testpreprocessor.cpp index e34a13c35..7b828519a 100644 --- a/testpreprocessor.cpp +++ b/testpreprocessor.cpp @@ -24,6 +24,9 @@ #include "testsuite.h" #include "preprocessor.h" +#include +#include + class TestPreprocessor : public TestFixture { public: @@ -37,8 +40,36 @@ private: TEST_CASE( test1 ); } + void check(const char filedata[], const std::map &expected) + { + std::istringstream istr(filedata); + std::map actual; + preprocess( istr, actual ); + + ASSERT_EQUALS( expected.size(), actual.size() ); + for ( std::map::const_iterator it = actual.begin(); it != actual.end(); ++it ) + { + std::map::const_iterator it2 = expected.find(it->first); + if ( it2 == expected.end() ) + assertFail(__FILE__, __LINE__); + else + ASSERT_EQUALS( it->second, it2->second ); + } + } + void test1() { + const char filedata[] = "#ifdef WIN32\n" + " abcdef\n" + "#else\n" + " qwerty\n" + "#endif\n"; + + std::map expected; + expected[""] = "\n\n\n qwerty\n\n"; + expected["WIN32"] = "\n abcdef\n\n\n\n"; + + check( filedata, expected ); } };