mirror of
https://github.com/tnodir/fort
synced 2024-11-14 21:55:37 +00:00
Tests: tst_ruletextparser.h: Add tests
This commit is contained in:
parent
f75ece4e61
commit
ce9e323f18
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -61,6 +61,7 @@ class RuleTextParser : public QObject
|
||||
public:
|
||||
enum ErrorCode : quint16 {
|
||||
ErrorNone = 0,
|
||||
ErrorUnexpectedStartOfLine,
|
||||
ErrorUnexpectedEndOfList,
|
||||
ErrorUnexpectedEndOfValuesList,
|
||||
ErrorUnexpectedSymboOfListEnd,
|
||||
|
Loading…
Reference in New Issue
Block a user