File indexing completed on 2024-04-28 04:48:12
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 "ImporterMocks.h" 0018 0019 #include "EngineController.h" 0020 #include "core/support/Amarok.h" 0021 #include "core/support/Components.h" 0022 0023 using namespace ::testing; 0024 0025 MockProvider::MockProvider( const QVariantMap &config, StatSyncing::ImporterManager *manager ) 0026 : StatSyncing::ImporterProvider( config, manager ) 0027 { 0028 } 0029 0030 QVariantMap 0031 MockProvider::config() const 0032 { 0033 return m_config; 0034 } 0035 0036 StatSyncing::ImporterManager* 0037 MockProvider::manager() const 0038 { 0039 return m_manager; 0040 } 0041 0042 MockManager::MockManager() 0043 { 0044 } 0045 0046 StatSyncing::ProviderPtrMap 0047 MockManager::providers() 0048 { 0049 return m_providers; 0050 } 0051 0052 StatSyncing::ImporterProviderPtr 0053 MockManager::concreteNewInstance( const QVariantMap &cfg ) 0054 { 0055 return StatSyncing::ImporterProviderPtr( new NiceMock<MockProvider>( cfg, this ) ); 0056 } 0057 0058 void 0059 MockManager::providerForgottenProxy( const QString &providerId ) 0060 { 0061 return StatSyncing::ImporterManager::slotProviderForgotten( providerId ); 0062 } 0063 0064 MockController::MockController( QObject *parent ) 0065 : StatSyncing::Controller( parent ) 0066 { 0067 } 0068 0069 void 0070 ImporterMocks::initTestCase() 0071 { 0072 DefaultValue<QString>::Set( QString() ); 0073 DefaultValue<QIcon>::Set( QIcon() ); 0074 DefaultValue<KPluginInfo>::Set( KPluginInfo() ); 0075 0076 m_engineController = new EngineController; 0077 Amarok::Components::setEngineController( m_engineController ); 0078 } 0079 0080 void 0081 ImporterMocks::init() 0082 { 0083 m_mockManager = new NiceMock<MockManager>; 0084 ON_CALL( *m_mockManager, newInstance( _ ) ) 0085 .WillByDefault( Invoke( m_mockManager, &MockManager::concreteNewInstance ) ); 0086 0087 ON_CALL( *m_mockManager, type() ).WillByDefault( Return( "randomType" ) ); 0088 0089 QVariantMap cfg; 0090 cfg["uid"] = QString( "providerUid" ); 0091 m_mockProvider = new NiceMock<MockProvider>( cfg, m_mockManager ); 0092 0093 m_mockController = new NiceMock<MockController>; 0094 Amarok::Components::setStatSyncingController( m_mockController ); 0095 } 0096 0097 void 0098 ImporterMocks::cleanup() 0099 { 0100 delete m_mockProvider; 0101 m_mockProvider = nullptr; 0102 0103 delete m_mockManager; 0104 m_mockManager = nullptr; 0105 0106 Amarok::Components::setStatSyncingController( nullptr ); 0107 delete m_mockController; 0108 m_mockController = nullptr; 0109 0110 Amarok::config( "Importers" ).deleteGroup(); 0111 } 0112 0113 void 0114 ImporterMocks::cleanupTestCase() 0115 { 0116 Amarok::config( "StatSyncing" ).deleteGroup(); 0117 Amarok::Components::setEngineController( nullptr ); 0118 delete m_engineController; 0119 } 0120