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.
9 #include "addons/AddonDatabase.h"
10 #include "addons/addoninfo/AddonInfoBuilder.h"
11 #include "filesystem/SpecialProtocol.h"
12 #include "settings/AdvancedSettings.h"
17 #include <gtest/gtest.h>
19 using namespace ADDON
;
22 class AddonDatabaseTest
: public ::testing::Test
25 DatabaseSettings settings
;
26 CAddonDatabase database
;
30 settings
.type
= "sqlite3";
31 settings
.name
= "test";
32 settings
.host
= CSpecialProtocol::TranslatePath("special://temp/");
34 database
.Connect("test", settings
, true);
36 std::set
<std::string
> installed
{"repository.a", "repository.b"};
37 database
.SyncInstalled(installed
, installed
, std::set
<std::string
>());
39 std::vector
<AddonInfoPtr
> addons
;
40 CreateAddon(addons
, "foo.bar", "1.0.0");
41 database
.SetRepoUpdateData("repository.a", {});
42 database
.UpdateRepositoryContent("repository.a", CAddonVersion("1.0.0"), "test", addons
);
45 CreateAddon(addons
, "foo.baz", "1.1.0");
46 database
.SetRepoUpdateData("repository.b", {});
47 database
.UpdateRepositoryContent("repository.b", CAddonVersion("1.0.0"), "test", addons
);
50 void CreateAddon(std::vector
<AddonInfoPtr
>& addons
, std::string id
, const std::string
& version
)
52 CAddonInfoBuilderFromDB builder
;
53 builder
.SetId(std::move(id
));
54 builder
.SetVersion(CAddonVersion(version
));
55 addons
.push_back(builder
.get());
58 void TearDown() override
65 TEST_F(AddonDatabaseTest
, TestFindById
)
68 EXPECT_TRUE(database
.FindByAddonId("foo.baz", addons
));
69 EXPECT_EQ(1U, addons
.size());
70 EXPECT_EQ(addons
.at(0)->ID(), "foo.baz");
71 EXPECT_EQ(addons
.at(0)->Version().asString(), "1.1.0");
72 EXPECT_EQ(addons
.at(0)->Origin(), "repository.b");
75 TEST_F(AddonDatabaseTest
, TestFindByNonExistingId
)
78 EXPECT_TRUE(database
.FindByAddonId("does.not.exist", addons
));
79 EXPECT_EQ(0U, addons
.size());