From 8726de494ce3ffa84c004adeb9b4742797530ce4 Mon Sep 17 00:00:00 2001
From: Nikhil Tanwar <2002nikhiltanwar@gmail.com>
Date: Tue, 11 Jul 2023 22:01:23 +0530
Subject: [PATCH] Tests for readLanguagesFromFeed and readCategoriesFromFeed
Added tests on a sample OPDS language and categories stream
---
test/meson.build | 1 +
test/opdsParsingTools.cpp | 131 ++++++++++++++++++++++++++++++++++++++
2 files changed, 132 insertions(+)
create mode 100644 test/opdsParsingTools.cpp
diff --git a/test/meson.build b/test/meson.build
index f7ed51f5d..6e89d2ad3 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -5,6 +5,7 @@ tests = [
'stringTools',
'pathTools',
'otherTools',
+ 'opdsParsingTools',
'kiwixserve',
'book',
'manager',
diff --git a/test/opdsParsingTools.cpp b/test/opdsParsingTools.cpp
new file mode 100644
index 000000000..0a7cd9b8d
--- /dev/null
+++ b/test/opdsParsingTools.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2023 Nikhil Tanwar (2002nikhiltanwar@gmail.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
+ * NON-INFRINGEMENT. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "gtest/gtest.h"
+#include "../include/tools.h"
+typedef kiwix::FeedLanguages FeedLanguages;
+typedef kiwix::FeedCategories FeedCategories;
+
+namespace
+{
+const char sampleLanguageOpdsStream[] = R"(
+
+
+ 1e587935-0f7b-dad6-eddc-ef3fafd4c3ed
+
+
+ List of languages
+ 2023-07-11T15:35:09Z
+
+
+ Abkhazian
+ abk
+ 3
+
+ 2023-07-11T15:35:09Z
+ 2e4d9a1c-9750-0418-8124-a0c663e206f7
+
+
+ isiZulu
+ zul
+ 4
+
+ 2023-07-11T15:35:09Z
+ 76eec223-994d-9b95-e309-baee06e585b0
+
+
+)";
+
+const char sampleCategoriesOpdsStream[] = R"(
+
+
+ 231da20c-0fe0-7345-11b2-d29f50364108
+
+
+ List of categories
+ 2023-07-11T15:35:09Z
+
+
+ gutenberg
+
+ 2023-07-11T15:35:09Z
+ 401dbe68-2f7a-5503-b431-054801c30bab
+ All entries with category of 'gutenberg'.
+
+
+ iFixit
+
+ 2023-07-11T15:35:09Z
+ c18e5459-af23-5fbf-0622-ff271bd9a5ad
+ All entries with category of 'iFixit'.
+
+
+ wikivoyage
+
+ 2023-07-11T15:35:09Z
+ 9a75be6c-7a35-6f52-1a69-bee9ad248459
+ All entries with category of 'wikivoyage'.
+
+
+ wiktionary
+
+ 2023-07-11T15:35:09Z
+ 7adb9f1a-73d7-0391-1238-d2e2c300ddaa
+ All entries with category of 'wiktionary'.
+
+
+)";
+
+TEST(OpdsParsingTest, languageTest)
+{
+ FeedLanguages expectedLanguagesFromFeed = {{"abk", "Abkhazian"}, {"zul", "isiZulu"}};
+ EXPECT_EQ(kiwix::readLanguagesFromFeed(sampleLanguageOpdsStream), expectedLanguagesFromFeed);
+}
+
+TEST(OpdsParsingTest, categoryTest)
+{
+ FeedCategories expectedCategoriesFromFeed = {"gutenberg", "iFixit", "wikivoyage", "wiktionary"};
+ EXPECT_EQ(kiwix::readCategoriesFromFeed(sampleCategoriesOpdsStream), expectedCategoriesFromFeed);
+}
+
+}