MediaTests.cpp 4.27 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

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
112
TEST_F( Medias, Thumbnail )
113
{
114
    auto f = ml->addFile( "media.avi" );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
115
    ASSERT_EQ( f->thumbnail(), "" );
116

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
117
    std::string newThumbnail( "/path/to/thumbnail" );
118

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
119
    f->setThumbnail( newThumbnail );
120
    f->save();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
121
    ASSERT_EQ( f->thumbnail(), newThumbnail );
122
123
124

    Reload();

125
    auto f2 = ml->media( f->id() );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
126
    ASSERT_EQ( f2->thumbnail(), newThumbnail );
127
}
128
129
130

TEST_F( Medias, PlayCount )
{
131
    auto f = ml->addFile( "media.avi" );
132
133
134
135
136
137
138
    ASSERT_EQ( 0, f->playCount() );
    f->increasePlayCount();
    ASSERT_EQ( 1, f->playCount() );
    f->save();

    Reload();

139
    f = std::static_pointer_cast<Media>( ml->media( f->id() ) );
140
141
    ASSERT_EQ( 1, f->playCount() );
}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

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() );
}