Tests: tst_ruletextparser.h: Add tests

This commit is contained in:
Nodir Temirkhodjaev 2024-11-06 19:41:40 +05:00
parent f75ece4e61
commit ce9e323f18
3 changed files with 45 additions and 2 deletions

View File

@ -210,3 +210,39 @@ TEST_F(RuleTextParserTest, lineIp6Range)
checkStringList(rf.values, { "67" });
}
}
TEST_F(RuleTextParserTest, lineEmptySections)
{
RuleTextParser p("1:::2::\n");
ASSERT_TRUE(p.parse());
ASSERT_EQ(p.ruleFilters().size(), 4);
}
TEST_F(RuleTextParserTest, badStartOfLine)
{
RuleTextParser p(":1\n");
ASSERT_FALSE(p.parse());
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedStartOfLine);
}
TEST_F(RuleTextParserTest, badNoFilterName)
{
RuleTextParser p("1:2:3");
ASSERT_FALSE(p.parse());
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorNoFilterName);
}
TEST_F(RuleTextParserTest, badFilterName)
{
RuleTextParser p("test(1)");
ASSERT_FALSE(p.parse());
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorBadFilterName);
}

View File

@ -97,8 +97,14 @@ bool RuleTextParser::parseLines()
const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_OR);
for (;;) {
if (!skipComments(CharLineBegin))
if (!skipComments(CharLineBegin)) {
if (!isEmpty()) {
setError(ErrorUnexpectedStartOfLine, tr("Unexpected start of line"));
return false;
}
break;
}
if (!parseLine())
break;
@ -142,7 +148,7 @@ bool RuleTextParser::parseLine()
endList(nodeIndex);
return true;
return !hasError();
}
bool RuleTextParser::parseLineSection(RuleCharTypes expectedSeparator)

View File

@ -61,6 +61,7 @@ class RuleTextParser : public QObject
public:
enum ErrorCode : quint16 {
ErrorNone = 0,
ErrorUnexpectedStartOfLine,
ErrorUnexpectedEndOfList,
ErrorUnexpectedEndOfValuesList,
ErrorUnexpectedSymboOfListEnd,