File indexing completed on 2024-04-28 04:48:13

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com>                             *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "TestImporterProvider.h"
0018 
0019 #include "core/support/Amarok.h"
0020 #include "core/support/Components.h"
0021 
0022 #include <QSignalSpy>
0023 #include <QTest>
0024 
0025 
0026 QTEST_GUILESS_MAIN( TestImporterProvider )
0027 
0028 using namespace ::testing;
0029 
0030 void
0031 TestImporterProvider::constructorShouldSetConfigAndManager()
0032 {
0033     QVariantMap cfg;
0034     cfg["nanananana"] = QString( "Batman" );
0035     MockProvider provider( cfg, m_mockManager );
0036 
0037     QVERIFY( provider.config().contains( QString( "nanananana" ) ) );
0038     QCOMPARE( provider.manager(), m_mockManager );
0039 }
0040 
0041 void
0042 TestImporterProvider::constructorShouldSetUidIfNotSet()
0043 {
0044     QVERIFY( !MockProvider( QVariantMap(), nullptr ).id().isEmpty() );
0045 }
0046 
0047 void
0048 TestImporterProvider::idShouldReturnConfiguredId()
0049 {
0050     QVariantMap cfg;
0051     cfg["uid"] = QString( "Joker" );
0052 
0053     QCOMPARE( MockProvider( cfg, nullptr ).config(), cfg );
0054 }
0055 
0056 void
0057 TestImporterProvider::descriptionShouldDelegateToManager()
0058 {
0059     EXPECT_CALL( *m_mockManager, description() ).WillOnce( Return( QString( "Ivy" ) ) );
0060     QCOMPARE( m_mockProvider->description(), QString( "Ivy" ) );
0061 }
0062 
0063 void
0064 TestImporterProvider::iconShouldDelegateToManager()
0065 {
0066     EXPECT_CALL( *m_mockManager, icon() ).WillOnce( Return( QIcon::fromTheme( "amarok" ) ) );
0067     QCOMPARE( m_mockProvider->icon().name(), QIcon::fromTheme( "amarok" ).name() );
0068 }
0069 
0070 void
0071 TestImporterProvider::nameShouldReturnConfiguredName()
0072 {
0073     QVariantMap cfg;
0074     cfg["uid"] = QString( "Bane" );
0075     cfg["name"] = QString( "Ra's" );
0076     MockProvider provider( cfg, m_mockManager );
0077 
0078     QCOMPARE( provider.prettyName(), QString( "Ra's" ) );
0079 }
0080 
0081 void
0082 TestImporterProvider::nameShouldNotCrashIfNameIsNotConfigured()
0083 {
0084     QVariantMap cfg;
0085     cfg["uid"] = QString( "TwoFace" );
0086     MockProvider provider( cfg, m_mockManager );
0087 
0088     QCOMPARE( provider.prettyName(), QString() );
0089 }
0090 
0091 void
0092 TestImporterProvider::isConfigurableShouldReturnTrue()
0093 {
0094     QVERIFY( m_mockProvider->isConfigurable() );
0095 }
0096 
0097 void
0098 TestImporterProvider::configWidgetShouldDelegateToManager()
0099 {
0100     StatSyncing::ProviderConfigWidget *widget = nullptr;
0101     EXPECT_CALL( *m_mockManager, configWidget( Eq(m_mockProvider->config()) ) )
0102             .WillOnce( Return( widget ) );
0103     QCOMPARE( m_mockProvider->configWidget(), widget );
0104 }
0105 
0106 void
0107 TestImporterProvider::reconfigureShouldEmitSignal()
0108 {
0109     QVariantMap cfg = m_mockProvider->config();
0110     cfg["customField"] = QString( "Selena" );
0111 
0112     QSignalSpy spy( m_mockProvider, &MockProvider::reconfigurationRequested );
0113     m_mockProvider->reconfigure( cfg );
0114 
0115     QCOMPARE( spy.count(), 1 );
0116     QCOMPARE( spy.takeFirst().at( 0 ).toMap(), cfg );
0117 }
0118 
0119 void
0120 TestImporterProvider::reconfigureShouldNotEmitSignalOnDifferentUid()
0121 {
0122     QVariantMap cfg;
0123     cfg["uid"] = "Different";
0124 
0125     QSignalSpy spy( m_mockProvider, &MockProvider::reconfigurationRequested );
0126     m_mockProvider->reconfigure( cfg );
0127 
0128     QCOMPARE( spy.count(), 0 );
0129 }
0130 
0131 void
0132 TestImporterProvider::defaultPreferenceShouldReturnNoByDefault()
0133 {
0134     QCOMPARE( m_mockProvider->defaultPreference(), StatSyncing::Provider::NoByDefault );
0135 }
0136