MediaTests.cpp 4.16 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
#include "Tests.h"
24
25

#include "IMediaLibrary.h"
26
#include "Media.h"
27
28
29
#include "Artist.h"
#include "Album.h"
#include "AlbumTrack.h"
30

31
class Medias : public Tests
32
33
34
35
{
};


36
TEST_F( Medias, Init )
37
38
39
40
{
    // only test for correct test fixture behavior
}

41
TEST_F( Medias, Create )
42
{
43
    auto f = ml->addFile( "media.avi", nullptr );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44
    ASSERT_NE( f, nullptr );
45
46

    ASSERT_EQ( f->playCount(), 0 );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
47
48
    ASSERT_EQ( f->albumTrack(), nullptr );
    ASSERT_EQ( f->showEpisode(), nullptr );
49
    ASSERT_TRUE( f->isStandAlone() );
50
    ASSERT_FALSE( f->isParsed() );
51
    ASSERT_EQ( f->duration(), -1 );
52
    ASSERT_NE( 0u, f->insertionDate() );
53

54
    auto files = ml->files();
55
56
57
58
    ASSERT_EQ( files.size(), 1u );
    ASSERT_EQ( files[0]->mrl(), f->mrl() );
}

59
TEST_F( Medias, Fetch )
60
{
61
    auto f = ml->addFile( "media.avi", nullptr );
62
    auto f2 = std::static_pointer_cast<Media>( ml->file( "media.avi" ) );
63
64
    ASSERT_EQ( f->mrl(), f2->mrl() );
    ASSERT_EQ( f, f2 );
65
66

    // Flush cache and fetch from DB
67
    Reload();
68

69
    f2 = std::static_pointer_cast<Media>( ml->file( "media.avi" ) );
70
    ASSERT_EQ( f->mrl(), f2->mrl() );
71
    ASSERT_TRUE( f2->isStandAlone() );
72
73
}

74
TEST_F( Medias, Delete )
75
{
76
    auto f = ml->addFile( "media.avi", nullptr );
77
    auto f2 = ml->file( "media.avi" );
78
79
80

    ASSERT_EQ( f, f2 );

81
    ml->deleteFile( f.get() );
82
    f2 = ml->file( "media.avi" );
83
84
    ASSERT_EQ( f2, nullptr );
}
85

86
TEST_F( Medias, LastModificationDate )
87
{
88
    auto f = ml->addFile( "media.avi", nullptr );
89
90
    ASSERT_NE( 0u, f->lastModificationDate() );

91
    Reload();
92
    auto f2 = std::static_pointer_cast<Media>( ml->file( "media.avi" ) );
93
94
    ASSERT_EQ( f->lastModificationDate(), f2->lastModificationDate() );
}
95

96
TEST_F( Medias, Duration )
97
{
98
    auto f = ml->addFile( "media.avi", nullptr );
99
    ASSERT_EQ( f->duration(), -1 );
100

101
102
103
104
    // Use a value that checks we're using a 64bits value
    int64_t d = int64_t(1) << 40;

    f->setDuration( d );
105
    f->save();
106
    ASSERT_EQ( f->duration(), d );
107
108
109

    Reload();

110
111
    auto f2 = ml->file( "media.avi" );
    ASSERT_EQ( f2->duration(), d );
112
}
113

114

115
TEST_F( Medias, Artist )
116
117
118
119
120
121
122
{
    auto f = std::static_pointer_cast<Media>( ml->addFile( "media.avi", nullptr ) );
    ASSERT_EQ( f->artist(), "" );

    std::string newArtist( "Rage Against The Otters" );

    f->setArtist( newArtist );
123
    f->save();
124
125
126
127
128
129
130
131
    ASSERT_EQ( f->artist(), newArtist );

    Reload();

    auto f2 = ml->file( "media.avi" );
    ASSERT_EQ( f2->artist(), newArtist );
}

132
TEST_F( Medias, Snapshot )
133
{
134
    auto f = ml->addFile( "media.avi", nullptr );
135
136
137
138
139
    ASSERT_EQ( f->snapshot(), "" );

    std::string newSnapshot( "/path/to/snapshot" );

    f->setSnapshot( newSnapshot );
140
    f->save();
141
142
143
144
    ASSERT_EQ( f->snapshot(), newSnapshot );

    Reload();

145
146
    auto f2 = ml->file( "media.avi" );
    ASSERT_EQ( f2->snapshot(), newSnapshot );
147
}
148
149
150
151
152
153
154
155
156
157
158
159
160
161

TEST_F( Medias, PlayCount )
{
    auto f = ml->addFile( "media.avi", nullptr );
    ASSERT_EQ( 0, f->playCount() );
    f->increasePlayCount();
    ASSERT_EQ( 1, f->playCount() );
    f->save();

    Reload();

    f = std::static_pointer_cast<Media>( ml->file( "media.avi" ) );
    ASSERT_EQ( 1, f->playCount() );
}