diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/testtaglist.cpp | 82 | ||||
-rw-r--r-- | tests/testtaglist.h | 20 |
3 files changed, 104 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2efacd706..a9c65bd09 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,6 +87,7 @@ TEST(TestGitStorage testgitstorage.cpp) TEST(TestPreferences testpreferences.cpp) TEST(TestPicture testpicture.cpp) TEST(TestMerge testmerge.cpp) +TEST(TestTagList testtaglist.cpp) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} @@ -102,6 +103,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestRenumber TestPicture TestMerge + TestTagList ) # useful for debugging CMake issues diff --git a/tests/testtaglist.cpp b/tests/testtaglist.cpp new file mode 100644 index 000000000..afe5049f1 --- /dev/null +++ b/tests/testtaglist.cpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testtaglist.h" +#include "core/dive.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) diff --git a/tests/testtaglist.h b/tests/testtaglist.h new file mode 100644 index 000000000..7e6e94742 --- /dev/null +++ b/tests/testtaglist.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTTAGLIST_H +#define TESTTAGLIST_H + +#include <QtTest> + +class TestTagList : public QObject { + Q_OBJECT +private slots: + void initTestCase(); + void cleanupTestCase(); + + void testGetTagstringNoTags(); + void testGetTagstringSingleTag(); + void testGetTagstringMultipleTags(); + void testGetTagstringWithAnEmptyTag(); + void testGetTagstringEmptyTagOnly(); +}; + +#endif |