diff --git a/mythtv/Makefile b/mythtv/Makefile index d6fef68cecf..ba3fa91b024 100644 --- a/mythtv/Makefile +++ b/mythtv/Makefile @@ -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..." diff --git a/mythtv/programs/mythfrontend/test/test.pro b/mythtv/programs/mythfrontend/test/test.pro new file mode 100644 index 00000000000..d5e353415ea --- /dev/null +++ b/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 diff --git a/mythtv/programs/mythfrontend/test/test_videolist/.gitignore b/mythtv/programs/mythfrontend/test/test_videolist/.gitignore new file mode 100644 index 00000000000..4bed75d9c2c --- /dev/null +++ b/mythtv/programs/mythfrontend/test/test_videolist/.gitignore @@ -0,0 +1 @@ +test_videolist diff --git a/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.cpp b/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.cpp new file mode 100644 index 00000000000..d6f52fe364e --- /dev/null +++ b/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 sOverrides; + sOverrides["FilenameTemplate"] = "abc"; + gCoreContext->setTestStringSettings(sOverrides); + + QMap 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) diff --git a/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.h b/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.h new file mode 100644 index 00000000000..b023de7426e --- /dev/null +++ b/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 +#include +#include "videometadata.h" +#include "videolist.h" + +class TestVideoList : public QObject +{ + Q_OBJECT + +private slots: + static void initTestCase(); + static void cleanupTestCase(); + + static void testGenericTree (); +}; diff --git a/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.pro b/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.pro new file mode 100644 index 00000000000..78fa2a661ee --- /dev/null +++ b/mythtv/programs/mythfrontend/test/test_videolist/test_videolist.pro @@ -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 diff --git a/mythtv/programs/mythfrontend/videolist.cpp b/mythtv/programs/mythfrontend/videolist.cpp index 59a99837749..922ec51cbd2 100644 --- a/mythtv/programs/mythfrontend/videolist.cpp +++ b/mythtv/programs/mythfrontend/videolist.cpp @@ -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); diff --git a/mythtv/programs/mythfrontend/videolist.h b/mythtv/programs/mythfrontend/videolist.h index cbf48fb9520..bbb1a26078e 100644 --- a/mythtv/programs/mythfrontend/videolist.h +++ b/mythtv/programs/mythfrontend/videolist.h @@ -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 { diff --git a/mythtv/programs/programs.pro b/mythtv/programs/programs.pro index 1977824a952..caddd5a96b2 100644 --- a/mythtv/programs/programs.pro +++ b/mythtv/programs/programs.pro @@ -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 { @@ -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