2 * Copyright (C) 2005-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.
12 #include "filesystem/Directory.h"
13 #include "platform/Filesystem.h"
14 #include "utils/FileUtils.h"
15 #include "utils/URIUtils.h"
16 #include "video/VideoUtils.h"
21 #include <gtest/gtest.h>
24 namespace fs
= KODI::PLATFORM::FILESYSTEM
;
29 using OptDef
= std::pair
<std::string
, bool>;
31 class OpticalMediaPathTest
: public testing::WithParamInterface
<OptDef
>, public testing::Test
35 using TrailerDef
= std::pair
<std::string
, std::string
>;
37 class TrailerTest
: public testing::WithParamInterface
<TrailerDef
>, public testing::Test
43 TEST_P(OpticalMediaPathTest
, GetOpticalMediaPath
)
46 const std::string temp_path
= fs::create_temp_directory(ec
);
48 const std::string file_path
= URIUtils::AddFileToFolder(temp_path
, GetParam().first
);
49 EXPECT_TRUE(CUtil::CreateDirectoryEx(URIUtils::GetDirectory(file_path
)));
51 std::ofstream
of(file_path
);
53 CFileItem
item(temp_path
, true);
54 if (GetParam().second
)
55 EXPECT_EQ(VIDEO::UTILS::GetOpticalMediaPath(item
), file_path
);
57 EXPECT_EQ(VIDEO::UTILS::GetOpticalMediaPath(item
), "");
59 XFILE::CDirectory::RemoveRecursive(temp_path
);
62 const auto mediapath_tests
= std::array
{
63 OptDef
{"VIDEO_TS.IFO", true}, OptDef
{"VIDEO_TS/VIDEO_TS.IFO", true},
64 OptDef
{"some.file", false},
66 OptDef
{"index.bdmv", true}, OptDef
{"INDEX.BDM", true},
67 OptDef
{"BDMV/index.bdmv", true}, OptDef
{"BDMV/INDEX.BDM", true},
71 INSTANTIATE_TEST_SUITE_P(TestVideoUtils
, OpticalMediaPathTest
, testing::ValuesIn(mediapath_tests
));
73 TEST_P(TrailerTest
, FindTrailer
)
75 std::string temp_path
;
76 if (!GetParam().second
.empty())
79 temp_path
= fs::create_temp_directory(ec
);
81 XFILE::CDirectory::Create(temp_path
);
82 const std::string file_path
= URIUtils::AddFileToFolder(temp_path
, GetParam().second
);
84 std::ofstream
of(file_path
);
86 URIUtils::AddSlashAtEnd(temp_path
);
89 std::string input_path
= GetParam().first
;
90 if (!temp_path
.empty())
92 StringUtils::Replace(input_path
, "#DIRECTORY#", temp_path
);
93 StringUtils::Replace(input_path
, "#URLENCODED_DIRECTORY#", CURL::Encode(temp_path
));
96 CFileItem
item(input_path
, false);
97 EXPECT_EQ(VIDEO::UTILS::FindTrailer(item
),
98 GetParam().second
.empty() ? ""
99 : URIUtils::AddFileToFolder(temp_path
, GetParam().second
));
101 if (!temp_path
.empty())
102 XFILE::CDirectory::RemoveRecursive(temp_path
);
105 const auto trailer_tests
= std::array
{
106 TrailerDef
{"https://some.where/foo", ""},
107 TrailerDef
{"upnp://1/2/3", ""},
108 TrailerDef
{"bluray://1", ""},
109 TrailerDef
{"pvr://foobar.pvr", ""},
110 TrailerDef
{"plugin://plugin.video.foo/foo?param=1", ""},
111 TrailerDef
{"dvd://1", ""},
112 TrailerDef
{"stack://#DIRECTORY#foo-cd1.avi , #DIRECTORY#foo-cd2.avi", "foo-trailer.mkv"},
113 TrailerDef
{"stack://#DIRECTORY#foo-cd1.avi , #DIRECTORY#foo-cd2.avi", "foo-cd1-trailer.avi"},
114 TrailerDef
{"stack://#DIRECTORY#foo-cd1.avi , #DIRECTORY#foo-cd2.avi", "movie-trailer.mp4"},
115 TrailerDef
{"zip://#URLENCODED_DIRECTORY#bar.zip/bar.avi", "bar-trailer.mov"},
116 TrailerDef
{"zip://#URLENCODED_DIRECTORY#bar.zip/bar.mkv", "movie-trailer.ogm"},
117 TrailerDef
{"#DIRECTORY#bar.mkv", "bar-trailer.mkv"},
118 TrailerDef
{"#DIRECTORY#bar.mkv", "movie-trailer.avi"},
121 INSTANTIATE_TEST_SUITE_P(TestVideoUtils
, TrailerTest
, testing::ValuesIn(trailer_tests
));