File: TestSqlArtist.cpp

package info (click to toggle)
amarok 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,344 kB
  • sloc: cpp: 195,053; xml: 4,329; ansic: 2,634; javascript: 673; ruby: 528; python: 507; sh: 252; makefile: 12
file content (104 lines) | stat: -rw-r--r-- 4,869 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/****************************************************************************************
 * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com>       *
 *                                                                                      *
 * This program is free software; you can redistribute it and/or modify it under        *
 * the terms of the GNU General Public License as published by the Free Software        *
 * Foundation; either version 2 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 General Public License for more details.             *
 *                                                                                      *
 * You should have received a copy of the GNU General Public License along with         *
 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
 ****************************************************************************************/

#include "TestSqlArtist.h"

#include "DefaultSqlQueryMakerFactory.h"
#include "core/meta/Meta.h"
#include "core-impl/storage/sql/mysqlestorage/MySqlEmbeddedStorage.h"
#include "SqlCollection.h"
#include "SqlMountPointManagerMock.h"


QTEST_GUILESS_MAIN( TestSqlArtist )

QTemporaryDir *TestSqlArtist::s_tmpDir = nullptr;

TestSqlArtist::TestSqlArtist()
    : QObject()
    , m_collection( nullptr )
    , m_storage( nullptr )
{
    std::atexit([]() { delete TestSqlArtist::s_tmpDir; } );
}

void
TestSqlArtist::initTestCase()
{
    if( !s_tmpDir )
        s_tmpDir = new QTemporaryDir();
    m_storage = QSharedPointer<MySqlEmbeddedStorage>( new MySqlEmbeddedStorage() );
    QVERIFY( m_storage->init( s_tmpDir->path() ) );
    m_collection = new Collections::SqlCollection( m_storage );
    m_collection->setMountPointManager( new SqlMountPointManagerMock( this, m_storage ) );
}

void
TestSqlArtist::cleanupTestCase()
{
    delete m_collection;
}

void
TestSqlArtist::init()
{
    //setup base data
    m_storage->query( QStringLiteral("INSERT INTO artists(id, name) VALUES (1, 'The Foo');") );
    m_storage->query( QStringLiteral("INSERT INTO artists(id, name) VALUES (2, 'No The Foo');") );
    m_storage->query( QStringLiteral("INSERT INTO artists(id, name) VALUES (3, 'artist3');") );
    m_storage->query( QStringLiteral("INSERT INTO artists(id, name) VALUES (4, 'DJ Bar');") );
    m_storage->query( QStringLiteral("INSERT INTO artists(id, name) VALUES (5, 'Bar Like No DJ');") );
    
    m_storage->query( QStringLiteral("INSERT INTO composers(id, name) VALUES (1, 'composer1');") );
    m_storage->query( QStringLiteral("INSERT INTO genres(id, name) VALUES (1, 'genre1');") );
    m_storage->query( QStringLiteral("INSERT INTO years(id, name) VALUES (1, '1');") );

    m_storage->query( QStringLiteral("INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (1, -1, './IDoNotExist.mp3', 'uid://1');") );
    m_storage->query( QStringLiteral("INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (2, -1, './IDoNotExistAsWell.mp3', 'uid://2');") );
    m_storage->query( QStringLiteral("INSERT INTO urls(id, deviceid, rpath, uniqueid ) VALUES (3, -1, './MeNeither.mp3', 'uid:/3');") );
}

void
TestSqlArtist::cleanup()
{
    m_storage->query( QStringLiteral("TRUNCATE TABLE years;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE genres;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE composers;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE albums;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE artists;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE tracks;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE urls;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE labels;") );
    m_storage->query( QStringLiteral("TRUNCATE TABLE urls_labels;") );
}

void
TestSqlArtist::testSortableName()
{
    Meta::ArtistPtr artistWithThe = m_collection->registry()->getArtist( 1 );
    QCOMPARE( artistWithThe->sortableName(), QStringLiteral( "Foo, The" ) );

    Meta::ArtistPtr artistWithoutThe = m_collection->registry()->getArtist( 2 );
    QCOMPARE( artistWithoutThe->sortableName(), QStringLiteral( "No The Foo" ) );

    Meta::ArtistPtr artistWithDJ = m_collection->registry()->getArtist( 4 );
    QCOMPARE( artistWithDJ->sortableName(), QStringLiteral( "Bar, DJ" ) );

    Meta::ArtistPtr artistWithoutDJ = m_collection->registry()->getArtist( 5 );
    QCOMPARE( artistWithoutDJ->sortableName(), QStringLiteral( "Bar Like No DJ" ) );
}