From 4b1927c03847a8efafa25bc49adf1fe9fc78c401 Mon Sep 17 00:00:00 2001 From: "Chang, Harry" Date: Sun, 31 Mar 2019 11:16:50 +0800 Subject: [PATCH] Logical combination: add purely negative match at EOD unit test MultiCombPurelyNegativeUniSubEOD6. --- unit/hyperscan/logical_combination.cpp | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/unit/hyperscan/logical_combination.cpp b/unit/hyperscan/logical_combination.cpp index 49854be1..9558948f 100644 --- a/unit/hyperscan/logical_combination.cpp +++ b/unit/hyperscan/logical_combination.cpp @@ -805,6 +805,59 @@ TEST(LogicalCombination, MultiCombPurelyNegativeUniSub6) { ASSERT_EQ(HS_SUCCESS, err); } +TEST(LogicalCombination, MultiCombPurelyNegativeUniSubEOD6) { + hs_database_t *db = nullptr; + hs_compile_error_t *compile_err = nullptr; + CallBackContext c; + string data = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "-----------------------------------------------" + "xdefedxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "-----------------------------------------------" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "-------------------------------------defed"; + const char *expr[] = {"abc", "defed", "foobar.*gh", "teakettle{4,10}", + "ijkl[mMn]", "cba", "fed", "google.*cn", + "haystacks{4,8}", "ijkl[oOp]", "cab", "fee", + "goobar.*jp", "shockwave{4,6}", "ijkl[rRs]", + "(101 & 102 & 103) | (!104 & !105)", + "(!201 | 202 & 203) & (!204 | 205)", + "((301 | 302) & 303) & (304 | 305)"}; + unsigned flags[] = {0, 0, 0, 0, 0, 0, HS_FLAG_MULTILINE, + 0, 0, 0, 0, 0, 0, 0, 0, + HS_FLAG_COMBINATION, HS_FLAG_COMBINATION, + HS_FLAG_COMBINATION}; + unsigned ids[] = {101, 102, 103, 104, 105, 201, 202, 203, 204, 205, 301, + 302, 303, 304, 305, 1001, 1002, 1003}; + hs_error_t err = hs_compile_multi(expr, flags, ids, 18, HS_MODE_NOSTREAM, + nullptr, &db, &compile_err); + + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_TRUE(db != nullptr); + + hs_scratch_t *scratch = nullptr; + err = hs_alloc_scratch(db, &scratch); + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_TRUE(scratch != nullptr); + + c.halt = 0; + err = hs_scan(db, data.c_str(), data.size(), 0, scratch, record_cb, + (void *)&c); + ASSERT_EQ(HS_SUCCESS, err); + ASSERT_EQ(8U, c.matches.size()); + ASSERT_EQ(MatchRecord(106, 102), c.matches[0]); + ASSERT_EQ(MatchRecord(106, 202), c.matches[1]); + ASSERT_EQ(MatchRecord(106, 1001), c.matches[2]); + ASSERT_EQ(MatchRecord(106, 1002), c.matches[3]); + ASSERT_EQ(MatchRecord(300, 102), c.matches[4]); + ASSERT_EQ(MatchRecord(300, 202), c.matches[5]); + ASSERT_EQ(MatchRecord(300, 1001), c.matches[6]); + ASSERT_EQ(MatchRecord(300, 1002), c.matches[7]); + + hs_free_database(db); + err = hs_free_scratch(scratch); + ASSERT_EQ(HS_SUCCESS, err); +} + TEST(LogicalCombination, MultiCombStream1) { hs_database_t *db = nullptr; hs_compile_error_t *compile_err = nullptr;