Commit f3c67e5a authored by Laurent Montel's avatar Laurent Montel 😁

Add more autotests

parent 85a1055e
[Rules]
;toto.warning=true
;foo.debug=true
;s.critical=false
org.kde.kio.kpasswdserver KPasswdServer (KIO)
org.kde.kurifilter-ikws KUriFilter IKWS (KIO)
org.kde.kurifilter-shorturi KUriFilter Shorturi (KIO)
BluezQt BluezQt
kf5.kauth KAuth
org.kde.kio.kpasswdserver KPasswdServer (KIO)
org.kde.kurifilter-ikws KUriFilter IKWS (KIO)
org.kde.kurifilter-shorturi KUriFilter Shorturi (KIO)
BluezQt BluezQt
kf5.kauth KAuth
org.kde.kio.kpasswdserver KPasswdServer (KIO)
org.kde.kurifilter-ikws KUriFilter IKWS (KIO)
org.kde.kurifilter-shorturi KUriFilter Shorturi (KIO)
BluezQt BluezQt
kf5.kauth KAuth
[Rules]
;toto.warning=true
;foo.debug=true
;s.critical=false
......@@ -63,38 +63,33 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine()
void KDebugSettingUtilTest::shouldParseQtLoggingLine_data()
{
#if 0
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("logname");
QTest::addColumn<QString>("type");
QTest::addColumn<KDebugSettingsUtil::LoadLoggingCategory::LogTypes>("loggingtype");
QTest::addColumn<KDebugSettingsUtil::LoadLoggingCategory::LogType>("loggingtype");
QTest::addColumn<bool>("enabled");
QTest::addColumn<bool>("valid");
QTest::newRow("empty") << QString() << QString() << QString() << LoggingCategory::Info << true << false;
QTest::newRow("valid") << QStringLiteral("toto=true") << QStringLiteral("toto") << QString() << KDebugSettingsUtil::LoadLoggingCategory::Info << true << true;
QTest::newRow("validdisabled") << QStringLiteral("toto=false") << QStringLiteral("toto") << QString() << KDebugSettingsUtil::LoadLoggingCategory::Info << false << true;
QTest::newRow("empty") << QString() << QString() << KDebugSettingsUtil::LoadLoggingCategory::Unknown << false << false;
QTest::newRow("valid") << QStringLiteral("toto=true") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::All << true << true;
QTest::newRow("validdisabled") << QStringLiteral("toto=false") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::All << false << true;
QTest::newRow("validdisabledwithtypewarning") << QStringLiteral("toto.warning=false") << QStringLiteral("toto") << QStringLiteral("warning") << KDebugSettingsUtil::LoadLoggingCategory::Info << false << true;
QTest::newRow("validenabledwithtypewarning") << QStringLiteral("toto.warning=true") << QStringLiteral("toto") << QStringLiteral("warning") << KDebugSettingsUtil::LoadLoggingCategory::Info << true << true;
QTest::newRow("validdisabledwithtypewarning") << QStringLiteral("toto.warning=false") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Warning << false << true;
QTest::newRow("validenabledwithtypewarning") << QStringLiteral("toto.warning=true") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Warning << true << true;
QTest::newRow("validdisabledwithtypecritical") << QStringLiteral("toto.critical=false") << QStringLiteral("toto") << QStringLiteral("critical") << KDebugSettingsUtil::LoadLoggingCategory::Info << false << true;
QTest::newRow("validenabledwithtypecritical") << QStringLiteral("toto.critical=true") << QStringLiteral("toto") << QStringLiteral("critical") << KDebugSettingsUtil::LoadLoggingCategory::Info << true << true;
QTest::newRow("validdisabledwithtypecritical") << QStringLiteral("toto.critical=false") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Critical << false << true;
QTest::newRow("validenabledwithtypecritical") << QStringLiteral("toto.critical=true") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Critical << true << true;
QTest::newRow("validdisabledwithtypedebug") << QStringLiteral("toto.debug=false") << QStringLiteral("toto") << QStringLiteral("debug") << KDebugSettingsUtil::LoadLoggingCategory::Info << false << true;
QTest::newRow("validenabledwithtypedebug") << QStringLiteral("toto.debug=true") << QStringLiteral("toto") << QStringLiteral("debug") << KDebugSettingsUtil::LoadLoggingCategory::Info << true << true;
QTest::newRow("validdisabledwithtypedebug") << QStringLiteral("toto.debug=false") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Debug << false << true;
QTest::newRow("validenabledwithtypedebug") << QStringLiteral("toto.debug=true") << QStringLiteral("toto") << KDebugSettingsUtil::LoadLoggingCategory::Debug << true << true;
QTest::newRow("invalid") << QStringLiteral("dd") << QString() << QString() << KDebugSettingsUtil::LoadLoggingCategory::Info << true << false;
QTest::newRow("invalidWithoutEnabledDisabled") << QStringLiteral("dd=") << QString() << QString() << KDebugSettingsUtil::LoadLoggingCategory::Info << true << false;
#endif
QTest::newRow("invalid") << QStringLiteral("dd") << QString() << KDebugSettingsUtil::LoadLoggingCategory::Unknown << false << false;
QTest::newRow("invalidWithoutEnabledDisabled") << QStringLiteral("dd=")<< QStringLiteral("dd") << KDebugSettingsUtil::LoadLoggingCategory::All << false << true;
}
void KDebugSettingUtilTest::shouldParseQtLoggingLine()
{
#if 0 //FIXME
QFETCH(QString, input);
QFETCH(QString, logname);
QFETCH(QString, type);
QFETCH(KDebugSettingsUtil::LoadLoggingCategory::LogTypes, loggingtype);
QFETCH(KDebugSettingsUtil::LoadLoggingCategory::LogType, loggingtype);
QFETCH(bool, enabled);
QFETCH(bool, valid);
KDebugSettingsUtil::LoadLoggingCategory result;
......@@ -102,9 +97,29 @@ void KDebugSettingUtilTest::shouldParseQtLoggingLine()
result.enabled = enabled;
result.type = loggingtype;
const KDebugSettingsUtil::LoadLoggingCategory cat = KDebugSettingsUtil::parseLineLoggingQtCategory(input);
QCOMPARE(cat, result);
QCOMPARE(cat.isValid(), valid);
#endif
QCOMPARE(cat, result);
}
void KDebugSettingUtilTest::shouldReadLoadKdeCategories_data()
{
QTest::addColumn<QString>("filename");
QTest::addColumn<int>("numberofcategories");
QTest::newRow("empty") << QStringLiteral("empty.categories") << 0;
QTest::newRow("correctlist") << QStringLiteral("correct.categories") << 5;
QTest::newRow("withduplicate") << QStringLiteral("duplicates.categories") << 5;
}
void KDebugSettingUtilTest::shouldReadLoadKdeCategories()
{
QFETCH(QString, filename);
QFETCH(int, numberofcategories);
const QString path = QString(QLatin1String(KDEBUGSETTINGS_DATA_DIR) + QLatin1Char('/') + filename);
QFile file(path);
QVERIFY(file.exists());
KdeLoggingCategory::List lst;
KDebugSettingsUtil::readLoggingCategories(path, lst, true);
QCOMPARE(lst.count(), numberofcategories);
}
QTEST_GUILESS_MAIN(KDebugSettingUtilTest)
......@@ -35,6 +35,10 @@ private Q_SLOTS:
void shouldParseQtLoggingLine_data();
void shouldParseQtLoggingLine();
void shouldReadLoadKdeCategories_data();
void shouldReadLoadKdeCategories();
};
#endif // KDEBUGSETTINGUTILTEST_H
......@@ -49,7 +49,11 @@ void LoadCategoriesJobTest::shouldReadRules_data()
QTest::addColumn<QString>("filename");
QTest::addColumn<KdeLoggingCategory::List>("listKdeLoggingCategories");
QTest::addColumn<bool>("foundoverriderules");
QTest::newRow("empty") << QString(QLatin1String(KDEBUGSETTINGS_DATA_DIR) + QLatin1Char('/') + QStringLiteral("emptyrulefiles.ini")) << KdeLoggingCategory::List() << false;
QTest::addColumn<LoggingCategory::List>("customcategories");
QTest::addColumn<LoggingCategory::List>("qtkdecategories");
QTest::newRow("empty") << QStringLiteral("emptyrulefiles.ini") << KdeLoggingCategory::List() << false << LoggingCategory::List() << LoggingCategory::List();
QTest::newRow("commentedlines") << QStringLiteral("commentedrulefiles.ini") << KdeLoggingCategory::List() << false << LoggingCategory::List() << LoggingCategory::List();
QTest::newRow("rulesbeforesection") << QStringLiteral("rulebeforerulessectionfiles.ini") << KdeLoggingCategory::List() << false << LoggingCategory::List() << LoggingCategory::List();
}
void LoadCategoriesJobTest::shouldReadRules()
......@@ -57,13 +61,20 @@ void LoadCategoriesJobTest::shouldReadRules()
QFETCH(QString, filename);
QFETCH(KdeLoggingCategory::List, listKdeLoggingCategories);
QFETCH(bool, foundoverriderules);
QFile file(filename);
QVERIFY(file.exists());
QFETCH(LoggingCategory::List, customcategories);
QFETCH(LoggingCategory::List, qtkdecategories);
LoadCategoriesJob job;
job.setFileName(filename);
QVERIFY(job.customCategories().isEmpty());
const QString path = QString(QLatin1String(KDEBUGSETTINGS_DATA_DIR) + QLatin1Char('/') + filename);
QFile file(path);
QVERIFY(file.exists());
job.setFileName(path);
job.setCategories(listKdeLoggingCategories);
job.start();
qDebug() << "job.customCategories()"<<job.customCategories().count();
QCOMPARE(job.customCategories(), customcategories);
QCOMPARE(job.foundOverrideRule(), foundoverriderules);
QVERIFY(job.qtKdeCategories().isEmpty());
QCOMPARE(job.qtKdeCategories(), qtkdecategories);
}
......
......@@ -61,7 +61,7 @@ void LoggingCategoryTest::shouldCreateRules_data()
QTest::addColumn<LoggingCategory::LoggingType>("loggingType");
QTest::addColumn<QString>("result");
QTest::newRow("all") << QStringLiteral("foo") << LoggingCategory::All << QStringLiteral("foo=true");
QTest::newRow("all") << QStringLiteral("foo") << LoggingCategory::All << QStringLiteral("foo=true\n");
QTest::newRow("debug") << QStringLiteral("foo") << LoggingCategory::Debug << QStringLiteral("foo.info=false\nfoo.debug=true\nfoo.warning=true\nfoo.critical=true\n");
QTest::newRow("info") << QStringLiteral("foo") << LoggingCategory::Info << QStringLiteral("foo.info=true\nfoo.warning=true\nfoo.critical=true\nfoo.debug=false\n");
QTest::newRow("critical") << QStringLiteral("foo") << LoggingCategory::Critical << QStringLiteral("foo.info=false\nfoo.debug=false\nfoo.warning=false\nfoo.critical=true\n");
......
......@@ -149,7 +149,8 @@ KDebugSettingsUtil::LoadLoggingCategory KDebugSettingsUtil::parseLineLoggingQtCa
cat.logName = p;
cat.type = LoadLoggingCategory::All;
}
} else {
cat.enabled = false;
}
return cat;
}
......@@ -212,6 +213,10 @@ LoggingCategory::List KDebugSettingsUtil::readLoggingQtCategories(const QString
(value.type & LoadLoggingCategory::Warning) &&
(value.type & LoadLoggingCategory::Critical)) {
cat.loggingType = LoggingCategory::All;
} else if ((value.type & LoadLoggingCategory::Debug) &&
(value.type & LoadLoggingCategory::Warning) &&
(value.type & LoadLoggingCategory::Critical)) {
cat.loggingType = LoggingCategory::Debug;
} else if ((value.type & LoadLoggingCategory::Info) &&
(value.type & LoadLoggingCategory::Warning) &&
(value.type & LoadLoggingCategory::Critical)) {
......@@ -221,9 +226,11 @@ LoggingCategory::List KDebugSettingsUtil::readLoggingQtCategories(const QString
cat.loggingType = LoggingCategory::Warning;
} else if (value.type & LoadLoggingCategory::Critical) {
cat.loggingType = LoggingCategory::Critical;
} else if (value.type == LoadLoggingCategory::Unknown) {
} else if (value.type & LoadLoggingCategory::Unknown) {
qDebug()<<" OFF "<< cat.logName;
cat.loggingType = LoggingCategory::Off;
}
//qDebug()<<"cat.loggingType"<<cat.loggingType;
categories.append(cat);
}
......
......@@ -22,6 +22,8 @@
#define KDEBUGSETTINGSUTIL_H
#include <QString>
#include <QObject>
#include <QDebug>
#include "kdeloggingcategory.h"
#include "loggingcategory.h"
namespace KDebugSettingsUtil
......@@ -36,21 +38,30 @@ struct LoadLoggingCategory {
}
enum LogType {
Unknown = 0,
Info = 1,
Warning = 2,
Debug = 4,
Critical = 8,
All = 16
Unknown = 1,
Info = 2,
Warning = 4,
Debug = 8,
Critical = 16,
All = 32
};
Q_FLAGS(LogTypes)
Q_DECLARE_FLAGS(LogTypes, LogType)
bool isValid() const
{
return (type != Unknown);
return !logName.isEmpty();
}
bool operator ==(const LoadLoggingCategory &other) const
{
qDebug()<< " enabled "<< enabled << " other.enabled :"<<other.enabled;
qDebug()<< " logname "<< logName << " other.logName :"<<other.logName;
qDebug()<<" type"<<type << " other.type "<< other.type;
return (enabled == other.enabled) &&
(type == other.type) &&
(logName == other.logName);
}
bool enabled;
LogTypes type;
QString logName;
......@@ -64,5 +75,6 @@ KdeLoggingCategory::List readLoggingCategoriesForInserting(const QString &filena
LoggingCategory::List readLoggingQtCategories(const QString &filename);
KDebugSettingsUtil::LoadLoggingCategory parseLineLoggingQtCategory(const QString &line);
}
Q_DECLARE_METATYPE(KDebugSettingsUtil::LoadLoggingCategory::LogType)
#endif // KDEBUGSETTINGSUTIL_H
......@@ -51,10 +51,12 @@ void LoadCategoriesJob::start()
if (!envPath.isEmpty()) {
const int number(mCategories.count());
LoggingCategory::List qtCategories = KDebugSettingsUtil::readLoggingQtCategories(envPath);
qDebug()<<" qtCategories"<<qtCategories.count();
for (int i = 0; i < number; ++i) {
KdeLoggingCategory kdeCat = mCategories.at(i);
bool foundkde = false;
Q_FOREACH (const LoggingCategory &cat, qtCategories) {
qDebug()<<" cat.logName"<<cat.logName << "kdeCat.logName"<<kdeCat.logName;
if (cat.logName == kdeCat.logName) {
//TODO optimization ?
LoggingCategory tmp(cat);
......@@ -76,6 +78,7 @@ void LoadCategoriesJob::start()
}
}
//FIXME
qDebug()<<" KEEP "<< qtCategories.count();
Q_FOREACH (const LoggingCategory &cat, qtCategories) {
LoggingCategory tmp;
tmp.description = cat.description;
......
......@@ -45,7 +45,7 @@ QString LoggingCategory::createRule()
QString str;
switch (loggingType) {
case All: {
str = logName + QLatin1String("=true");
str = logName + QLatin1String("=true\n");
break;
}
case Info: {
......
......@@ -47,6 +47,7 @@ struct LoggingCategory {
bool enabled;
};
Q_DECLARE_TYPEINFO(LoggingCategory, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(LoggingCategory)
Q_DECLARE_METATYPE(LoggingCategory::LoggingType)
#endif // LOGGINGCATEGORY_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment