PatternFormatter fix, added test

This commit is contained in:
Guenter Obiltschnig 2015-08-20 20:23:13 +02:00
parent fafe691a04
commit ec71e76f0a
2 changed files with 25 additions and 5 deletions

View File

@ -256,13 +256,18 @@ void PatternFormatter::parsePriorityNames()
{
_priorities[i] = priorities[i];
}
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
if (st.count() == 8)
if (!_priorityNames.empty())
{
for (int i = 1; i <= 8; i++)
_priorities[i] = st[i - 1];
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
if (st.count() == 8)
{
for (int i = 1; i <= 8; i++)
{
_priorities[i] = st[i - 1];
}
}
else throw Poco::SyntaxException("priorityNames property must specify a comma-separated list of 8 property names");
}
else throw Poco::SyntaxException("priorityNames property must specify a comma-separated list of 8 property names");
}

View File

@ -93,6 +93,21 @@ void PatternFormatterTest::testPatternFormatter()
fmt.setProperty("pattern", "start %v[8] end");
fmt.format(msg, result);
assert (result == "start stSource end");
result.clear();
fmt.setProperty("pattern", "%p");
fmt.setProperty("priorityNames", "FAT, CRI, ERR, WRN, NTC, INF, DBG, TRC");
fmt.format(msg, result);
assert (result == "ERR");
try
{
fmt.setProperty("priorityNames", "FAT, CRI,");
fail("invalid value, must throw");
}
catch (Poco::SyntaxException&)
{
}
}