AlbumTrackTests.cpp 3.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * 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.
 *****************************************************************************/

23 24 25 26
#if HAVE_CONFIG_H
# include "config.h"
#endif

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
27 28
#include "Tests.h"

29 30 31
#include "Album.h"
#include "AlbumTrack.h"
#include "Artist.h"
32
#include "Media.h"
33
#include "Genre.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
34 35 36 37 38

class AlbumTracks : public Tests
{
};

39 40 41
TEST_F( AlbumTracks, Create )
{
    auto album = ml->createAlbum( "album" );
42
    auto f = ml->addFile( "track1.mp3" );
43
    auto track = album->addTrack( f, 1, 10 );
44
    f->save();
45 46 47 48 49
    ASSERT_NE( nullptr, track );
    ASSERT_EQ( 10u, track->discNumber() );

    Reload();

50
    f = std::static_pointer_cast<Media>( ml->media( f->id() ) );
51 52
    ASSERT_EQ( 10u, f->albumTrack()->discNumber() );
}
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
53

54 55 56
TEST_F( AlbumTracks, Artist )
{
    auto album = ml->createAlbum( "album" );
57
    auto f = ml->addFile( "track1.mp3" );
58
    auto track = album->addTrack( f, 1, 0 );
59
    f->save();
60

61 62 63 64 65 66 67
    auto artist = track->artist();
    ASSERT_EQ( nullptr, artist );
    auto newArtist = ml->createArtist( "Dream Seaotter" );
    track->setArtist( newArtist );
    artist = track->artist();
    ASSERT_NE( nullptr, artist );
    ASSERT_EQ( artist->name(), newArtist->name() );
68 69 70 71

    Reload();

    // Don't reuse the "track" and "f" variable, their type differ
72 73
    auto media = ml->media( f->id() );
    auto albumTrack = media->albumTrack();
74 75 76 77
    artist = albumTrack->artist();
    ASSERT_NE( nullptr, artist );
    ASSERT_EQ( newArtist->name(), artist->name() );
    ASSERT_EQ( newArtist->id(), artist->id() );
78
}
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
TEST_F( AlbumTracks, SetGenre )
{
    auto a = ml->createAlbum( "album" );
    auto f = ml->addFile( "track.mp3" );
    auto t = a->addTrack( f, 1, 0 );
    f->save();
    auto genre = ml->createGenre( "happy underground post progressive death metal" );

    ASSERT_EQ( nullptr, t->genre() );
    t->setGenre( genre );
    ASSERT_EQ( t->genre()->name(), "happy underground post progressive death metal" );

    Reload();

    a = std::static_pointer_cast<Album>( ml->album( a->id() ) );
95
    auto tracks = a->tracks( SortingCriteria::Default, false );
96 97 98 99
    ASSERT_EQ( tracks.size(), 1u );
    auto t2 = tracks[0];
    ASSERT_EQ( t->genre()->id(), t2->albumTrack()->genre()->id() );
}
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

TEST_F( AlbumTracks, Media )
{
    auto album = ml->createAlbum( "album" );
    auto f = ml->addFile( "track1.mp3" );
    auto track = album->addTrack( f, 1, 10 );
    f->save();

    auto media = track->media();
    ASSERT_NE( nullptr, media );
    ASSERT_EQ( media->id(), f->id() );

    Reload();

    track = ml->albumTrack( track->id() );
    media = track->media();
    ASSERT_NE( nullptr, media );
    ASSERT_EQ( media->id(), f->id() );
}