MediaTests.cpp 4.63 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" );
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_FALSE( f->isParsed() );
50
    ASSERT_EQ( f->duration(), -1 );
51
    ASSERT_NE( 0u, f->insertionDate() );
52

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

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

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

68
    f2 = std::static_pointer_cast<Media>( ml->media( f->id() ) );
69
    ASSERT_EQ( f->mrl(), f2->mrl() );
70
71
}

72
TEST_F( Medias, Delete )
73
{
74
    auto f = ml->addFile( "media.avi" );
75
    auto f2 = ml->media( f->id() );
76
77
78

    ASSERT_EQ( f, f2 );

79
    ml->deleteFile( f.get() );
80
    f2 = ml->media( f->id() );
81
82
    ASSERT_EQ( f2, nullptr );
}
83

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

89
    Reload();
90
    auto f2 = std::static_pointer_cast<Media>( ml->media( f->id() ) );
91
92
    ASSERT_EQ( f->lastModificationDate(), f2->lastModificationDate() );
}
93

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

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

    f->setDuration( d );
103
    f->save();
104
    ASSERT_EQ( f->duration(), d );
105
106
107

    Reload();

108
    auto f2 = ml->media( f->id() );
109
    ASSERT_EQ( f2->duration(), d );
110
}
111

112

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

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

    f->setArtist( newArtist );
121
    f->save();
122
123
124
125
    ASSERT_EQ( f->artist(), newArtist );

    Reload();

126
    auto f2 = ml->media( f->id() );
127
128
129
    ASSERT_EQ( f2->artist(), newArtist );
}

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

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

    f->setSnapshot( newSnapshot );
138
    f->save();
139
140
141
142
    ASSERT_EQ( f->snapshot(), newSnapshot );

    Reload();

143
    auto f2 = ml->media( f->id() );
144
    ASSERT_EQ( f2->snapshot(), newSnapshot );
145
}
146
147
148

TEST_F( Medias, PlayCount )
{
149
    auto f = ml->addFile( "media.avi" );
150
151
152
153
154
155
156
    ASSERT_EQ( 0, f->playCount() );
    f->increasePlayCount();
    ASSERT_EQ( 1, f->playCount() );
    f->save();

    Reload();

157
    f = std::static_pointer_cast<Media>( ml->media( f->id() ) );
158
159
    ASSERT_EQ( 1, f->playCount() );
}
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

TEST_F( Medias, Progress )
{
    auto f = ml->addFile( "media.avi" );
    ASSERT_EQ( .0f, f->progress() );
    f->setProgress( 123.0f );
    // Check that a non-sensical value is ignored
    ASSERT_EQ( .0f, f->progress() );
    f->setProgress( 0.666f );
    ASSERT_EQ( .666f, f->progress() );
    f->save();

    Reload();

    f = ml->media( f->id() );
    ASSERT_EQ( .666f, f->progress() );
}

TEST_F( Medias, Rating )
{
    auto f = ml->addFile( "media.avi" );
    ASSERT_EQ( -1, f->rating() );
    f->setRating( 12345 );
    f->save();
    ASSERT_EQ( 12345, f->rating() );

    Reload();

    f = ml->media( f->id() );
    ASSERT_EQ( 12345, f->rating() );
}