mirror of
https://github.com/tnodir/fort
synced 2024-11-15 01:25:52 +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" });
|
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);
|
const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_OR);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!skipComments(CharLineBegin))
|
if (!skipComments(CharLineBegin)) {
|
||||||
|
if (!isEmpty()) {
|
||||||
|
setError(ErrorUnexpectedStartOfLine, tr("Unexpected start of line"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!parseLine())
|
if (!parseLine())
|
||||||
break;
|
break;
|
||||||
@ -142,7 +148,7 @@ bool RuleTextParser::parseLine()
|
|||||||
|
|
||||||
endList(nodeIndex);
|
endList(nodeIndex);
|
||||||
|
|
||||||
return true;
|
return !hasError();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTextParser::parseLineSection(RuleCharTypes expectedSeparator)
|
bool RuleTextParser::parseLineSection(RuleCharTypes expectedSeparator)
|
||||||
|
@ -61,6 +61,7 @@ class RuleTextParser : public QObject
|
|||||||
public:
|
public:
|
||||||
enum ErrorCode : quint16 {
|
enum ErrorCode : quint16 {
|
||||||
ErrorNone = 0,
|
ErrorNone = 0,
|
||||||
|
ErrorUnexpectedStartOfLine,
|
||||||
ErrorUnexpectedEndOfList,
|
ErrorUnexpectedEndOfList,
|
||||||
ErrorUnexpectedEndOfValuesList,
|
ErrorUnexpectedEndOfValuesList,
|
||||||
ErrorUnexpectedSymboOfListEnd,
|
ErrorUnexpectedSymboOfListEnd,
|
||||||
|
Loading…
Reference in New Issue
Block a user