tests: Verify ExpressionMatch with invalid regex
authorShane Synan <digitalcircuit36939@gmail.com>
Thu, 3 Jan 2019 03:54:02 +0000 (22:54 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 31 May 2019 14:41:59 +0000 (16:41 +0200)
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

index e39903c..8ba1bd7 100644 (file)
@@ -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"));
+}