From c41e04630e685bbd4c4cbd5d331f16c496b2ef8f Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Wed, 2 Jan 2019 22:54:02 -0500 Subject: [PATCH] tests: Verify ExpressionMatch with invalid regex Verify that ExpressionMatch behaves reasonably with an invalid regular expression passed in, rejecting all matches and being labeled as not valid. This matches the test devised by justJanne in the process of resolving a crash in Quasseldroid-NG. We should make sure Quassel desktop never regresses into crashing, too. See https://git.kuschku.de/justJanne/QuasselDroid-ng/commit/f1f320782cb0bca3fb7974e7688ce33af19456cf --- tests/common/expressionmatchtest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/common/expressionmatchtest.cpp b/tests/common/expressionmatchtest.cpp index e39903c6..8ba1bd77 100644 --- a/tests/common/expressionmatchtest.cpp +++ b/tests/common/expressionmatchtest.cpp @@ -434,3 +434,22 @@ TEST(ExpressionMatchTest, trimMultiWildcardWhitespace) EXPECT_EQ(ExpressionMatch::trimMultiWildcardWhitespace(result), result); } } + + +TEST(ExpressionMatchTest, testInvalidRegEx) +{ + // Invalid regular expression pattern + ExpressionMatch invalidRegExMatch = + ExpressionMatch("*network", ExpressionMatch::MatchMode::MatchRegEx, false); + + // Assert not valid + ASSERT_FALSE(invalidRegExMatch.isValid()); + // Assert not empty + EXPECT_FALSE(invalidRegExMatch.isEmpty()); + // Assert default match fails + EXPECT_FALSE(invalidRegExMatch.match("")); + // Assert wildcard match fails + EXPECT_FALSE(invalidRegExMatch.match("network")); + // Assert literal match fails + EXPECT_FALSE(invalidRegExMatch.match("*network")); +} -- 2.20.1