File indexing completed on 2024-04-21 14:53:11

0001 /*
0002     SPDX-License-Identifier: BSD-3-Clause
0003 */
0004 
0005 #include <QCoreApplication>
0006 
0007 #include "log1.h"
0008 #include "log2.h"
0009 #include "log3.h"
0010 
0011 #include <iostream>
0012 
0013 int main(int argc, char **argv)
0014 {
0015     // Make the unit test more reliable on system which have these env vars set
0016     qunsetenv("QT_LOGGING_CONF");
0017     qunsetenv("QT_LOGGING_RULES");
0018 
0019     QCoreApplication qapp(argc, argv);
0020 
0021     bool success = true;
0022 
0023     // NB: we cannot test against QtInfoMsg, as that (a) does not exist before
0024     // Qt 5.5, and (b) has incorrect semantics in Qt 5.5, in that it is
0025     // treated as more severe than QtCriticalMsg.
0026 
0027     if (log1().categoryName() != QLatin1String("log.one")) {
0028         qWarning("log1 category was \"%s\", expected \"log.one\"", log1().categoryName());
0029         success = false;
0030     }
0031     if (log1().isDebugEnabled()) {
0032         qWarning("log1 debug messages were enabled");
0033         success = false;
0034     }
0035     if (!log1().isWarningEnabled()) {
0036         qWarning("log1 warning messages were not enabled");
0037         success = false;
0038     }
0039 
0040     if (foo::bar::log2().categoryName() != QLatin1String("log.two")) {
0041         qWarning("log2 category was \"%s\", expected \"log.two\"", foo::bar::log2().categoryName());
0042         success = false;
0043     }
0044     if (foo::bar::log2().isDebugEnabled()) {
0045         qWarning("log2 debug messages were enabled");
0046         success = false;
0047     }
0048     if (!foo::bar::log2().isWarningEnabled()) {
0049         qWarning("log2 warning messages were not enabled");
0050         success = false;
0051     }
0052 
0053     if (log3().categoryName() != QLatin1String("three")) {
0054         qWarning("log3 category was \"%s\", expected \"three\"", log3().categoryName());
0055         success = false;
0056     }
0057     if (log3().isDebugEnabled()) {
0058         qWarning("log3 debug messages were enabled");
0059         success = false;
0060     }
0061     if (log3().isWarningEnabled()) {
0062         qWarning("log3 warning messages were enabled");
0063         success = false;
0064     }
0065     if (!log3().isCriticalEnabled()) {
0066         qWarning("log3 critical messages were not enabled");
0067         success = false;
0068     }
0069 
0070     return success ? 0 : 1;
0071 }