From 2508f3c721555f7b8f07f698c14fe919e1022b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 13 May 2009 21:38:57 +0200 Subject: [PATCH] Preprocessor: Added test case for #291. One of the assertions is a TODO and it should be fixed. http://apps.sourceforge.net/trac/cppcheck/ticket/291 --- test/testpreprocessor.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index dc9c34d68..7537417fe 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -122,6 +122,7 @@ private: TEST_CASE(unicode1); TEST_CASE(define_part_of_func); + TEST_CASE(conditionalDefine); TEST_CASE(multiline_comment); } @@ -948,6 +949,29 @@ private: ASSERT_EQUALS("", errout.str()); } + void conditionalDefine() + { + const char filedata[] = "#ifdef A\n" + "#define N 10\n" + "#else\n" + "#define N 20\n" + "#endif\n" + "N"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Preprocessor preprocessor; + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); + ASSERT_EQUALS("\n\n\n\n\n20\n", actual[""]); + TODO_ASSERT_EQUALS("\n\n\n\n\n10\n", actual["A"]); + ASSERT_EQUALS("", errout.str()); + } + + void multiline_comment() { errout.str("");