Пример #1
0
void
TestAmazonMetaFactory::testCreateAlbum()
{
    QStringList list, list2;
    list << "id" << "name" << "description" << "artistID" << "price" << "coverUrl" << "ASIN";
    list2 << "23" << "name" << "description" << "42" << "price" << "coverUrl" << "ASIN";

    AmazonMetaFactory factory( "Amazontest" );
    Meta::AlbumPtr albumPtr = factory.createAlbum( list );
    Meta::AlbumPtr albumPtr2 = factory.createAlbum( list2 );

    QVERIFY( albumPtr );
    QVERIFY( albumPtr2 );

    Meta::AmazonAlbum* amazonAlbum = dynamic_cast<Meta::AmazonAlbum*>( albumPtr.data() );
    Meta::AmazonAlbum* amazonAlbum2 = dynamic_cast<Meta::AmazonAlbum*>( albumPtr2.data() );

    QVERIFY( amazonAlbum );
    QVERIFY( amazonAlbum2 );

    QCOMPARE( amazonAlbum->id(), 0 );
    QCOMPARE( amazonAlbum->name(), QString( "name" ) );
    QCOMPARE( amazonAlbum->description(), QString( "description" ) );
    QCOMPARE( amazonAlbum->artistId(), 0 );
    QCOMPARE( amazonAlbum->price(), QString( "price" ) );
    QCOMPARE( amazonAlbum->coverUrl(), QString( "coverUrl" ) );
    QCOMPARE( amazonAlbum->asin(), QString( "ASIN" ) );

    QCOMPARE( amazonAlbum2->id(), 23 );
    QCOMPARE( amazonAlbum2->artistId(), 42 );
}
Пример #2
0
int
AmazonParser::addAlbumToCollection( const QString &albumTitle, const QString &description, const QString &artistID, const QString &price, const QString &imgUrl, const QString &albumAsin, const bool isCompilation )
{
    QStringList results;
    QString albumID;

    debug() << albumAsin;

    if( !m_collection->albumIDMap()->contains( albumAsin ) ) // we have a new album here
    {
        // id, name, description, artistID
        albumID.setNum( m_collection->albumIDMap()->size() + 1 );
        results << albumID << albumTitle << description << artistID << price << imgUrl << albumAsin;

        Meta::AlbumPtr newAlbum = m_factory->createAlbum( results );
        dynamic_cast<Meta::AmazonAlbum*>( newAlbum.data() )->setIsCompilation( isCompilation );
        m_collection->addAlbum( newAlbum );
        m_collection->albumIDMap()->insert( albumAsin, albumID.toInt() );
    }
    else // album is known, but we might need to update it
    {
        int id;
        id = m_collection->albumIDMap()->value( albumAsin );

        if( !price.isEmpty() )
        {
            dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() )->setPrice( price );
        }

        if( !imgUrl.isEmpty() )
        {
            dynamic_cast<Meta::AmazonAlbum*>( m_collection->albumById( id ).data() )->setCoverUrl( imgUrl );
        }
    }

    // return album ID
    return m_collection->albumIDMap()->value( albumAsin );
}
void addMockTrack( Collections::CollectionTestImpl *coll, const QString &trackName, const QString &artistName, const QString &albumName )
{
    Meta::MockTrack *track = new Meta::MockTrack();
    ::testing::Mock::AllowLeak( track );
    Meta::TrackPtr trackPtr( track );
    EXPECT_CALL( *track, name() ).Times( AnyNumber() ).WillRepeatedly( Return( trackName ) );
    EXPECT_CALL( *track, prettyName() ).Times( AnyNumber() ).WillRepeatedly( Return( trackName ) );
    EXPECT_CALL( *track, uidUrl() ).Times( AnyNumber() ).WillRepeatedly( Return( trackName + '_' + artistName + '_' + albumName ) );
    EXPECT_CALL( *track, playableUrl() ).Times( AnyNumber() ).WillRepeatedly( Return( KUrl( '/' + track->uidUrl() ) ) );
    EXPECT_CALL( *track, composer() ).Times( AnyNumber() ).WillRepeatedly( Return( Meta::ComposerPtr() ) );
    EXPECT_CALL( *track, genre() ).Times( AnyNumber() ).WillRepeatedly( Return( Meta::GenrePtr() ) );
    EXPECT_CALL( *track, year() ).Times( AnyNumber() ).WillRepeatedly( Return( Meta::YearPtr() ) );
    coll->mc->addTrack( trackPtr );

    Meta::AlbumPtr albumPtr = coll->mc->albumMap().value( albumName, QString() /* no album artist */ );
    Meta::MockAlbum *album;
    Meta::TrackList albumTracks;
    if( albumPtr )
    {
        album = dynamic_cast<Meta::MockAlbum*>( albumPtr.data() );
        if( !album )
        {
            QFAIL( "expected a Meta::MockAlbum" );
            return;
        }
        albumTracks = albumPtr->tracks();
    }
    else
    {
        album = new Meta::MockAlbum();
        ::testing::Mock::AllowLeak( album );
        albumPtr = Meta::AlbumPtr( album );
        EXPECT_CALL( *album, name() ).Times( AnyNumber() ).WillRepeatedly( Return( albumName ) );
        EXPECT_CALL( *album, prettyName() ).Times( AnyNumber() ).WillRepeatedly( Return( albumName ) );
        EXPECT_CALL( *album, hasAlbumArtist() ).Times( AnyNumber() ).WillRepeatedly( Return( false ) );
        EXPECT_CALL( *album, isCompilation() ).Times( AnyNumber() ).WillRepeatedly( Return( false ) ); //inconsistent
        coll->mc->addAlbum( albumPtr );
    }
    albumTracks << trackPtr;
    EXPECT_CALL( *album, tracks() ).Times( AnyNumber() ).WillRepeatedly( Return( albumTracks ) );

    EXPECT_CALL( *track, album() ).Times( AnyNumber() ).WillRepeatedly( Return( albumPtr ) );

    Meta::ArtistPtr artistPtr = coll->mc->artistMap().value( artistName );
    Meta::MockArtist *artist;
    Meta::TrackList artistTracks;
    if( artistPtr )
    {
        artist = dynamic_cast<Meta::MockArtist*>( artistPtr.data() );
        if( !artist )
        {
            QFAIL( "expected a Meta::MockArtist" );
            return;
        }
        artistTracks = artistPtr->tracks();
    }
    else
    {
        artist = new Meta::MockArtist();
        ::testing::Mock::AllowLeak( artist );
        artistPtr = Meta::ArtistPtr( artist );
        EXPECT_CALL( *artist, name() ).Times( AnyNumber() ).WillRepeatedly( Return( artistName ) );
        EXPECT_CALL( *artist, prettyName() ).Times( AnyNumber() ).WillRepeatedly( Return( artistName ) );
        coll->mc->addArtist( artistPtr );
    }
    artistTracks << trackPtr;
    EXPECT_CALL( *artist, tracks() ).Times( AnyNumber() ).WillRepeatedly( Return( artistTracks ) );
    EXPECT_CALL( *track, artist() ).Times( AnyNumber() ).WillRepeatedly( Return( artistPtr ) );
    EXPECT_CALL( *album, albumArtist() ).Times( AnyNumber() ).WillRepeatedly( Return( artistPtr ) );
}