mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
PatternFormatter fix, added test
This commit is contained in:
@@ -256,14 +256,19 @@ void PatternFormatter::parsePriorityNames()
|
|||||||
{
|
{
|
||||||
_priorities[i] = priorities[i];
|
_priorities[i] = priorities[i];
|
||||||
}
|
}
|
||||||
|
if (!_priorityNames.empty())
|
||||||
|
{
|
||||||
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
|
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
|
||||||
if (st.count() == 8)
|
if (st.count() == 8)
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= 8; i++)
|
for (int i = 1; i <= 8; i++)
|
||||||
|
{
|
||||||
_priorities[i] = st[i - 1];
|
_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");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string& PatternFormatter::getPriorityName(int prio)
|
const std::string& PatternFormatter::getPriorityName(int prio)
|
||||||
|
|||||||
@@ -93,6 +93,21 @@ void PatternFormatterTest::testPatternFormatter()
|
|||||||
fmt.setProperty("pattern", "start %v[8] end");
|
fmt.setProperty("pattern", "start %v[8] end");
|
||||||
fmt.format(msg, result);
|
fmt.format(msg, result);
|
||||||
assert (result == "start stSource end");
|
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&)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user