From 831962c779a19a1822b0074012763b604ac42d24 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Mon, 3 Nov 2014 18:34:08 -0800 Subject: [PATCH] Allow trailing newline in trie files. Bug: 17958588 Change-Id: Iaa9b5aa95ee27e31d486755954df193f808b7e82 --- framework/common/tcuCommandLine.cpp | 9 +++++++++ modules/internal/ditFrameworkTests.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/framework/common/tcuCommandLine.cpp b/framework/common/tcuCommandLine.cpp index 3bcc06a..9c25f31 100644 --- a/framework/common/tcuCommandLine.cpp +++ b/framework/common/tcuCommandLine.cpp @@ -375,6 +375,15 @@ static void parseCaseTrie (CaseTreeNode* root, std::istream& in) { expectNode = false; nodeStack.pop_back(); + + // consume trailing new line + if (nodeStack.empty()) + { + if (in.peek() == '\r') + in.get(); + if (in.peek() == '\n') + in.get(); + } } else expectNode = true; diff --git a/modules/internal/ditFrameworkTests.cpp b/modules/internal/ditFrameworkTests.cpp index 5776cdc..0b5b1b5 100644 --- a/modules/internal/ditFrameworkTests.cpp +++ b/modules/internal/ditFrameworkTests.cpp @@ -251,9 +251,37 @@ public: }; addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); } + { + static const char* const caseList = "{test}\r"; + static const MatchCase subCases[] = + { + { "test", MatchCase::MATCH_CASE }, + { "test.cd", MatchCase::NO_MATCH }, + }; + addChild(new CaseListParserCase(m_testCtx, "trailing_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); + } + { + static const char* const caseList = "{test}\n"; + static const MatchCase subCases[] = + { + { "test", MatchCase::MATCH_CASE }, + { "test.cd", MatchCase::NO_MATCH }, + }; + addChild(new CaseListParserCase(m_testCtx, "trailing_lf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); + } + { + static const char* const caseList = "{test}\r\n"; + static const MatchCase subCases[] = + { + { "test", MatchCase::MATCH_CASE }, + { "test.cd", MatchCase::NO_MATCH }, + }; + addChild(new CaseListParserCase(m_testCtx, "trailing_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); + } // Negative tests addChild(new NegativeCaseListCase(m_testCtx, "empty_string", "")); + addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n")); addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}")); addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}")); addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}")); @@ -275,6 +303,11 @@ public: addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}")); addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}")); addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x")); + addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_1", "{\na}")); + addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_2", "{a\n,b}")); + addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_3", "{a,\nb}")); + addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_4", "{a{b\n}}")); + addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_5", "{a{b}\n}")); } }; -- 2.7.4