summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2015-05-28 19:38:29 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-06 21:23:05 +0200
commit3a8b238052163952831fb5924b2483a375e86ebd (patch)
treeab120b4fac3a5345a20e7a09e1e7477e67d9ed6f /tests
parent161dc66c2c8d5f973ee69dab36c3969a7efd7495 (diff)
downloadMultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar
MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.gz
MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.lz
MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.xz
MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.zip
NOISSUE Various changes from multiauth that are unrelated to it
Diffstat (limited to 'tests')
-rw-r--r--tests/tst_Resource.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/tst_Resource.cpp b/tests/tst_Resource.cpp
new file mode 100644
index 00000000..ba6f0509
--- /dev/null
+++ b/tests/tst_Resource.cpp
@@ -0,0 +1,101 @@
+#include <QTest>
+#include <QAction>
+#include "TestUtil.h"
+
+#include "resources/Resource.h"
+#include "resources/ResourceHandler.h"
+#include "resources/ResourceObserver.h"
+
+class DummyStringResourceHandler : public ResourceHandler
+{
+public:
+ explicit DummyStringResourceHandler(const QString &key)
+ : m_key(key) {}
+
+ void init(std::shared_ptr<ResourceHandler> &) override
+ {
+ setResult(m_key);
+ }
+
+ QString m_key;
+};
+class DummyObserver : public ResourceObserver
+{
+public:
+ void resourceUpdated() override
+ {
+ values += get<QString>();
+ }
+
+ QStringList values;
+};
+class DummyObserverObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString property MEMBER property)
+
+public:
+ explicit DummyObserverObject(QObject *parent = nullptr) : QObject(parent) {}
+
+ QString property;
+};
+
+class ResourceTest : public QObject
+{
+ Q_OBJECT
+private
+slots:
+ void initTestCase()
+ {
+ Resource::registerHandler<DummyStringResourceHandler>("dummy");
+ }
+ void cleanupTestCase()
+ {
+ }
+
+ void test_Then()
+ {
+ QString val;
+ Resource::create("dummy:test_Then")
+ ->then([&val](const QString &key) { val = key; });
+ QCOMPARE(val, QStringLiteral("test_Then"));
+ }
+ void test_Object()
+ {
+ DummyObserver *observer = new DummyObserver;
+ Resource::create("dummy:test_Object")->applyTo(observer);
+ QCOMPARE(observer->values, QStringList() << "test_Object");
+ }
+ void test_QObjectProperty()
+ {
+ DummyObserverObject *object = new DummyObserverObject;
+ Resource::create("dummy:test_QObjectProperty")->applyTo(object);
+ QCOMPARE(object->property, QStringLiteral("test_QObjectProperty"));
+ }
+
+ void test_DontRequestPlaceholder()
+ {
+ auto resource = Resource::create("dummy:asdf")
+ ->then([](const QString &key) { QCOMPARE(key, QStringLiteral("asdf")); });
+ // the following call should not notify the observer. if it does the above QCOMPARE would fail.
+ resource->placeholder(Resource::create("dummy:fdsa"));
+ }
+
+ void test_MergedResources()
+ {
+ auto r1 = Resource::create("dummy:asdf");
+ auto r2 = Resource::create("dummy:asdf");
+ auto r3 = Resource::create("dummy:fdsa");
+ auto r4 = Resource::create("dummy:asdf");
+
+ QCOMPARE(r1, r2);
+ QCOMPARE(r1, r4);
+ QVERIFY(r1 != r3);
+ QVERIFY(r2 != r3);
+ QVERIFY(r4 != r3);
+ }
+};
+
+QTEST_GUILESS_MAIN(ResourceTest)
+
+#include "tst_Resource.moc"