diff options
Diffstat (limited to 'tests/auto/tools/tst_tools.cpp')
-rw-r--r-- | tests/auto/tools/tst_tools.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/tools/tst_tools.cpp b/tests/auto/tools/tst_tools.cpp index 92e0978b5..894cfdcf6 100644 --- a/tests/auto/tools/tst_tools.cpp +++ b/tests/auto/tools/tst_tools.cpp @@ -68,6 +68,16 @@ using namespace qbs; using namespace qbs::Internal; +namespace std { +template<typename T> struct hash<std::vector<T>> +{ + std::size_t operator()(const std::vector<T> &v) const noexcept + { + return hashRange(v); + } +}; +} // namespace std + TestTools::TestTools(Settings *settings) : m_settings(settings), testDataDir(testWorkDir("tools")) { @@ -1299,6 +1309,40 @@ void TestTools::stringutils_trimmed() QCOMPARE(trimmed(std::move(a)), std::string("a")); } +void TestTools::hash_tuple() +{ + using Key = std::tuple<int, int>; + + Key key0{0, 5}; + Key key1{10, 20}; + Key key2{30, 40}; + + std::unordered_map<Key, int> map; + map.insert({key1, 1}); + map.insert({key2, 2}); + + QCOMPARE(map[key0], 0); + QCOMPARE(map[key1], 1); + QCOMPARE(map[key2], 2); +} + +void TestTools::hash_range() +{ + using Key = std::vector<int>; + + Key key0; + Key key1{1}; + Key key2{1, 2}; + + std::unordered_map<Key, int> map; + map.insert({key1, 1}); + map.insert({key2, 2}); + + QCOMPARE(map[key0], 0); + QCOMPARE(map[key1], 1); + QCOMPARE(map[key2], 2); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); |