aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/tools/tst_tools.cpp44
-rw-r--r--tests/auto/tools/tst_tools.h3
2 files changed, 47 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);
diff --git a/tests/auto/tools/tst_tools.h b/tests/auto/tools/tst_tools.h
index d1ba0a57b..619174976 100644
--- a/tests/auto/tools/tst_tools.h
+++ b/tests/auto/tools/tst_tools.h
@@ -100,6 +100,9 @@ private slots:
void stringutils_endsWith();
void stringutils_trimmed();
+ void hash_tuple();
+ void hash_range();
+
private:
QString setupSettingsDir1();
QString setupSettingsDir2();