summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-18 09:41:30 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-04-21 07:16:33 +0000
commitdfc2a4a537a053b2c9157d48090637a0b77c4485 (patch)
tree0b58839664652430cd923f74d0cc0c910fd88fa6 /tests/auto
parent45104dff04f938cc5d40698fca518b317b53083e (diff)
QLoggingRegistry: remove rules vector
It only contained a concatenation of the individual rule sets, probably to fix their order in a central place, as well as simplifying iteration in defaultCategoryFilter(). Fix these two issues differently, but introducing a RuleSet enum that lists rule sets in the order in which they should be applied by defaultCategoryFilter(), and turn individual rule sets vectors into a C array of vectors. This enables two nested loops in defaultCategoryFilter to replace the one loop over 'rules'. Apart from building up 'rules' in updateRules(), this was the only access to that member. That leaves updateRules() with just the task of running defaultCategoryFilter() on the new rule sets. Consequently, a call to updateRules() can now replace the identical loop in installFilter(). Performance should not suffer. Iterating over a fixed-size array of vectors is hardly any slower than iterating over a single vector, and while the construction of 'rules' was probably a one-off task in most programs, this way of keeping the rules also saves memory because rules are not kept in two different vectors. It is also more maintainable, of course. Change-Id: Ibc132d096c8137dd02b034752646212e51208637 Reviewed-by: Kai Koehne <kai.koehne@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
index 0a74dc64c0..1643eed3d2 100644
--- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
+++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp
@@ -202,18 +202,15 @@ private slots:
QLoggingRegistry registry;
registry.init();
- QCOMPARE(registry.apiRules.size(), 0);
- QCOMPARE(registry.configRules.size(), 0);
- QCOMPARE(registry.envRules.size(), 1);
-
- QCOMPARE(registry.rules.size(), 1);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::ApiRules].size(), 0);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 0);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].size(), 1);
// check that QT_LOGGING_RULES take precedence
qputenv("QT_LOGGING_RULES", "Digia.*=true");
registry.init();
- QCOMPARE(registry.envRules.size(), 2);
- QCOMPARE(registry.envRules.at(1).enabled, true);
- QCOMPARE(registry.rules.size(), 2);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].size(), 2);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].at(1).enabled, true);
}
void QLoggingRegistry_config()
@@ -238,7 +235,7 @@ private slots:
QLoggingRegistry registry;
registry.init();
- QCOMPARE(registry.configRules.size(), 1);
+ QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 1);
// remove file again
QVERIFY(file.remove());
@@ -260,10 +257,9 @@ private slots:
QLoggingRegistry *registry = QLoggingRegistry::instance();
// empty all rules , check default
- registry->rules.clear();
- registry->apiRules.clear();
- registry->configRules.clear();
- registry->envRules.clear();
+ registry->ruleSets[QLoggingRegistry::ApiRules].clear();
+ registry->ruleSets[QLoggingRegistry::ConfigRules].clear();
+ registry->ruleSets[QLoggingRegistry::EnvironmentRules].clear();
registry->updateRules();
QVERIFY(cat.isWarningEnabled());
@@ -271,7 +267,7 @@ private slots:
// set Config rule
QLoggingSettingsParser parser;
parser.setContent("[Rules]\nDigia.*=false");
- registry->configRules=parser.rules();
+ registry->ruleSets[QLoggingRegistry::ConfigRules] = parser.rules();
registry->updateRules();
QVERIFY(!cat.isWarningEnabled());
@@ -283,7 +279,7 @@ private slots:
// set Env rule, should overwrite Config one
parser.setContent("Digia.*=false");
- registry->envRules=parser.rules();
+ registry->ruleSets[QLoggingRegistry::EnvironmentRules] = parser.rules();
registry->updateRules();
QVERIFY(!cat.isWarningEnabled());