aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testtaglist.cpp
blob: cd7e59c433a5956ce22006a546ef037fe899e76a (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: GPL-2.0
#include "testtaglist.h"
#include "core/dive.h"
#include "core/tag.h"

void TestTagList::initTestCase()
{
	taglist_init_global();
}

void TestTagList::cleanupTestCase()
{
	taglist_free(g_tag_list);
	g_tag_list = NULL;
}

void TestTagList::testGetTagstringNoTags()
{
	struct tag_entry *tag_list = NULL;
	char *tagstring = taglist_get_tagstring(tag_list);
	QVERIFY(tagstring != NULL);
	QCOMPARE(*tagstring, '\0');
}

void TestTagList::testGetTagstringSingleTag()
{
	struct tag_entry *tag_list = NULL;
	taglist_add_tag(&tag_list, "A new tag");
	char *tagstring = taglist_get_tagstring(tag_list);
	QVERIFY(tagstring != NULL);
	QCOMPARE(QString::fromUtf8(tagstring), QString::fromUtf8("A new tag"));
	free(tagstring);
}

void TestTagList::testGetTagstringMultipleTags()
{
	struct tag_entry *tag_list = NULL;
	taglist_add_tag(&tag_list, "A new tag");
	taglist_add_tag(&tag_list, "A new tag 1");
	taglist_add_tag(&tag_list, "A new tag 2");
	taglist_add_tag(&tag_list, "A new tag 3");
	taglist_add_tag(&tag_list, "A new tag 4");
	taglist_add_tag(&tag_list, "A new tag 5");
	char *tagstring = taglist_get_tagstring(tag_list);
	QVERIFY(tagstring != NULL);
	QCOMPARE(QString::fromUtf8(tagstring),
		 QString::fromUtf8(
			 "A new tag, "
			 "A new tag 1, "
			 "A new tag 2, "
			 "A new tag 3, "
			 "A new tag 4, "
			 "A new tag 5"));
	free(tagstring);
}

void TestTagList::testGetTagstringWithAnEmptyTag()
{
	struct tag_entry *tag_list = NULL;
	taglist_add_tag(&tag_list, "A new tag");
	taglist_add_tag(&tag_list, "A new tag 1");
	taglist_add_tag(&tag_list, "");
	char *tagstring = taglist_get_tagstring(tag_list);
	QVERIFY(tagstring != NULL);
	QCOMPARE(QString::fromUtf8(tagstring),
		 QString::fromUtf8(
			 "A new tag, "
			 "A new tag 1"));
	free(tagstring);
}

void TestTagList::testGetTagstringEmptyTagOnly()
{
	struct tag_entry *tag_list = NULL;
	taglist_add_tag(&tag_list, "");
	char *tagstring = taglist_get_tagstring(tag_list);
	QVERIFY(tagstring != NULL);
	QCOMPARE(QString::fromUtf8(tagstring),
		 QString::fromUtf8(""));
	free(tagstring);
}

QTEST_GUILESS_MAIN(TestTagList)