summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@digia.com>2014-02-21 11:39:12 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-13 13:26:14 +0100
commitb3871dc8049819ae3e095555f451457567eb4ee3 (patch)
tree8708c19f75e3022ff25ef74047c051b52c1a9682 /tests
parentf6d0c67d30ef1c22b086641e8d1288e1baaa1663 (diff)
Make parsing of categories in logging rules consistent.
The documentation says that the left side of a logging rule has the syntax <category>[.<type>] with optional wildcard '*' as the first or the last character (or at both positions. However, so far we didn't allow qt.*.debug But what we did allow is implicit dropping of trailing '.', e.g. qt.* matched also 'qt' Fix these by splitting up the '.type' in advance, and then do string matching only on the 'real' category names. Change-Id: Iab50ad0fc673464e870f5ab8dfb3245d829b3107 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
index dc6f16828b..56545bb909 100644
--- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
+++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
@@ -45,6 +45,13 @@
#include <QtCore/private/qloggingregistry_p.h>
QT_USE_NAMESPACE
+enum LoggingRuleState {
+ Invalid,
+ Match,
+ NoMatch
+};
+Q_DECLARE_METATYPE(LoggingRuleState);
+Q_DECLARE_METATYPE(QtMsgType);
class tst_QLoggingRegistry : public QObject
{
@@ -59,6 +66,113 @@ private slots:
qunsetenv("QT_LOGGING_CONF");
}
+ void QLoggingRule_parse_data()
+ {
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QString>("category");
+ QTest::addColumn<QtMsgType>("msgType");
+ QTest::addColumn<LoggingRuleState>("result");
+
+ // _empty_ should match (only) _empty_
+ QTest::newRow("_empty_-_empty_")
+ << QString("") << QString("") << QtDebugMsg << Match;
+ QTest::newRow("_empty_-default")
+ << QString("") << QString("default") << QtDebugMsg << NoMatch;
+ QTest::newRow(".debug-_empty_")
+ << QString(".debug") << QString("") << QtDebugMsg << Match;
+ QTest::newRow(".warning-default")
+ << QString(".warning") << QString("default") << QtDebugMsg << NoMatch;
+
+ // literal should match only literal
+ QTest::newRow("qt-qt")
+ << QString("qt") << QString("qt") << QtDebugMsg << Match;
+ QTest::newRow("qt-_empty_")
+ << QString("qt") << QString("") << QtDebugMsg << NoMatch;
+ QTest::newRow("qt-qtx")
+ << QString("qt") << QString("qtx") << QtDebugMsg << NoMatch;
+ QTest::newRow("qt-qt.io")
+ << QString("qt") << QString("qt.io") << QtDebugMsg << NoMatch;
+ QTest::newRow("qt.debug-qt")
+ << QString("qt.debug") << QString("qt") << QtDebugMsg << Match;
+ QTest::newRow("qt.critical-qt")
+ << QString("qt.critical") << QString("qt") << QtDebugMsg << NoMatch;
+
+ // * should match everything
+ QTest::newRow("_star_-qt.io.debug")
+ << QString("*") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_-qt.io.warning")
+ << QString("*") << QString("qt.io") << QtWarningMsg << Match;
+ QTest::newRow("_star_-qt.io.critical")
+ << QString("*") << QString("qt.io") << QtCriticalMsg << Match;
+ QTest::newRow("_star_-_empty_")
+ << QString("*") << QString("") << QtDebugMsg << Match;
+ QTest::newRow("_star_.debug-qt.io")
+ << QString("*.debug") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_.warning-qt.io")
+ << QString("*.warning") << QString("qt.io") << QtDebugMsg << NoMatch;
+
+ // qt.* should match everything starting with 'qt.'
+ QTest::newRow("qt._star_-qt.io")
+ << QString("qt.*") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("qt._star_-qt")
+ << QString("qt.*") << QString("qt") << QtDebugMsg << NoMatch;
+ QTest::newRow("qt__star_-qt")
+ << QString("qt*") << QString("qt") << QtDebugMsg << Match;
+ QTest::newRow("qt._star_-qt.io.fs")
+ << QString("qt.*") << QString("qt.io.fs") << QtDebugMsg << Match;
+ QTest::newRow("qt._star_.debug-qt.io.fs")
+ << QString("qt.*.debug") << QString("qt.io.fs") << QtDebugMsg << Match;
+ QTest::newRow("qt._star_.warning-qt.io.fs")
+ << QString("qt.*.warning") << QString("qt.io.fs") << QtDebugMsg << NoMatch;
+
+ // *.io should match everything ending with .io
+ QTest::newRow("_star_.io-qt.io")
+ << QString("*.io") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_io-qt.io")
+ << QString("*io") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_.io-io")
+ << QString("*.io") << QString("io") << QtDebugMsg << NoMatch;
+ QTest::newRow("_star_io-io")
+ << QString("*io") << QString("io") << QtDebugMsg << Match;
+ QTest::newRow("_star_.io-qt.ios")
+ << QString("*.io") << QString("qt.ios") << QtDebugMsg << NoMatch;
+ QTest::newRow("_star_.io-qt.io.x")
+ << QString("*.io") << QString("qt.io.x") << QtDebugMsg << NoMatch;
+ QTest::newRow("_star_.io.debug-qt.io")
+ << QString("*.io.debug") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_.io.warning-qt.io")
+ << QString("*.io.warning") << QString("qt.io") << QtDebugMsg << NoMatch;
+
+ // *qt* should match everything that contains 'qt'
+ QTest::newRow("_star_qt_star_-qt.core.io")
+ << QString("*qt*") << QString("qt.core.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_qt_star_-default")
+ << QString("*qt*") << QString("default") << QtDebugMsg << NoMatch;
+ QTest::newRow("_star_qt._star_.debug-qt.io")
+ << QString("*qt.*.debug") << QString("qt.io") << QtDebugMsg << Match;
+ QTest::newRow("_star_.qt._star_.warning-qt.io")
+ << QString("*.qt.*.warning") << QString("qt.io") << QtDebugMsg << NoMatch;
+ }
+
+ void QLoggingRule_parse()
+ {
+ QFETCH(QString, pattern);
+ QFETCH(QString, category);
+ QFETCH(QtMsgType, msgType);
+ QFETCH(LoggingRuleState, result);
+
+ QLoggingRule rule(pattern, true);
+ LoggingRuleState state = Invalid;
+ if (rule.flags != QLoggingRule::Invalid) {
+ switch (rule.pass(category, msgType)) {
+ case -1: QFAIL("Shoudn't happen, we set pattern to true"); break;
+ case 0: state = NoMatch; break;
+ case 1: state = Match; break;
+ }
+ }
+ QCOMPARE(state, result);
+ }
+
void QLoggingSettingsParser_iniStyle()
{
//