summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@kde.org>2015-08-03 10:37:19 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-08-03 14:40:19 +0000
commit8fdd1e3867019fc62ee2bba3c8a892d8e701f8ed (patch)
treef4e0707e870e57d6602a5fd69f6a8dc49918574d
parent5ba3309703bccc745c1c56ab8fe28529285aaca4 (diff)
QLoggingCategory: fix default severity in Q_LOGGING_CATEGORY macro
[ChangeLog][QtCore][QLoggingCategory] Fixed behavior of default severity passed to constructor or Q_LOGGING_CATEGORY with regards to QtInfoMsg, which was previously treated as being more severe than QtFatalMsg. This is because the code was using the numeric value of QtMsgType as a proxy for severity (via the <= operator), but the value of QtInfoMsg is greater than QtFatalMsg. Instead, the severity ordering must be dealt with explicitly. Change-Id: I5f178afc735221b00cb67c2cea4fa964bd9079ce Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
-rw-r--r--src/corelib/io/qloggingregistry.cpp8
-rw-r--r--tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp11
2 files changed, 16 insertions, 3 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index 11fe32529f..880e567562 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -398,10 +398,12 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
Q_ASSERT(reg->categories.contains(cat));
QtMsgType enableForLevel = reg->categories.value(cat);
+ // NB: note that the numeric values of the Qt*Msg constants are
+ // not in severity order.
bool debug = (enableForLevel == QtDebugMsg);
- bool info = (enableForLevel <= QtInfoMsg);
- bool warning = (enableForLevel <= QtWarningMsg);
- bool critical = (enableForLevel <= QtCriticalMsg);
+ bool info = debug || (enableForLevel == QtInfoMsg);
+ bool warning = info || (enableForLevel == QtWarningMsg);
+ bool critical = warning || (enableForLevel == QtCriticalMsg);
// hard-wired implementation of
// qt.*.debug=false
diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp
index deef9eecbf..0f2cfd406d 100644
--- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp
+++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp
@@ -376,6 +376,7 @@ private slots:
#ifdef Q_COMPILER_VARIADIC_MACROS
Q_LOGGING_CATEGORY(TST_MACRO_2, "tst.macro.2", QtDebugMsg)
Q_LOGGING_CATEGORY(TST_MACRO_3, "tst.macro.3", QtFatalMsg)
+ Q_LOGGING_CATEGORY(TST_MACRO_4, "tst.macro.4", QtInfoMsg)
#endif
void QLoggingCategoryMacro()
@@ -383,6 +384,7 @@ private slots:
const QLoggingCategory &cat1 = TST_MACRO_1();
QCOMPARE(cat1.categoryName(), "tst.macro.1");
QCOMPARE(cat1.isDebugEnabled(), true);
+ QCOMPARE(cat1.isInfoEnabled(), true);
QCOMPARE(cat1.isWarningEnabled(), true);
QCOMPARE(cat1.isCriticalEnabled(), true);
@@ -390,14 +392,23 @@ private slots:
const QLoggingCategory &cat2 = TST_MACRO_2();
QCOMPARE(cat2.categoryName(), "tst.macro.2");
QCOMPARE(cat2.isDebugEnabled(), true);
+ QCOMPARE(cat2.isInfoEnabled(), true);
QCOMPARE(cat2.isWarningEnabled(), true);
QCOMPARE(cat2.isCriticalEnabled(), true);
const QLoggingCategory &cat3 = TST_MACRO_3();
QCOMPARE(cat3.categoryName(), "tst.macro.3");
QCOMPARE(cat3.isDebugEnabled(), false);
+ QCOMPARE(cat3.isInfoEnabled(), false);
QCOMPARE(cat3.isWarningEnabled(), false);
QCOMPARE(cat3.isCriticalEnabled(), false);
+
+ const QLoggingCategory &cat4 = TST_MACRO_4();
+ QCOMPARE(cat4.categoryName(), "tst.macro.4");
+ QCOMPARE(cat4.isDebugEnabled(), false);
+ QCOMPARE(cat4.isInfoEnabled(), true);
+ QCOMPARE(cat4.isWarningEnabled(), true);
+ QCOMPARE(cat4.isCriticalEnabled(), true);
#endif
}