summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/test/TestAddonBuilder.cpp
blob: 08f6c6de65d6dc4a183da53174675a66ecf46b88 (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
51
52
53
54
/*
 *  Copyright (C) 2016-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "addons/AddonBuilder.h"
#include "addons/LanguageResource.h"
#include "addons/addoninfo/AddonInfo.h"
#include "addons/addoninfo/AddonInfoBuilder.h"
#include "addons/addoninfo/AddonType.h"

#include <gtest/gtest.h>

using namespace ADDON;


class TestAddonBuilder : public ::testing::Test
{
protected:
  TestAddonBuilder() = default;
};

TEST_F(TestAddonBuilder, ShouldFailWhenEmpty)
{
  EXPECT_EQ(nullptr, CAddonBuilder::Generate(nullptr, AddonType::UNKNOWN));
}

TEST_F(TestAddonBuilder, ShouldBuildDependencyAddons)
{
  std::vector<DependencyInfo> deps;
  deps.emplace_back("a", CAddonVersion("1.0.0"), CAddonVersion("1.0.10"), false);

  CAddonInfoBuilderFromDB builder;
  builder.SetId("aa");
  builder.SetDependencies(deps);
  CAddonType addonType(AddonType::UNKNOWN);
  builder.SetExtensions(addonType);
  AddonPtr addon = CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN);
  EXPECT_EQ(deps, addon->GetDependencies());
}

TEST_F(TestAddonBuilder, ShouldReturnDerivedType)
{
  CAddonInfoBuilderFromDB builder;
  builder.SetId("aa");
  CAddonType addonType(AddonType::RESOURCE_LANGUAGE);
  builder.SetExtensions(addonType);
  auto addon = std::dynamic_pointer_cast<CLanguageResource>(
      CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN));
  EXPECT_NE(nullptr, addon);
}