summaryrefslogtreecommitdiffstats
path: root/xbmc/video/test/TestVideoInfoScanner.cpp
blob: 981d7498b07658d071aec9ebfa114ec6d45960f9 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 *  Copyright (C) 2005-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 "FileItem.h"
#include "video/VideoInfoScanner.h"

#include <gtest/gtest.h>

using namespace VIDEO;
using ::testing::Test;
using ::testing::WithParamInterface;
using ::testing::ValuesIn;

typedef struct
{
  const char* path;
  int season;
  int episode[4]; // for multi-episodes
} TestEntry;

static const TestEntry TestData[] = {
  //season+episode
  {"foo.S02E03.mkv",   2, {3} },
  {"foo.203.mkv",      2, {3} },
  //episode only
  {"foo.Ep03.mkv",     1, {3} },
  {"foo.Ep_03.mkv",    1, {3} },
  {"foo.Part.III.mkv", 1, {3} },
  {"foo.Part.3.mkv",   1, {3} },
  {"foo.E03.mkv",      1, {3} },
  {"foo.2009.E03.mkv", 1, {3} },
  // multi-episode
  {"The Legend of Korra - S01E01-02 - Welcome to Republic City & A Leaf in the Wind.mkv", 1, { 1, 2 } },
  {"foo.S01E01E02.mkv", 1, {1,2} },
  {"foo.S01E03E04E05.mkv", 1, {3,4,5} }
};

class TestVideoInfoScanner : public Test,
                             public WithParamInterface<TestEntry>
{
};

TEST_P(TestVideoInfoScanner, EnumerateEpisodeItem)
{
  const TestEntry& entry = GetParam();
  CVideoInfoScanner scanner;
  CFileItem item(entry.path, false);
  EPISODELIST expected;
  for (int i = 0; i < 3 && entry.episode[i]; i++)
    expected.push_back(EPISODE(entry.season, entry.episode[i], 0, false));

  EPISODELIST result;
  ASSERT_TRUE(scanner.EnumerateEpisodeItem(&item, result));
  EXPECT_EQ(expected.size(), result.size());
  for (size_t i = 0; i < expected.size(); i++)
    EXPECT_EQ(expected[i], result[i]);
}

INSTANTIATE_TEST_SUITE_P(VideoInfoScanner, TestVideoInfoScanner, ValuesIn(TestData));

TEST(TestVideoInfoScanner, EnumerateEpisodeItemByTitle)
{
  CVideoInfoScanner scanner;
  CFileItem item("/foo.special.mp4", false);
  EPISODELIST result;
  ASSERT_TRUE(scanner.EnumerateEpisodeItem(&item, result));
  ASSERT_EQ(result.size(), 1);
  ASSERT_EQ(result[0].strTitle, "foo");
}