mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:36:08 +00:00
Tests: tst_ruletextparser.h: Add "lineIpPortList" test
This commit is contained in:
parent
7731f47cc4
commit
5c73dea22f
@ -64,3 +64,38 @@ TEST_F(RuleTextParserTest, lineIpPort)
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "53" }));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, lineIpPortList)
|
||||
{
|
||||
RuleTextParser p("1.1.1.1:53\n"
|
||||
"2.2.2.2:64\n"
|
||||
"3.3.3.3:75\n");
|
||||
|
||||
ASSERT_TRUE(p.parse());
|
||||
|
||||
ASSERT_EQ(p.ruleFilters().size(), 10);
|
||||
|
||||
// Check IP
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[5];
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "2.2.2.2" }));
|
||||
}
|
||||
|
||||
// Check Port
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[6];
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "64" }));
|
||||
}
|
||||
|
||||
// Check IP
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[8];
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "3.3.3.3" }));
|
||||
}
|
||||
|
||||
// Check Port
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[9];
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "75" }));
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ RuleCharType processChar(const QChar c, const char *extraChars = nullptr)
|
||||
return CharDigit;
|
||||
}
|
||||
|
||||
if (c == '\n') {
|
||||
return CharNewLine;
|
||||
}
|
||||
|
||||
if (c.isSpace()) {
|
||||
return CharSpace;
|
||||
}
|
||||
@ -414,20 +418,7 @@ bool RuleTextParser::parseChars(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ungetParsedChar();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuleTextParser::ungetParsedChar()
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
ungetChar();
|
||||
}
|
||||
return !hasError();
|
||||
}
|
||||
|
||||
bool RuleTextParser::nextCharType(
|
||||
@ -440,7 +431,7 @@ bool RuleTextParser::nextCharType(
|
||||
m_charType = CharNone;
|
||||
|
||||
while (!isEmpty()) {
|
||||
const QChar c = *m_p++;
|
||||
const QChar c = *m_p;
|
||||
|
||||
m_charType = getCharType(m_charType, c, extraChars);
|
||||
|
||||
@ -449,6 +440,8 @@ bool RuleTextParser::nextCharType(
|
||||
return false;
|
||||
}
|
||||
|
||||
++m_p;
|
||||
|
||||
m_parsedCharTypes |= m_charType;
|
||||
|
||||
if ((m_charType & skipCharTypes) == 0)
|
||||
|
@ -119,8 +119,6 @@ private:
|
||||
bool parseChars(RuleCharTypes expectedCharTypes, RuleCharTypes skipCharTypes,
|
||||
const char *extraChars = nullptr);
|
||||
|
||||
void ungetParsedChar();
|
||||
|
||||
bool nextCharType(RuleCharTypes expectedCharTypes, RuleCharTypes skipCharTypes,
|
||||
const char *extraChars = nullptr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user