summaryrefslogtreecommitdiffstats
path: root/api/logic/wonko/WonkoIndex_test.cpp
blob: 7eb51bc32beacf0fd7a1fb792d45a0d5261af4e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <QTest>
#include "TestUtil.h"

#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersionList.h"
#include "Env.h"

class WonkoIndexTest : public QObject
{
	Q_OBJECT
private
slots:
	void test_isProvidedByEnv()
	{
		QVERIFY(ENV.wonkoIndex() != nullptr);
		QCOMPARE(ENV.wonkoIndex(), ENV.wonkoIndex());
	}

	void test_providesTasks()
	{
		QVERIFY(ENV.wonkoIndex()->localUpdateTask() != nullptr);
		QVERIFY(ENV.wonkoIndex()->remoteUpdateTask() != nullptr);
	}

	void test_hasUid_and_getList()
	{
		WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")});
		QVERIFY(windex.hasUid("list1"));
		QVERIFY(!windex.hasUid("asdf"));
		QVERIFY(windex.getList("list2") != nullptr);
		QCOMPARE(windex.getList("list2")->uid(), QString("list2"));
		QVERIFY(windex.getList("adsf") == nullptr);
	}

	void test_merge()
	{
		WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")});
		QCOMPARE(windex.lists().size(), 3);
		windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")})));
		QCOMPARE(windex.lists().size(), 3);
		windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list4"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list5")})));
		QCOMPARE(windex.lists().size(), 5);
		windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list6")})));
		QCOMPARE(windex.lists().size(), 6);
	}
};

QTEST_GUILESS_MAIN(WonkoIndexTest)

#include "WonkoIndex_test.moc"