HistoryTests.cpp 3.46 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*****************************************************************************
 * 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.
 *****************************************************************************/

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include "Tests.h"

#include "medialibrary/IHistoryEntry.h"
#include "History.h"
#include "Media.h"

#include "compat/Thread.h"

class HistoryTest : public Tests
{

};

TEST_F( HistoryTest, InsertMrl )
{
42 43
    auto m = ml->addMedia( "upnp://stream" );
    ml->addToStreamHistory( m );
44
    auto hList = ml->lastStreamsPlayed()->all();
45 46
    ASSERT_EQ( 1u, hList.size() );
    auto h = hList[0];
47
    ASSERT_EQ( h->media()->files()[0]->mrl(), "upnp://stream" );
48 49 50 51 52 53 54
    ASSERT_NE( 0u, h->insertionDate() );
}

TEST_F( HistoryTest, MaxEntries )
{
    for ( auto i = 0u; i < History::MaxEntries; ++i )
    {
55 56
        auto m = ml->addMedia( "http://media" + std::to_string( i ) );
        ml->addToStreamHistory( m );
57
    }
58
    auto hList = ml->lastStreamsPlayed()->all();
59
    ASSERT_EQ( History::MaxEntries, hList.size() );
60 61
    auto m = ml->addMedia("smb://new-media" );
    ml->addToStreamHistory( m );
62
    hList = ml->lastStreamsPlayed()->all();
63 64 65 66 67
    ASSERT_EQ( History::MaxEntries, hList.size() );
}

TEST_F( HistoryTest, Ordering )
{
68 69
    auto m = ml->addMedia( "first-stream" );
    ml->addToStreamHistory( m );
70
    compat::this_thread::sleep_for( std::chrono::seconds( 1 ) );
71 72
    auto m2 = ml->addMedia( "second-stream" );
    ml->addToStreamHistory( m2 );
73
    auto hList = ml->lastStreamsPlayed()->all();
74
    ASSERT_EQ( 2u, hList.size() );
75 76
    ASSERT_EQ( hList[0]->media()->id(), m2->id() );
    ASSERT_EQ( hList[1]->media()->id(), m->id() );
77 78 79 80
}

TEST_F( HistoryTest, UpdateInsertionDate )
{
81 82
    auto m = ml->addMedia( "stream" );
    ml->addToStreamHistory( m );
83
    auto hList = ml->lastStreamsPlayed()->all();
84 85 86
    ASSERT_EQ( 1u, hList.size() );
    auto date = hList[0]->insertionDate();
    compat::this_thread::sleep_for( std::chrono::seconds( 1 ) );
87
    ml->addToStreamHistory( m );
88
    hList = ml->lastStreamsPlayed()->all();
89 90 91 92 93 94
    ASSERT_EQ( 1u, hList.size() );
    ASSERT_NE( date, hList[0]->insertionDate() );
}

TEST_F( HistoryTest, ClearStreamHistory )
{
95 96 97 98
    auto m = ml->addMedia( "f00" );
    ml->addToStreamHistory( m );
    auto m2 = ml->addMedia( "bar" );
    ml->addToStreamHistory( m2 );
99
    auto history = ml->lastStreamsPlayed()->all();
100 101 102
    ASSERT_EQ( 2u, history.size() );

    ml->clearHistory();
103
    history = ml->lastStreamsPlayed()->all();
104 105 106 107
    ASSERT_EQ( 0u, history.size() );

    Reload();

108
    history = ml->lastStreamsPlayed()->all();
109 110
    ASSERT_EQ( 0u, history.size() );
}