Merge pull request #26117 from notspiff/infoscanner_inforet_enum_class
[xbmc.git] / xbmc / addons / test / TestAddonInfoBuilder.cpp
blob03af236fbd2a1558b55e589d678677f371c7020b
1 /*
2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "addons/Repository.h"
10 #include "addons/addoninfo/AddonInfo.h"
11 #include "addons/addoninfo/AddonInfoBuilder.h"
12 #include "addons/addoninfo/AddonType.h"
13 #include "utils/XBMCTinyXML2.h"
15 #include <set>
17 #include <gtest/gtest.h>
19 using namespace ADDON;
21 const std::string addonXML = R"xml(
22 <addon id="metadata.blablabla.org"
23 name="The Bla Bla Bla Addon"
24 version="1.2.3"
25 provider-name="Team Kodi">
26 <requires>
27 <import addon="xbmc.metadata" version="2.1.0"/>
28 <import addon="metadata.common.imdb.com" minversion="2.9.2" version="2.9.2"/>
29 <import addon="metadata.common.themoviedb.org" minversion="3.1.0" version="3.1.0"/>
30 <import addon="plugin.video.youtube" minversion="4.4.0" version="4.4.10" optional="true"/>
31 </requires>
32 <extension point="xbmc.metadata.scraper.movies"
33 language="en"
34 library="blablabla.xml"/>
35 <extension point="xbmc.python.module"
36 library="lib.so"/>
37 <extension point="kodi.addon.metadata">
38 <summary lang="en">Summary bla bla bla</summary>
39 <description lang="en">Description bla bla bla</description>
40 <disclaimer lang="en">Disclaimer bla bla bla</disclaimer>
41 <platform>all</platform>
42 <language>marsian</language>
43 <license>GPL v2.0</license>
44 <forum>https://forum.kodi.tv</forum>
45 <website>https://kodi.tv</website>
46 <email>a@a.dummy</email>
47 <source>https://github.com/xbmc/xbmc</source>
48 </extension>
49 </addon>
50 )xml";
52 class TestAddonInfoBuilder : public ::testing::Test
54 protected:
55 TestAddonInfoBuilder() = default;
58 TEST_F(TestAddonInfoBuilder, ShouldFailWhenIdIsNotSet)
60 AddonInfoPtr addon = CAddonInfoBuilder::Generate("", AddonType::UNKNOWN);
61 EXPECT_EQ(nullptr, addon);
64 TEST_F(TestAddonInfoBuilder, TestGenerate_Id_Type)
66 AddonInfoPtr addon = CAddonInfoBuilder::Generate("foo.baz", AddonType::VISUALIZATION);
67 EXPECT_NE(nullptr, addon);
68 EXPECT_EQ(addon->ID(), "foo.baz");
69 EXPECT_EQ(addon->MainType(), AddonType::VISUALIZATION);
70 EXPECT_TRUE(addon->HasType(AddonType::VISUALIZATION));
71 EXPECT_FALSE(addon->HasType(AddonType::SCREENSAVER));
74 TEST_F(TestAddonInfoBuilder, TestGenerate_Repo)
76 CXBMCTinyXML2 doc;
77 EXPECT_TRUE(doc.Parse(addonXML));
78 ASSERT_NE(nullptr, doc.RootElement());
80 RepositoryDirInfo repo;
81 AddonInfoPtr addon = CAddonInfoBuilder::Generate(doc.RootElement(), repo);
82 ASSERT_NE(nullptr, addon);
83 EXPECT_EQ(addon->ID(), "metadata.blablabla.org");
85 EXPECT_EQ(addon->MainType(), AddonType::SCRAPER_MOVIES);
86 EXPECT_TRUE(addon->HasType(AddonType::SCRAPER_MOVIES));
87 EXPECT_EQ(addon->Type(AddonType::SCRAPER_MOVIES)->LibName(), "blablabla.xml");
88 EXPECT_EQ(addon->Type(AddonType::SCRAPER_MOVIES)->GetValue("@language").asString(), "en");
90 EXPECT_TRUE(addon->HasType(AddonType::SCRIPT_MODULE));
91 EXPECT_EQ(addon->Type(AddonType::SCRIPT_MODULE)->LibName(), "lib.so");
92 EXPECT_FALSE(addon->HasType(AddonType::SCRAPER_ARTISTS));
94 EXPECT_EQ(addon->Name(), "The Bla Bla Bla Addon");
95 EXPECT_EQ(addon->Author(), "Team Kodi");
96 EXPECT_EQ(addon->Version().asString(), "1.2.3");
98 EXPECT_EQ(addon->Summary(), "Summary bla bla bla");
99 EXPECT_EQ(addon->Description(), "Description bla bla bla");
100 EXPECT_EQ(addon->Disclaimer(), "Disclaimer bla bla bla");
101 EXPECT_EQ(addon->License(), "GPL v2.0");
102 EXPECT_EQ(addon->Forum(), "https://forum.kodi.tv");
103 EXPECT_EQ(addon->Website(), "https://kodi.tv");
104 EXPECT_EQ(addon->EMail(), "a@a.dummy");
105 EXPECT_EQ(addon->Source(), "https://github.com/xbmc/xbmc");
107 const std::vector<DependencyInfo>& dependencies = addon->GetDependencies();
108 ASSERT_EQ(dependencies.size(), (long unsigned int)4);
109 EXPECT_EQ(dependencies[0].id, "xbmc.metadata");
110 EXPECT_EQ(dependencies[0].optional, false);
111 EXPECT_EQ(dependencies[0].versionMin.asString(), "2.1.0");
112 EXPECT_EQ(dependencies[0].version.asString(), "2.1.0");
113 EXPECT_EQ(dependencies[1].id, "metadata.common.imdb.com");
114 EXPECT_EQ(dependencies[1].optional, false);
115 EXPECT_EQ(dependencies[1].versionMin.asString(), "2.9.2");
116 EXPECT_EQ(dependencies[1].version.asString(), "2.9.2");
117 EXPECT_EQ(dependencies[2].id, "metadata.common.themoviedb.org");
118 EXPECT_EQ(dependencies[2].optional, false);
119 EXPECT_EQ(dependencies[2].versionMin.asString(), "3.1.0");
120 EXPECT_EQ(dependencies[2].version.asString(), "3.1.0");
121 EXPECT_EQ(dependencies[3].id, "plugin.video.youtube");
122 EXPECT_EQ(dependencies[3].optional, true);
123 EXPECT_EQ(dependencies[3].versionMin.asString(), "4.4.0");
124 EXPECT_EQ(dependencies[3].version.asString(), "4.4.10");
126 auto info = addon->ExtraInfo().find("language");
127 ASSERT_NE(info, addon->ExtraInfo().end());
128 EXPECT_EQ(info->second, "marsian");
131 TEST_F(TestAddonInfoBuilder, TestGenerate_DBEntry)
133 CAddonInfoBuilderFromDB builder;
134 builder.SetId("video.blablabla.org");
135 builder.SetVersion(CAddonVersion("1.2.3"));
136 CAddonType addonType(AddonType::PLUGIN);
137 addonType.Insert("provides", "video audio");
138 builder.SetExtensions(addonType);
139 builder.SetName("The Bla Bla Bla Addon");
140 builder.SetAuthor("Team Kodi");
141 builder.SetSummary("Summary bla bla bla");
142 builder.SetDescription("Description bla bla bla");
143 builder.SetDisclaimer("Disclaimer bla bla bla");
144 builder.SetLicense("GPL v2.0");
145 builder.SetForum("https://forum.kodi.tv");
146 builder.SetWebsite("https://kodi.tv");
147 builder.SetEMail("a@a.dummy");
148 builder.SetSource("https://github.com/xbmc/xbmc");
149 InfoMap extrainfo;
150 extrainfo["language"] = "marsian";
151 builder.SetExtrainfo(extrainfo);
153 AddonInfoPtr addon = builder.get();
154 ASSERT_NE(nullptr, addon);
155 EXPECT_EQ(addon->ID(), "video.blablabla.org");
157 EXPECT_EQ(addon->MainType(), AddonType::PLUGIN);
158 EXPECT_TRUE(addon->HasType(AddonType::PLUGIN));
159 EXPECT_TRUE(addon->HasType(AddonType::VIDEO));
160 EXPECT_TRUE(addon->HasType(AddonType::AUDIO));
161 EXPECT_FALSE(addon->HasType(AddonType::GAME));
163 EXPECT_EQ(addon->Name(), "The Bla Bla Bla Addon");
164 EXPECT_EQ(addon->Author(), "Team Kodi");
165 EXPECT_EQ(addon->Version().asString(), "1.2.3");
167 EXPECT_EQ(addon->Summary(), "Summary bla bla bla");
168 EXPECT_EQ(addon->Description(), "Description bla bla bla");
169 EXPECT_EQ(addon->Disclaimer(), "Disclaimer bla bla bla");
170 EXPECT_EQ(addon->License(), "GPL v2.0");
171 EXPECT_EQ(addon->Forum(), "https://forum.kodi.tv");
172 EXPECT_EQ(addon->Website(), "https://kodi.tv");
173 EXPECT_EQ(addon->EMail(), "a@a.dummy");
174 EXPECT_EQ(addon->Source(), "https://github.com/xbmc/xbmc");
176 auto info = addon->ExtraInfo().find("language");
177 ASSERT_NE(info, addon->ExtraInfo().end());
178 EXPECT_EQ(info->second, "marsian");