Commit e5fae9b9 authored by Christian Stenger's avatar Christian Stenger Committed by Tobias Hunger

Tests: Fix compile on Windows and Linux

Template code inside utils/algorithm.h is not correctly instantiated when
respective containers that shall use these functions are included after
the algorithm file.
Additionally there had been issues using nullptr as comparison inside
QCOMPARE().

Change-Id: I2bd6baf3890090c5f5bbbd6229afb9aeeb7617ef
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 67767f99
......@@ -23,14 +23,16 @@
**
****************************************************************************/
#include <utils/algorithm.h>
#include <QtTest>
#include <array>
#include <memory>
#include <valarray>
// must get included after the containers above or gcc4.9 will have a problem using
// initializer_list related code on the templates inside algorithm.h
#include <utils/algorithm.h>
class tst_Algorithm : public QObject
{
Q_OBJECT
......@@ -222,14 +224,14 @@ void tst_Algorithm::findOrDefault()
v2.emplace_back(std::make_unique<int>(3));
v2.emplace_back(std::make_unique<int>(4));
QCOMPARE(Utils::findOrDefault(v2, [](const std::unique_ptr<int> &ip) { return *ip == 2; }), v2.at(1).get());
QCOMPARE(Utils::findOrDefault(v2, [](const std::unique_ptr<int> &ip) { return *ip == 5; }), nullptr);
QCOMPARE(Utils::findOrDefault(v2, [](const std::unique_ptr<int> &ip) { return *ip == 5; }), static_cast<int*>(0));
std::vector<std::unique_ptr<Struct>> v3;
v3.emplace_back(std::make_unique<Struct>(1));
v3.emplace_back(std::make_unique<Struct>(3));
v3.emplace_back(std::make_unique<Struct>(5));
v3.emplace_back(std::make_unique<Struct>(7));
QCOMPARE(Utils::findOrDefault(v3, &Struct::isOdd), v3.at(0).get());
QCOMPARE(Utils::findOrDefault(v3, &Struct::isEven), nullptr);
QCOMPARE(Utils::findOrDefault(v3, &Struct::isEven), static_cast<Struct*>(0));
}
QTEST_MAIN(tst_Algorithm)
......
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