Skip to content

Commit

Permalink
Add a test to check VideoList use of MythGenericTree.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Sep 11, 2021
1 parent cab50bf commit baec807
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 1 deletion.
1 change: 1 addition & 0 deletions mythtv/Makefile
Expand Up @@ -99,6 +99,7 @@ uninstall: $(addsuffix _uninstall,$(SUBDIRS))

test: libs/libmythbase/version.h subdirs
cd libs ; $(MAKE) test
cd programs ; $(MAKE) test

ctags tags:
@echo "Making tags..."
Expand Down
9 changes: 9 additions & 0 deletions mythtv/programs/mythfrontend/test/test.pro
@@ -0,0 +1,9 @@
include (../../../settings.pro)

TEMPLATE = subdirs

SUBDIRS += $$files(test_*)

unittest.target = test
unittest.commands = ../../../programs/scripts/unittests.sh
unix:QMAKE_EXTRA_TARGETS += unittest
@@ -0,0 +1 @@
test_videolist
141 changes: 141 additions & 0 deletions mythtv/programs/mythfrontend/test/test_videolist/test_videolist.cpp
@@ -0,0 +1,141 @@
/*
* Class TestVideoList
*
* Copyright (c) David Hampton 2021
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "test_videolist.h"

#include "mythcorecontext.h"
#include "mythgenerictree.h"
#include "videofilter.h"
#include "videometadatalistmanager.h"

void TestVideoList::initTestCase()
{
gCoreContext = new MythCoreContext("test_videolist_1.0", nullptr);

QMap<QString,QString> sOverrides;
sOverrides["FilenameTemplate"] = "abc";
gCoreContext->setTestStringSettings(sOverrides);

QMap<QString,int> iOverrides;
iOverrides["VideoDefaultCategory"] = kCategoryFilterAll;
iOverrides["VideoDefaultGenre"] = kGenreFilterAll;
iOverrides["VideoDefaultCountry"] = kCountryFilterAll;
iOverrides["VideoDefaultCast"] = kCastFilterAll;
iOverrides["VideoDefaultYear"] = kYearFilterAll;
iOverrides["VideoDefaultRuntime"] = kRuntimeFilterAll;
iOverrides["VideoDefaultUserrating"] = kUserRatingFilterAll;
iOverrides["VideoDefaultBrowse"] = kBrowseFilterAll;
iOverrides["VideoDefaultWatched"] = kWatchedFilterAll;
iOverrides["VideoDefaultInetref"] = kInetRefFilterAll;
iOverrides["VideoDefaultCoverfile"] = kCoverFileFilterAll;
// iOverrides["VideoDefaultOrderby"] = kOrderByTitle;
gCoreContext->setTestIntSettings(iOverrides);
}

void TestVideoList::testGenericTree ()
{
auto metadata = VideoMetadata(
QStringLiteral("TV Series/Flash (2014)/Season 3/Flash (2014) - S03E04.mkv"), // filename
QString(), // sortfilename
"c7097018f6b14e43", // hash
"Bogus Flash trailer name", // trailer
"The Flash (2014) Season 3_coverart.jpg", // coverfile
"The Flash (2014) Season 3x4_screenshot.jpg",
"The Flash (2014) Season 3_banner.jpg",
"The Flash (2014) Season 3_fanart.jpg",
"The Flash (2014)", "flash (2014)", // title, sorttitle
"The New Rogues", "new rogues", // subtitle, sortsubtitle
QString(), // tagline
2016, QDate(2016,10,25), // year, releasedate
"ttvdb.py_279121", //inetref
0, // collectionref
"http://thetvdb.com/?tab=episode&seriesid=279121&seasonid=671084&id=5714605", // homepage
"Stefan Pleszczynski", // director
"The CW", // studio
"Barry continues to train Jesse and when a new meta human, " \
"Mirror Master, appears on the scene he lets her tag along. " \
"Mirror Master has teamed up with his old partner, Top, and " \
"is looking for Snart to even a score. Jesse is quick to join " \
"the chase but defies one of Barry's orders which results in " \
"disastrous consequences.", // plot
7.8F, "TV-14", // userrating, rating
45, 5, // length, playcount
3, 4, // season, eposide
QDate(2016,11,3), // insertdate
21749, // id
ParentalLevel::plLowest,
0, -1, true, true); // categoryID, childID, browse, watched

// Build tree
auto *root = new MythGenericTree("Video Home", kRootNode, false);
AddFileNode(root, "The Flash", &metadata);
QCOMPARE(root->childCount(), 1);

// Validate GetText call
auto *child = root->getChildAt(0);
QVERIFY(child != nullptr);
QCOMPARE(child->GetText(), QString("The Flash"));
QCOMPARE(child->GetText("filename"), QString("TV Series/Flash (2014)/Season 3/Flash (2014) - S03E04.mkv"));
QCOMPARE(child->GetText("director"), QString("Stefan Pleszczynski"));
QCOMPARE(child->GetText("rating"), QString("TV-14"));
QCOMPARE(child->GetText("length"), QString("45 minute(s)"));
QCOMPARE(child->GetText("playcount"), QString("5"));
QCOMPARE(child->GetText("year"), QString("2016"));
QCOMPARE(child->GetText("season"), QString("3"));
QCOMPARE(child->GetText("episode"), QString("4"));
QCOMPARE(child->GetText("s00e00"), QString("s03e04"));
QCOMPARE(child->GetText("00x00"), QString("3x04"));

// Validate all possible GetImage values
QCOMPARE(child->GetImage(), QString());
QCOMPARE(child->GetImage("coverfile"), QString("The Flash (2014) Season 3_coverart.jpg"));
QCOMPARE(child->GetImage("screenshotfile"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));
QCOMPARE(child->GetImage("screenshotfile"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));
QCOMPARE(child->GetImage("bannerfile"), QString("The Flash (2014) Season 3_banner.jpg"));
QCOMPARE(child->GetImage("fanartfile"), QString("The Flash (2014) Season 3_fanart.jpg"));
QCOMPARE(child->GetImage("smartimage"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));
QCOMPARE(child->GetImage("buttonimage"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));
// Also included in GetText.
QCOMPARE(child->GetText("coverfile"), QString("The Flash (2014) Season 3_coverart.jpg"));
QCOMPARE(child->GetText("screenshotfile"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));
QCOMPARE(child->GetText("bannerfile"), QString("The Flash (2014) Season 3_banner.jpg"));
QCOMPARE(child->GetText("fanartfile"), QString("The Flash (2014) Season 3_fanart.jpg"));
QCOMPARE(child->GetText("smartimage"), QString("The Flash (2014) Season 3x4_screenshot.jpg"));

// Validate all possible GetState values
QCOMPARE(child->GetState(), QString());
QCOMPARE(child->GetState("trailerstate"), QString("hasTrailer"));
QCOMPARE(child->GetState("userratingstate"), QString("7")); // not 7.8
QCOMPARE(child->GetState("watchedstate"), QString("yes"));
QCOMPARE(child->GetState("videolevel"), QString("Lowest"));
// Also included in GetText.
QCOMPARE(child->GetText("trailerstate"), QString("hasTrailer"));
QCOMPARE(child->GetText("userratingstate"), QString("7")); // not 7.8
QCOMPARE(child->GetText("watchedstate"), QString("yes"));
QCOMPARE(child->GetText("videolevel"), QString("Lowest"));

delete root;
}

void TestVideoList::cleanupTestCase()
{
}

QTEST_APPLESS_MAIN(TestVideoList)
35 changes: 35 additions & 0 deletions mythtv/programs/mythfrontend/test/test_videolist/test_videolist.h
@@ -0,0 +1,35 @@
/*
* Class TestVideoList
*
* Copyright (c) David Hampton 2021
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <QtTest/QtTest>
#include <iostream>
#include "videometadata.h"
#include "videolist.h"

class TestVideoList : public QObject
{
Q_OBJECT

private slots:
static void initTestCase();
static void cleanupTestCase();

static void testGenericTree ();
};
@@ -0,0 +1,72 @@
include ( ../../../../settings.pro )
include ( ../../../../test.pro )

QT += network sql widgets xml testlib

TEMPLATE = app
TARGET = test_videolist
DEPENDPATH += . ../..
INCLUDEPATH += . ../..
INCLUDEPATH += ../../../../libs/libmythbase
INCLUDEPATH += ../../../../libs/libmythui
INCLUDEPATH += ../../../../libs/libmyth
INCLUDEPATH += ../../../../libs/libmythtv
INCLUDEPATH += ../../../../libs/libmythmetadata

LIBS += ../../obj/videolist.o
LIBS += ../../obj/videofilter.o ../../obj/moc_videofilter.o
LIBS += ../../obj/upnpscanner.o ../../obj/moc_upnpscanner.o

# Add all the necessary libraries
LIBS += -L../../../../libs/libmythbase -lmythbase-$$LIBVERSION
LIBS += -L../../../../libs/libmythservicecontracts -lmythservicecontracts-$$LIBVERSION
LIBS += -L../../../../libs/libmythui -lmythui-$$LIBVERSION
LIBS += -L../../../../libs/libmythupnp -lmythupnp-$$LIBVERSION
LIBS += -L../../../../libs/libmyth -lmyth-$$LIBVERSION
LIBS += -L../../../../libs/libmythtv -lmythtv-$$LIBVERSION
LIBS += -L../../../../libs/libmythmetadata -lmythmetadata-$$LIBVERSION
# Add FFMpeg for libmythtv
LIBS += -L../../../../external/FFmpeg/libswresample -lmythswresample
LIBS += -L../../../../external/FFmpeg/libavutil -lmythavutil
LIBS += -L../../../../external/FFmpeg/libavcodec -lmythavcodec
LIBS += -L../../../../external/FFmpeg/libswscale -lmythswscale
LIBS += -L../../../../external/FFmpeg/libavformat -lmythavformat
LIBS += -L../../../../external/FFmpeg/libavfilter -lmythavfilter
LIBS += -L../../../../external/FFmpeg/libpostproc -lmythpostproc
using_mheg:LIBS += -L../../../../libs/libmythfreemheg -lmythfreemheg-$$LIBVERSION

using_mheg:QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythfreemheg
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythmetadata
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythtv
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmyth
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythservicecontracts
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythupnp
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythui
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../libs/libmythbase
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavutil
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libswscale
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavformat
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavfilter
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavcodec
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libpostproc
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libswresample
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../

!using_libexiv_external {
LIBS += -L../../../../external/libexiv2 -lmythexiv2-0.28
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/libexiv2 -lexpat
freebsd: LIBS += -lprocstat -liconv
darwin: LIBS += -liconv -lz
}

# Input
HEADERS += test_videolist.h
SOURCES += test_videolist.cpp

QMAKE_CLEAN += $(TARGET)
QMAKE_CLEAN += ; ( cd $(OBJECTS_DIR) && rm -f *.gcov *.gcda *.gcno )

LIBS += $$EXTRA_LIBS $$LATE_LIBS

# Fix runtime linking
linux:QMAKE_LFLAGS += -Wl,--disable-new-dtags
2 changes: 1 addition & 1 deletion mythtv/programs/mythfrontend/videolist.cpp
Expand Up @@ -296,7 +296,7 @@ static MythGenericTree *AddDirNode(
return sub_node;
}

static int AddFileNode(MythGenericTree *where_to_add, const QString& name,
int AddFileNode(MythGenericTree *where_to_add, const QString& name,
VideoMetadata *metadata)
{
MythGenericTree *sub_node = where_to_add->addNode(name, 0, true);
Expand Down
3 changes: 3 additions & 0 deletions mythtv/programs/mythfrontend/videolist.h
Expand Up @@ -61,6 +61,9 @@ class VideoList
class VideoListImp *m_imp;
};

int AddFileNode(MythGenericTree *where_to_add, const QString& name,
VideoMetadata *metadata);

class VideoMetadata;
class TreeNodeData
{
Expand Down
11 changes: 11 additions & 0 deletions mythtv/programs/programs.pro
Expand Up @@ -11,6 +11,12 @@ using_frontend {
SUBDIRS += mythpreviewgen mythmediaserver mythccextractor
SUBDIRS += mythscreenwizard
!mingw:!win32-msvc*: SUBDIRS += mythtranscode/external/replex

# unit tests mythfrontend
mythfrontend-test.depends = sub-mythfrontend
mythfrontend-test.target = buildtestmythfrontend
mythfrontend-test.commands = cd mythfrontend/test && $(QMAKE) && $(MAKE)
unix:QMAKE_EXTRA_TARGETS += mythfrontend-test
}

using_backend {
Expand All @@ -23,3 +29,8 @@ using_backend {
}

using_mythtranscode: SUBDIRS += mythtranscode

unittest.depends = mythfrontend-test
unittest.target = test
unittest.commands = scripts/unittests.sh
unix:QMAKE_EXTRA_TARGETS += unittest

0 comments on commit baec807

Please sign in to comment.