|
Freya
0.0.1
A Gtk3 MPD Client
|
00001 /*********************************************************** 00002 * This file is part of Freya 00003 * - A free MPD Gtk3 MPD Client - 00004 * 00005 * Authors: Christopher Pahl, Christoph Piechula, 00006 * Eduard Schneider 00007 * 00008 * Copyright (C) [2011-2012] 00009 * Hosted at: https://github.com/studentkittens/Freya 00010 * 00011 * __..--''``---....___ _..._ __ 00012 * /// //_.-' .-/"; ` ``<._ ``.''_ `. / // / 00013 * ///_.-' _..--.'_ `( ) ) // // 00014 * / (_..-' // (< _ ;_..__ ; `' / /// 00015 * / // // // `-._,_)' // / ``--...____..-' /// / // 00016 * Ascii-Art by Felix Lee <flee@cse.psu.edu> 00017 * 00018 * Freya is free software: you can redistribute it and/or modify 00019 * it under the terms of the GNU General Public License as published by 00020 * the Free Software Foundation, either version 3 of the License, or 00021 * (at your option) any later version. 00022 * 00023 * Freya is distributed in the hope that it will be useful, 00024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 * GNU General Public License for more details. 00027 * 00028 * You should have received a copy of the GNU General Public License 00029 * along with Freya. If not, see <http://www.gnu.org/licenses/>. 00030 **************************************************************/ 00031 #include <cxxtest/TestSuite.h> 00032 #include "Client.hh" 00033 #include <glib.h> 00034 #include <glib/gstdio.h> 00035 #include "../Log/Writer.hh" 00036 00037 /* The whole suite. One suit for each module. */ 00038 class MPDTestSuite : public CxxTest::TestSuite 00039 { 00040 MPD::Client cl; 00041 bool clientUpdated; 00042 bool connectionChanged; 00043 bool isFirstRun; 00044 00045 public: 00046 00047 /* Fixtures */ 00048 void setUp() { 00049 LogSetVerbosity(Log::LOG_WARN); 00050 clientUpdated = false; 00051 connectionChanged = false; 00052 isFirstRun = true; 00053 00054 /* Connect signals */ 00055 cl.signal_client_update().connect( 00056 sigc::mem_fun(*this,&MPDTestSuite::clientUpdate)); 00057 cl.signal_connection_change().connect( 00058 sigc::mem_fun(*this,&MPDTestSuite::connectionChange)); 00059 00060 cl.connect(); 00061 } 00062 00063 void tearDown() { 00064 cl.disconnect(); 00065 connectionChanged = false; 00066 clientUpdated = false; 00067 } 00068 00069 /* -- Signals -- */ 00070 00071 void connectionChange(bool server_changed, bool is_connected) 00072 { 00073 connectionChanged = is_connected; 00074 } 00075 00076 void clientUpdate(enum mpd_idle, MPD::NotifyData& data) 00077 { 00078 clientUpdated = true; 00079 } 00080 00081 /* --- */ 00082 00083 void testConnect() 00084 { 00085 // All those should indicate we're connected 00086 TS_ASSERT(connectionChanged); 00087 TS_ASSERT(cl.ping()); 00088 TS_ASSERT(cl.is_connected()); 00089 } 00090 00091 void testDisconnect() 00092 { 00093 cl.disconnect(); 00094 TS_ASSERT(!connectionChanged); 00095 TS_ASSERT(!cl.ping()); 00096 TS_ASSERT(!cl.is_connected()); 00097 cl.connect(); 00098 testConnect(); 00099 } 00100 00101 void testSignalClientUpdate() 00102 { 00103 // connect() should call force_update() 00104 TS_ASSERT(clientUpdated); 00105 clientUpdated = false; 00106 // lets call it ourselves 00107 cl.force_update(); 00108 TS_ASSERT(clientUpdated); 00109 clientUpdated = false; 00110 } 00111 00112 bool toggleStates[4]; 00113 00114 /* Exemplary test of one client command */ 00115 void toggleCommandsClientUpdate(mpd_idle event, MPD::NotifyData& data) { 00116 TS_ASSERT(data.get_status().get_random() == toggleStates[0]); 00117 TS_ASSERT(data.get_status().get_consume() == toggleStates[1]); 00118 TS_ASSERT(data.get_status().get_single() == toggleStates[2]); 00119 TS_ASSERT(data.get_status().get_repeat() == toggleStates[3]); 00120 } 00121 00122 void testToggleCommands() { 00123 toggleStates[0] = cl.get_status()->get_random(); 00124 toggleStates[1] = cl.get_status()->get_consume(); 00125 toggleStates[2] = cl.get_status()->get_single(); 00126 toggleStates[3] = cl.get_status()->get_repeat(); 00127 00128 cl.toggle_random(); 00129 cl.toggle_consume(); 00130 cl.toggle_single(); 00131 cl.toggle_repeat(); 00132 00133 if(isFirstRun) 00134 { 00135 isFirstRun = false; 00136 testToggleCommands(); 00137 } 00138 } 00139 };
1.8.0