mirror of
https://github.com/tnodir/fort
synced 2024-11-15 01:36:22 +00:00
Tests: tst_ruletextparser.h: Add tests
This commit is contained in:
parent
3dd6fbc7a5
commit
973581ada4
@ -64,6 +64,15 @@ TEST_F(RuleTextParserTest, maxListDepth)
|
|||||||
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorListMaxDepth);
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorListMaxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, emptyComment)
|
||||||
|
{
|
||||||
|
RuleTextParser p("#");
|
||||||
|
|
||||||
|
ASSERT_TRUE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.ruleFilters().size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(RuleTextParserTest, lineIpPort)
|
TEST_F(RuleTextParserTest, lineIpPort)
|
||||||
{
|
{
|
||||||
RuleTextParser p("1.1.1.1:53");
|
RuleTextParser p("1.1.1.1:53");
|
||||||
@ -246,3 +255,66 @@ TEST_F(RuleTextParserTest, badFilterName)
|
|||||||
|
|
||||||
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorBadFilterName);
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorBadFilterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badEndOfValueBegin)
|
||||||
|
{
|
||||||
|
RuleTextParser p("[1[");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedEndOfValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badEndOfValueEnd)
|
||||||
|
{
|
||||||
|
RuleTextParser p("[1]]");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedStartOfLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badEndOfList)
|
||||||
|
{
|
||||||
|
RuleTextParser p("{1");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedEndOfList);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badEndOfValuesList)
|
||||||
|
{
|
||||||
|
RuleTextParser p("(1");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedEndOfValuesList);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badSymboOfListEnd)
|
||||||
|
{
|
||||||
|
RuleTextParser p("1}");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorUnexpectedSymboOfListEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badExtraFilterName)
|
||||||
|
{
|
||||||
|
RuleTextParser p("ip dir(1)");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorExtraFilterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RuleTextParserTest, badBadSymbol)
|
||||||
|
{
|
||||||
|
RuleTextParser p("1\b");
|
||||||
|
|
||||||
|
ASSERT_FALSE(p.parse());
|
||||||
|
|
||||||
|
ASSERT_EQ(p.errorCode(), RuleTextParser::ErrorBadSymbol);
|
||||||
|
}
|
||||||
|
@ -317,20 +317,40 @@ bool RuleTextParser::parseBracketValue(RuleCharTypes expectedSeparator)
|
|||||||
resetParsedCharTypes();
|
resetParsedCharTypes();
|
||||||
|
|
||||||
if (!nextCharType(CharValueBegin | CharLetter | CharValue,
|
if (!nextCharType(CharValueBegin | CharLetter | CharValue,
|
||||||
CharLineBreak | CharBracketEnd | expectedSeparator, extraValueEndChars))
|
CharLineBreak | CharBracketEnd | expectedSeparator, extraValueEndChars)) {
|
||||||
|
checkBracketValueEnd();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasParsedCharTypes(CharBracketEnd))
|
if (hasParsedCharTypes(CharBracketEnd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!checkBracketValuesSeparator(expectedSeparator))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const bool expectValueEnd = hasParsedCharTypes(CharValueBegin);
|
||||||
|
|
||||||
|
return parseValue(expectValueEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RuleTextParser::checkBracketValuesSeparator(RuleCharTypes expectedSeparator)
|
||||||
|
{
|
||||||
if (!hasParsedCharTypes(expectedSeparator)) {
|
if (!hasParsedCharTypes(expectedSeparator)) {
|
||||||
setError(ErrorUnexpectedEndOfValuesList, tr("Unexpected end of values list"));
|
setError(ErrorUnexpectedEndOfValuesList, tr("Unexpected end of values list"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool expectValueEnd = hasParsedCharTypes(CharValueBegin);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return parseValue(expectValueEnd);
|
bool RuleTextParser::checkBracketValueEnd()
|
||||||
|
{
|
||||||
|
if (!hasParsedCharTypes(CharBracketEnd)) {
|
||||||
|
setError(ErrorUnexpectedEndOfValuesList, tr("Unexpected end of values list"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTextParser::parseValue(bool expectValueEnd)
|
bool RuleTextParser::parseValue(bool expectValueEnd)
|
||||||
|
@ -108,6 +108,8 @@ private:
|
|||||||
|
|
||||||
void parseBracketValues();
|
void parseBracketValues();
|
||||||
bool parseBracketValue(RuleCharTypes expectedSeparator);
|
bool parseBracketValue(RuleCharTypes expectedSeparator);
|
||||||
|
bool checkBracketValuesSeparator(RuleCharTypes expectedSeparator);
|
||||||
|
bool checkBracketValueEnd();
|
||||||
bool parseValue(bool expectValueEnd);
|
bool parseValue(bool expectValueEnd);
|
||||||
bool checkValueEnd(bool &expectValueEnd);
|
bool checkValueEnd(bool &expectValueEnd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user