aboutsummaryrefslogtreecommitdiff
path: root/autotests/kentrymaptest.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2021-02-23 13:08:15 +0200
committerAhmad Samir <a.samirh78@gmail.com>2021-02-24 05:38:32 +0000
commitcae1e9b6d2ec957f8bc4643b898308a404d00a5f (patch)
tree1524789c5d560ff21af3fd54e4bec2007571965c /autotests/kentrymaptest.cpp
parent48c132be8aa983165126b0641a083848dd5c6620 (diff)
downloadkconfig-cae1e9b6d2ec957f8bc4643b898308a404d00a5f.tar.gz
kconfig-cae1e9b6d2ec957f8bc4643b898308a404d00a5f.tar.bz2
Add KEntryMap::constFindEntry() method
- This has the same logic as QMap::constFind(); less detaching and now we can use auto keyword when creating iterators and always get a const_iterator even when calling constFindEntry() on a non-const map. - Use QCOMPARE() where appropriate in the unit tests.
Diffstat (limited to 'autotests/kentrymaptest.cpp')
-rw-r--r--autotests/kentrymaptest.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/autotests/kentrymaptest.cpp b/autotests/kentrymaptest.cpp
index d571f761..899fcac1 100644
--- a/autotests/kentrymaptest.cpp
+++ b/autotests/kentrymaptest.cpp
@@ -54,21 +54,21 @@ void KEntryMapTest::testSimple()
map.setEntry(group1, key2, value2, EntryOptions());
QCOMPARE(map.size(), 3); // the group marker & 2 keys
- QVERIFY(map.findEntry(group1) != map.end());
- QVERIFY(map.findEntry(group1.toLower()) == map.end());
+ QVERIFY(map.constFindEntry(group1) != map.cend());
+ QCOMPARE(map.constFindEntry(group1.toLower()), map.cend());
- QVERIFY(map.findEntry(group1, key1) != map.end());
- QVERIFY(map.findEntry(group1, key1.toLower()) == map.end());
- QVERIFY(map.findEntry(group1, key2) != map.end());
- QVERIFY(map.findEntry(group1, key2.toUpper()) == map.end());
+ QVERIFY(map.constFindEntry(group1, key1) != map.cend());
+ QCOMPARE(map.constFindEntry(group1, key1.toLower()), map.cend());
+ QVERIFY(map.constFindEntry(group1, key2) != map.cend());
+ QCOMPARE(map.constFindEntry(group1, key2.toUpper()), map.cend());
- QByteArray found = map.findEntry(group1, key1)->mValue;
- QVERIFY(found == value1);
+ QByteArray found = map.constFindEntry(group1, key1)->mValue;
+ QCOMPARE(found, value1);
QVERIFY(found != value2);
- found = map.findEntry(group1, key2)->mValue;
+ found = map.constFindEntry(group1, key2)->mValue;
QVERIFY(found != value1);
- QVERIFY(found == value2);
+ QCOMPARE(found, value2);
}
void KEntryMapTest::testDirty()
@@ -93,16 +93,16 @@ void KEntryMapTest::testDefault()
map.setEntry(group1, key2, value2, EntryOptions());
QCOMPARE(map.size(), 4); // group marker, default1, entry1, entry2
- const KEntryMap::ConstIterator defaultEntry(map.findEntry(group1, key1, SearchDefaults));
- const KEntryMap::ConstIterator entry1(map.findEntry(group1, key1));
- const KEntryMap::ConstIterator entry2(map.findEntry(group1, key2));
+ const auto defaultEntry(map.constFindEntry(group1, key1, SearchDefaults));
+ const auto entry1(map.constFindEntry(group1, key1));
+ const auto entry2(map.constFindEntry(group1, key2));
// default set for entry1
QVERIFY(defaultEntry != map.constEnd());
QCOMPARE(defaultEntry->mValue, entry1->mValue);
// no default set for entry2
- QVERIFY(map.findEntry(group1, key2, SearchDefaults) == map.end());
+ QCOMPARE(map.constFindEntry(group1, key2, SearchDefaults), map.cend());
// change from default
map.setEntry(group1, key1, value2, EntryOptions());
@@ -131,7 +131,7 @@ void KEntryMapTest::testDelete()
map.setEntry(group1, key2, QByteArray(), EntryDeleted | EntryDirty);
QCOMPARE(map.size(), 5); // entry should still be in map, so it can override merged entries later
- QCOMPARE(map.findEntry(group1, key2)->mValue, QByteArray());
+ QCOMPARE(map.constFindEntry(group1, key2)->mValue, QByteArray());
}
void KEntryMapTest::testGlobal()
@@ -139,11 +139,11 @@ void KEntryMapTest::testGlobal()
KEntryMap map;
map.setEntry(group1, key1, value1, EntryGlobal);
- QCOMPARE(map.findEntry(group1, key1)->bGlobal, true);
+ QCOMPARE(map.constFindEntry(group1, key1)->bGlobal, true);
// this should create a new key that is not "global"
map.setEntry(group1, key1, value2, EntryOptions());
- QVERIFY(!map.findEntry(group1, key1)->bGlobal);
+ QCOMPARE(map.constFindEntry(group1, key1)->bGlobal, false);
}
void KEntryMapTest::testImmutable()
@@ -151,18 +151,18 @@ void KEntryMapTest::testImmutable()
KEntryMap map;
map.setEntry(group1, key1, value1, EntryImmutable);
- QCOMPARE(map.findEntry(group1, key1)->bImmutable, true); // verify the immutable bit was set
+ QCOMPARE(map.constFindEntry(group1, key1)->bImmutable, true); // verify the immutable bit was set
map.setEntry(group1, key1, value2, EntryOptions());
- QCOMPARE(map.findEntry(group1, key1)->mValue, value1); // verify the value didn't change
+ QCOMPARE(map.constFindEntry(group1, key1)->mValue, value1); // verify the value didn't change
map.clear();
map.setEntry(group1, QByteArray(), QByteArray(), EntryImmutable);
- QCOMPARE(map.findEntry(group1)->bImmutable, true); // verify the group is immutable
+ QCOMPARE(map.constFindEntry(group1)->bImmutable, true); // verify the group is immutable
map.setEntry(group1, key1, value1, EntryOptions()); // should be ignored since the group is immutable
- QVERIFY(map.findEntry(group1, key1) == map.end());
+ QCOMPARE(map.constFindEntry(group1, key1), map.cend());
}
void KEntryMapTest::testLocale()
@@ -173,17 +173,17 @@ void KEntryMapTest::testLocale()
KEntryMap map;
map.setEntry(group1, key1, untranslated, EntryDefault);
- QCOMPARE(map.findEntry(group1, key1)->mValue, untranslated);
- QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, untranslated); // no localized value yet
+ QCOMPARE(map.constFindEntry(group1, key1)->mValue, untranslated);
+ QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, untranslated); // no localized value yet
map.setEntry(group1, key1, translated, EntryLocalized);
- QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translated); // has localized value now
- QVERIFY(map.findEntry(group1, key1, SearchLocalized)->mValue != map.findEntry(group1, key1)->mValue);
- QCOMPARE(map.findEntry(group1, key1, SearchDefaults | SearchLocalized)->mValue, untranslated); // default should still be untranslated
+ QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translated); // has localized value now
+ QVERIFY(map.constFindEntry(group1, key1, SearchLocalized)->mValue != map.constFindEntry(group1, key1)->mValue);
+ QCOMPARE(map.constFindEntry(group1, key1, SearchDefaults | SearchLocalized)->mValue, untranslated); // default should still be untranslated
map.setEntry(group1, key1, translatedDefault, EntryDefault | EntryLocalized);
- QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translatedDefault);
+ QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translatedDefault);
map.setEntry(group1, key1, translated, EntryLocalized); // set the translated entry to a different locale
- QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translated);
+ QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translated);
}