Unverified Commit 6a709e02 authored by Alexandre Fernandez's avatar Alexandre Fernandez
Browse files

ML: unittests: removed gtest from Album checks [WIP]

parent fdf052e7
......@@ -233,7 +233,7 @@ endif
if HAVE_TESTS
check_PROGRAMS = unittest samples
check_PROGRAMS = ut_album_add_track ut_album_album_artist samples
lib_LTLIBRARIES += libgtest.la libgtestmain.la
......@@ -259,51 +259,33 @@ libgtestmain_la_CPPFLAGS = $(libgtest_la_CPPFLAGS)
libgtestmain_la_CXXFLAGS = $(libgtest_la_CXXFLAGS)
libgtestmain_la_LIBADD = $(libgtest_la_LIBADD)
unittest_SOURCES = \
test/common/MediaLibraryTester.cpp \
test/mocks/FileSystem.cpp \
test/mocks/filesystem/MockDevice.cpp \
test/mocks/filesystem/MockDirectory.cpp \
test/mocks/filesystem/MockFile.cpp \
test/unittest/AlbumTests.cpp \
test/unittest/AlbumTrackTests.cpp \
test/unittest/ArtistTests.cpp \
test/unittest/AudioTrackTests.cpp \
test/unittest/DeviceTests.cpp \
test/unittest/FileTests.cpp \
test/unittest/FolderTests.cpp \
test/unittest/FsUtilsTests.cpp \
test/unittest/UrlTests.cpp \
test/unittest/GenreTests.cpp \
test/unittest/HistoryTests.cpp \
test/unittest/LabelTests.cpp \
test/unittest/MediaTests.cpp \
test/unittest/MovieTests.cpp \
test/unittest/PlaylistTests.cpp \
test/unittest/RemovalNotifierTests.cpp \
test/unittest/ShowTests.cpp \
test/unittest/Tests.cpp \
test/unittest/VideoTrackTests.cpp \
test/unittest/MiscTests.cpp \
$(NULL)
unittest_CPPFLAGS = \
UNITTEST_CPPFLAGS = \
$(MEDIALIB_CPPFLAGS) \
-I$(top_srcdir)/test \
-I$(top_srcdir)/googletest/include \
-I$(top_srcdir)/test/unittest \
$(SQLITE_CFLAGS) \
$(VLCPP_CFLAGS) \
$(VLC_CFLAGS) \
$(NULL)
unittest_LDADD = \
UNITTEST_LDADD = \
libmedialibrary.la \
libgtest.la \
libgtestmain.la \
$(PTHREAD_LIBS) \
$(SQLITE_LIBS) \
$(NULL)
UNITTEST_SOURCES = \
test/common/MediaLibraryTester.cpp \
test/unittest/Tests.cpp \
$(NULL)
ut_album_add_track_SOURCES = $(UNITTEST_SOURCES) test/unittest/Album/AlbumAddTrack.cpp
ut_album_add_track_CPPFLAGS = $(UNITTEST_CPPFLAGS)
ut_album_add_track_LDADD = $(UNITTEST_LDADD)
ut_album_album_artist_SOURCES = $(UNITTEST_SOURCES) test/unittest/Album/AlbumAlbumArtist.cpp
ut_album_album_artist_CPPFLAGS = $(UNITTEST_CPPFLAGS)
ut_album_album_artist_LDADD = $(UNITTEST_LDADD)
samples_SOURCES = \
test/common/MediaLibraryTester.cpp \
test/samples/main.cpp \
......@@ -329,6 +311,8 @@ samples_LDADD = \
$(SQLITE_LIBS) \
$(NULL)
TESTS = ut_album_add_track ut_album_album_artist
endif
pkgconfigdir = $(libdir)/pkgconfig
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestAddTrack()
{
auto a = ml->createAlbum( "albumtag" );
auto f = std::static_pointer_cast<Media>( ml->addMedia( "track.mp3" ) );
auto track = a->addTrack( f, 10, 0, 0, nullptr );
f->save();
assert( track != nullptr );
auto tracks = a->tracks( SortingCriteria::Default, false );
assert( tracks.size() == 1u );
Reload();
a = std::static_pointer_cast<Album>( ml->album( a->id() ) );
tracks = a->tracks( SortingCriteria::Default, false );
assert( tracks.size() == 1u );
assert( tracks[0]->albumTrack()->trackNumber() == track->trackNumber() );
}
int main()
{
Albums a{};
a.TestAddTrack();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestAlbumArtist()
{
auto album = ml->createAlbum( "test" );
assert( album->albumArtist() == nullptr );
auto artist = ml->createArtist( "artist" );
album->setAlbumArtist( artist );
assert( album->albumArtist() != nullptr );
Reload();
album = std::static_pointer_cast<Album>( ml->album( album->id() ) );
auto albumArtist = album->albumArtist();
assert( albumArtist != nullptr );
assert( albumArtist->name() == artist->name() );
}
int main()
{
Albums a{};
a.TestAlbumArtist();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestArtists()
{
auto album = ml->createAlbum( "album" );
auto artist1 = ml->createArtist( "john" );
auto artist2 = ml->createArtist( "doe" );
assert( album != nullptr );
assert( artist1 != nullptr );
assert( artist2 != nullptr );
auto res = album->addArtist( artist1 );
assert( res == true );
res = album->addArtist( artist2 );
assert( res == true );
auto artists = album->artists( false );
assert( artists.size() == 2u );
Reload();
album = std::static_pointer_cast<Album>( ml->album( album->id() ) );
artists = album->artists( false );
assert( album->albumArtist() == nullptr );
assert( artists.size() == 2u );
}
int main()
{
Albums a{};
a.TestArtists();
return 0;
}
......@@ -20,20 +20,27 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <Album/AlbumTests.h>
#include "gtest/gtest.h"
void Albums::TestAutoDelete()
{
auto a = ml->createAlbum( "album" );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
auto t = a->addTrack( m, 1, 1, 0, nullptr );
auto album = ml->album( a->id() );
assert( nullptr != album );
#include "utils/Url.h"
ml->deleteTrack( t->id() );
using namespace medialibrary;
album = ml->album( a->id() );
assert( nullptr != album );
}
TEST( UrlUtils, encode )
int main()
{
ASSERT_EQ( "meow", utils::url::encode( "meow" ) );
ASSERT_EQ( "plain%20space", utils::url::encode( "plain space" ) );
ASSERT_EQ( "/%C3%A1%C3%A9%C3%BA%C3%AD%C3%B3/f00/%C3%9Far", utils::url::encode( "/áéúíó/f00/ßar" ) );
ASSERT_EQ( "/file/with%23sharp", utils::url::encode( "/file/with#sharp" ) );
Albums a{};
a.TestAutoDelete();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2017 Hugo Beauzée-Luyssen, Videolabs
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
......@@ -20,21 +20,22 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <Album/AlbumTests.h>
#include "Tests.h"
class Misc : public Tests
void Albums::TestCreate()
{
};
auto a = ml->createAlbum( "album" );
assert( a != nullptr);
auto a2 = ml->album( a->id() );
assert( a == a2 );
assert( a2->title() == "album");
}
TEST_F( Misc, FileExtensions )
int main()
{
const auto supportedExtensions = ml->getSupportedExtensions();
for ( auto i = 0u; i < supportedExtensions.size() - 1; i++ )
{
ASSERT_LT( strcmp( supportedExtensions[i], supportedExtensions[i + 1] ), 0 );
}
Albums a{};
a.TestCreate();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestDuration()
{
auto a = ml->createAlbum( "album" );
assert( 0u == a->duration() );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track.mp3" ) );
m->setDuration( 100 );
m->save();
a->addTrack( m, 1, 1, 0, nullptr );
assert( 100u == a->duration() );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "track2.mp3" ) );
m2->setDuration( 200 );
m2->save();
auto t2 = a->addTrack( m2, 1, 1, 0, nullptr );
assert( 300u == a->duration() );
// Check that we don't add negative durations (default sqlite duration is -1)
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "track3.mp3" ) );
auto t3 = a->addTrack( m3, 1, 1, 0, nullptr );
assert( 300u == a->duration() );
Reload();
auto a2 = ml->album( a->id() );
assert( 300u == a2->duration() );
// Check that the duration is updated when a media/track gets removed
ml->deleteTrack( t2->id() );
Reload();
a2 = ml->album( a->id() );
assert( 100u == a2->duration() );
// And check that we don't remove negative durations
ml->deleteTrack( t3->id() );
Reload();
a2 = ml->album( a->id() );
assert( 100u == a2->duration() );
}
int main()
{
Albums a{};
a.TestDuration();
return 0;
}
......@@ -20,57 +20,28 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <Album/AlbumTests.h>
#include "Tests.h"
#include "Media.h"
#include "VideoTrack.h"
class VideoTracks : public Tests
{
};
TEST_F( VideoTracks, AddTrack )
{
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.avi" ) );
bool res = f->addVideoTrack( "H264", 1920, 1080, 29.97, "language", "description" );
ASSERT_TRUE( res );
}
TEST_F( VideoTracks, FetchTracks )
void Albums::TestFetchAlbumFromTrack()
{
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.avi" ) );
f->addVideoTrack( "H264", 1920, 1080, 29.97, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 29.97, "l2", "d2" );
// Testing fetch from initially created instance:
auto ts = f->videoTracks();
ASSERT_EQ( ts.size(), 2u );
auto t2 = ts[0];
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920u );
ASSERT_EQ( t2->height(), 1080u );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
auto a = ml->createAlbum( "album" );
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.mp3" ) );
auto t = a->addTrack( f, 1, 0, 0, nullptr );
f->save();
// Reload from DB
Reload();
auto m = ml->media( f->id() );
ASSERT_NE( nullptr, m );
ts = m->videoTracks();
ASSERT_EQ( ts.size(), 2u );
t2 = ts[0];
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920u );
ASSERT_EQ( t2->height(), 1080u );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
f = ml->media( f->id() );
auto t2 = f->albumTrack();
auto a2 = t2->album();
assert( a2 != nullptr );
assert( a2->title() == "album" );
}
int main()
{
Albums a{};
a.TestFetchAlbumFromTrack();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestFetch()
{
auto a = ml->createAlbum( "album" );
// Clear the cache
Reload();
auto a2 = ml->album( a->id() );
// The shared pointer are expected to point to a different instance
assert( a != a2 );
assert( a->id() == a2->id() );
}
int main()
{
Albums a{};
a.TestFetch();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestNbTrack()
{
auto a = ml->createAlbum( "albumtag" );
for ( auto i = 1u; i <= 10; ++i )
{
auto f = std::static_pointer_cast<Media>( ml->addMedia( "track" + std::to_string(i) + ".mp3" ) );
auto track = a->addTrack( f, i, i, 0, nullptr );
f->save();
assert( track != nullptr );
}
auto tracks = a->tracks( SortingCriteria::Default, false );
assert( tracks.size() == a->nbTracks() );
Reload();
a = std::static_pointer_cast<Album>( ml->album( a->id() ) );
tracks = a->tracks( SortingCriteria::Default, false );
assert( tracks.size() == a->nbTracks() );
}
int main()
{
Albums a{};
a.TestNbTrack();
return 0;
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <Album/AlbumTests.h>
void Albums::TestSearchAfterArtistUpdate()
{
auto a = ml->createAlbum( "sea otters" );
auto artist = ml->createArtist( "pangolin of fire" );
auto artist2 = ml->createArtist( "pangolin of ice" );
a->setAlbumArtist( artist );
auto albums = ml->searchAlbums( "fire" );
assert( 1u == albums.size() );