Allow trailing newline in trie files.
authorJarkko Pöyry <jpoyry@google.com>
Tue, 4 Nov 2014 02:34:08 +0000 (18:34 -0800)
committerPyry Haulos <phaulos@google.com>
Tue, 11 Nov 2014 16:56:24 +0000 (16:56 +0000)
Bug: 18329517
Bug: 17958588
Change-Id: Iaa9b5aa95ee27e31d486755954df193f808b7e82
(cherry picked from commit 831962c779a19a1822b0074012763b604ac42d24)

framework/common/tcuCommandLine.cpp
modules/internal/ditFrameworkTests.cpp

index 93b3a86..6cb8295 100644 (file)
@@ -374,6 +374,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;
index 5776cdc..0b5b1b5 100644 (file)
@@ -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}"));
        }
 };