[video] Fix the refresh of movies with additional versions or extras
[xbmc.git] / xbmc / test / TestFileItem.cpp
blobe78ba27676decac03fe9cf940b575a86aa48f221
1 /*
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.
7 */
9 #include "FileItem.h"
10 #include "ServiceBroker.h"
11 #include "URL.h"
12 #include "settings/AdvancedSettings.h"
13 #include "settings/Settings.h"
14 #include "settings/SettingsComponent.h"
15 #include "settings/lib/SettingsManager.h"
17 #include <gtest/gtest.h>
19 using ::testing::Test;
20 using ::testing::WithParamInterface;
21 using ::testing::ValuesIn;
23 struct TestFileData
25 const char *file;
26 bool use_folder;
27 const char *base;
30 class AdvancedSettingsResetBase : public Test
32 public:
33 AdvancedSettingsResetBase();
36 AdvancedSettingsResetBase::AdvancedSettingsResetBase()
38 // Force all advanced settings to be reset to defaults
39 const auto settings = CServiceBroker::GetSettingsComponent();
40 CSettingsManager* settingsMgr = settings->GetSettings()->GetSettingsManager();
41 settings->GetAdvancedSettings()->Uninitialize(*settingsMgr);
42 settings->GetAdvancedSettings()->Initialize(*settingsMgr);
45 class TestFileItemSpecifiedArtJpg : public AdvancedSettingsResetBase,
46 public WithParamInterface<TestFileData>
51 TEST_P(TestFileItemSpecifiedArtJpg, GetLocalArt)
53 CFileItem item;
54 item.SetPath(GetParam().file);
55 std::string path = CURL(item.GetLocalArt("art.jpg", GetParam().use_folder)).Get();
56 std::string compare = CURL(GetParam().base).Get();
57 EXPECT_EQ(compare, path);
60 const TestFileData MovieFiles[] = {{ "c:\\dir\\filename.avi", false, "c:\\dir\\filename-art.jpg" },
61 { "c:\\dir\\filename.avi", true, "c:\\dir\\art.jpg" },
62 { "/dir/filename.avi", false, "/dir/filename-art.jpg" },
63 { "/dir/filename.avi", true, "/dir/art.jpg" },
64 { "smb://somepath/file.avi", false, "smb://somepath/file-art.jpg" },
65 { "smb://somepath/file.avi", true, "smb://somepath/art.jpg" },
66 { "stack:///path/to/movie-cd1.avi , /path/to/movie-cd2.avi", false, "/path/to/movie-art.jpg" },
67 { "stack:///path/to/movie-cd1.avi , /path/to/movie-cd2.avi", true, "/path/to/art.jpg" },
68 { "stack:///path/to/movie_name/cd1/some_file1.avi , /path/to/movie_name/cd2/some_file2.avi", true, "/path/to/movie_name/art.jpg" },
69 { "/home/user/TV Shows/Dexter/S1/1x01.avi", false, "/home/user/TV Shows/Dexter/S1/1x01-art.jpg" },
70 { "/home/user/TV Shows/Dexter/S1/1x01.avi", true, "/home/user/TV Shows/Dexter/S1/art.jpg" },
71 { "zip://g%3a%5cmultimedia%5cmovies%5cSphere%2ezip/Sphere.avi", false, "g:\\multimedia\\movies\\Sphere-art.jpg" },
72 { "zip://g%3a%5cmultimedia%5cmovies%5cSphere%2ezip/Sphere.avi", true, "g:\\multimedia\\movies\\art.jpg" },
73 { "/home/user/movies/movie_name/video_ts/VIDEO_TS.IFO", false, "/home/user/movies/movie_name/art.jpg" },
74 { "/home/user/movies/movie_name/video_ts/VIDEO_TS.IFO", true, "/home/user/movies/movie_name/art.jpg" },
75 { "/home/user/movies/movie_name/BDMV/index.bdmv", false, "/home/user/movies/movie_name/art.jpg" },
76 { "/home/user/movies/movie_name/BDMV/index.bdmv", true, "/home/user/movies/movie_name/art.jpg" }};
78 INSTANTIATE_TEST_SUITE_P(MovieFiles, TestFileItemSpecifiedArtJpg, ValuesIn(MovieFiles));
80 class TestFileItemFallbackArt : public AdvancedSettingsResetBase,
81 public WithParamInterface<TestFileData>
85 TEST_P(TestFileItemFallbackArt, GetLocalArt)
87 CFileItem item;
88 item.SetPath(GetParam().file);
89 std::string path = CURL(item.GetLocalArt("", GetParam().use_folder)).Get();
90 std::string compare = CURL(GetParam().base).Get();
91 EXPECT_EQ(compare, path);
94 const TestFileData NoArtFiles[] = {{ "c:\\dir\\filename.avi", false, "c:\\dir\\filename.tbn" },
95 { "/dir/filename.avi", false, "/dir/filename.tbn" },
96 { "smb://somepath/file.avi", false, "smb://somepath/file.tbn" },
97 { "/home/user/TV Shows/Dexter/S1/1x01.avi", false, "/home/user/TV Shows/Dexter/S1/1x01.tbn" },
98 { "zip://g%3a%5cmultimedia%5cmovies%5cSphere%2ezip/Sphere.avi", false, "g:\\multimedia\\movies\\Sphere.tbn" }};
100 INSTANTIATE_TEST_SUITE_P(NoArt, TestFileItemFallbackArt, ValuesIn(NoArtFiles));
102 class TestFileItemBasePath : public AdvancedSettingsResetBase,
103 public WithParamInterface<TestFileData>
107 TEST_P(TestFileItemBasePath, GetBaseMoviePath)
109 CFileItem item;
110 item.SetPath(GetParam().file);
111 std::string path = CURL(item.GetBaseMoviePath(GetParam().use_folder)).Get();
112 std::string compare = CURL(GetParam().base).Get();
113 EXPECT_EQ(compare, path);
116 const TestFileData BaseMovies[] = {{ "c:\\dir\\filename.avi", false, "c:\\dir\\filename.avi" },
117 { "c:\\dir\\filename.avi", true, "c:\\dir\\" },
118 { "/dir/filename.avi", false, "/dir/filename.avi" },
119 { "/dir/filename.avi", true, "/dir/" },
120 { "smb://somepath/file.avi", false, "smb://somepath/file.avi" },
121 { "smb://somepath/file.avi", true, "smb://somepath/" },
122 { "stack:///path/to/movie_name/cd1/some_file1.avi , /path/to/movie_name/cd2/some_file2.avi", false, "stack:///path/to/movie_name/cd1/some_file1.avi , /path/to/movie_name/cd2/some_file2.avi" },
123 { "stack:///path/to/movie_name/cd1/some_file1.avi , /path/to/movie_name/cd2/some_file2.avi", true, "/path/to/movie_name/" },
124 { "/home/user/TV Shows/Dexter/S1/1x01.avi", false, "/home/user/TV Shows/Dexter/S1/1x01.avi" },
125 { "/home/user/TV Shows/Dexter/S1/1x01.avi", true, "/home/user/TV Shows/Dexter/S1/" },
126 { "zip://g%3a%5cmultimedia%5cmovies%5cSphere%2ezip/Sphere.avi", true, "g:\\multimedia\\movies\\" },
127 { "/home/user/movies/movie_name/video_ts/VIDEO_TS.IFO", false, "/home/user/movies/movie_name/" },
128 { "/home/user/movies/movie_name/video_ts/VIDEO_TS.IFO", true, "/home/user/movies/movie_name/" },
129 { "/home/user/movies/movie_name/BDMV/index.bdmv", false, "/home/user/movies/movie_name/" },
130 { "/home/user/movies/movie_name/BDMV/index.bdmv", true, "/home/user/movies/movie_name/" }};
132 INSTANTIATE_TEST_SUITE_P(BaseNameMovies, TestFileItemBasePath, ValuesIn(BaseMovies));