The Winamp Remote Control suite
a remote control client and plugin for Winamp 2.x, 5.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ClientSuite.cpp
Go to the documentation of this file.
1 #include <string.h>
2 #include "WinampClientBase.h"
3 #include "ClientBinder.h"
4 #include "ContextInfo.h"
5 #include "RPCException.h"
6 #include "StringVectorPrinter.h"
7 #include "catch.hpp"
8 
9 namespace WinampRemote
10 {
11 namespace UnitTest
12 {
13 
18 {
27  // NOTA BENE: declaration order guarantees the correct initialisation order
28  TestContext() : ci(), binder(ci.computername().c_str(), "\\pipe\\winampremote")
29  {
30  }
31 
32 };
33 
34 } // end namespace UnitTest
35 } // end namespace WinampRemote
36 
37 
41 TEST_CASE("Client/Version", "test server version")
42 {
45  CHECK(client.winampVersion() >= 0);
46 
47 }
48 
52 TEST_CASE("Client/Status", "test server status")
53 {
56  WAPlaybackStatus status = client.getPlaybackStatus();
57  CHECK( ((status == WA_NOT_PLAYING) || (status == WA_PLAYING) || (status == WA_PAUSED)) );
58 
59 }
60 
64 TEST_CASE("Client/Play", "test play")
65 {
68  INFO("initiate play request");
69  client.playSong();
70  INFO("the process is not synchronous and takes a while");
71  Sleep(500);
72  INFO("test playback state");
73  CHECK( client.getPlaybackStatus() == WA_PLAYING );
74 
75 }
76 
80 TEST_CASE("Client/Pause", "test pause")
81 {
84  INFO("initiate play request");
85  client.playSong();
86  INFO("the process is not synchronous and takes a while");
87  Sleep(500);
88  CHECK( client.getPlaybackStatus() == WA_PLAYING );
89  INFO("state is playing - initiate pause request");
90  client.pause();
91  INFO("the process is not synchronous and takes a while");
92  Sleep(500);
93  INFO("test playback state");
94  CHECK( client.getPlaybackStatus() == WA_PAUSED );
95 
96 }
97 
101 TEST_CASE("Client/Stop", "test stop")
102 {
105  INFO("initiate play request");
106  client.playSong();
107  INFO("the process is not synchronous and takes a while");
108  Sleep(500);
109  CHECK( client.getPlaybackStatus() == WA_PLAYING );
110  INFO("state is playing - initiate stop request");
111  client.stopSong();
112  INFO("the process is not synchronous and takes a while");
113  Sleep(500);
114  CHECK( client.getPlaybackStatus() == WA_NOT_PLAYING );
115 
116 }
117 
121 TEST_CASE("Client/PlaylistItem", "test playlist item")
122 {
125 
126  string playlistItem = client.getPlayListItem(0);
127  CHECK(playlistItem == client.getPlayListItem(0));
128 
129 }
130 
134 TEST_CASE("Client/PlaylistCurrentItem", "test playlist current item")
135 {
138 
139  string current = client.getPlayListItem(1);
140  client.setPlaylistIndex(1);
141  Sleep(1000);
142  int index = client.getCurrentPlayPosition();
143  CHECK(index == 1);
144  string playlistItem = client.getCurrentPlayListItem(index);
145  CHECK(current == playlistItem);
146 
147 }
148 
152 TEST_CASE("Client/PlaylistSize", "test getPlaylistLength")
153 {
156 
157  vector<string> playList ( client.getPlayList() );
158  CHECK( playList.size() == (unsigned int) client.getPlaylistLength() );
159 
160 }
161 
165 TEST_CASE("Client/SendString", "test sendString")
166 {
169 
170  client.sendString();
171  // this returns void: what is a valid test?
172  CHECK(true);
173 }
174 
178 TEST_CASE("Client/SongNext", "test nextSong")
179 {
182 
183  client.setShuffle(false);
184  client.setPlaylistIndex(1);
185  Sleep(1000);
186  CHECK(client.getCurrentPlayPosition() == 1);
187  client.nextSong();
188  Sleep(1000);
189  CHECK(client.getCurrentPlayPosition() == 2);
190 }
191 
195 TEST_CASE("Client/SongPrevious", "test previousSong")
196 {
199 
200  client.setShuffle(false);
201  client.setPlaylistIndex(2);
202  Sleep(1000);
203  CHECK(client.getCurrentPlayPosition() == 2);
204  client.previousSong();
205  Sleep(1000);
206  CHECK(client.getCurrentPlayPosition() == 1);
207 
208 }
209 
213 TEST_CASE("Client/PlaylistStart", "test playlistStart position")
214 {
217 
218  client.setPlaylistIndex(2);
219  Sleep(1000);
220  CHECK(client.getCurrentPlayPosition() == 2);
221  client.playlistStart();
222  Sleep(1000);
223  CHECK(client.getCurrentPlayPosition() == 0);
224 }
225 
229 TEST_CASE("Client/PlaylistEnd", "test playlistEnd")
230 {
233 
234  client.playlistEnd();
235  Sleep(1000);
236  CHECK( client.getCurrentPlayPosition() == client.getPlaylistLength() - 1);
237 }
238 
242 TEST_CASE("Client/PlaylistIndexSet", "test setPlaylistIndex")
243 {
246 
247  client.setPlaylistIndex(0);
248  CHECK(client.getCurrentPlayPosition() == 0);
249 }
250 
254 TEST_CASE("Client/PlaylistStartBegins", "test startPlaylist begins play")
255 {
258 
259  client.stopSong();
260  client.startPlaylist();
261  CHECK(client.getPlaybackStatus() == WA_PLAYING);
262 }
263 
264 TEST_CASE("Client/SetPlaylist", "test setPlaylist")
265 {
266 
269 
270  vector<string> originalPlayList (client.getPlayList(false) );
271 
272  WinampRemote::Utils::StringVectorPrinter original(originalPlayList);
273  CAPTURE(original);
274 
275  client.setPlayList(originalPlayList);
276 
277  WinampRemote::Utils::StringVectorPrinter current(originalPlayList);
278  CAPTURE(current);
279 
280  CHECK(original.sstr.str() == current.sstr.str());
281 
282 }
286 TEST_CASE("Client/DeletePlaylist", "test deletePlaylist")
287 {
290 
291  vector<string> originalPlayList ( client.getPlayList() );
292 
293 
295 
296  CHECK( originalPlayList.size() == (unsigned int) client.getPlaylistLength() );
297  client.deletePlaylist();
298 
299  CHECK( 0 == client.getPlaylistLength() );
300 
301  client.setPlayList(originalPlayList);
302 
303  vector<string> playList ( client.getPlayList() );
304 
305 // CAPTURE(WinampRemote::Utils::StringVectorPrinter((playList));
306 
307  CHECK( originalPlayList.size() == playList.size() );
308 }
309 
313 TEST_CASE("Client/InsertPlaylist", "test insertPlaylist")
314 {
317 
318  vector<string> originalPlayList ( client.getPlayList(false) );
319 
320  WinampRemote::Utils::StringVectorPrinter original (originalPlayList);
321  CAPTURE(original);
322 
323  client.insertPlayList(originalPlayList, 10);
324 
325  vector<string> newPlayList (client.getPlayList(false) );
326 
327  WinampRemote::Utils::StringVectorPrinter current (newPlayList);
328  CAPTURE(current);
329 
330  unsigned int newListLength = client.getPlaylistLength();
331  client.setPlayList(originalPlayList);
332 
333  CHECK( (newPlayList.size()) == newListLength );
334 
335  CHECK( (2 * originalPlayList.size()) == newListLength );
336 
337 
338 }
339 
340 
344 TEST_CASE("Client/StopWithFade", "test stopWithFade")
345 {
348 
349  client.startPlaylist();
350  client.stopWithFade();
351  CHECK(client.getPlaybackStatus() == WA_PLAYING);
352 
353  int songLength = 0, songPos = 0;
354  client.getTimes(songLength, songPos);
355  CAPTURE(songLength);
356  CAPTURE(songPos);
357  client.setTime((songLength * 1000) - 500);
358  CAPTURE(client.getTime());
359  Sleep(1000);
360  CAPTURE(client.getTime());
361 }
362 
366 TEST_CASE("Client/StopAfterCurrent", "test stopAfterCurrent")
367 {
370 
371  client.startPlaylist();
372  client.stopAfterCurrent();
373  CHECK(client.getPlaybackStatus() == WA_PLAYING);
374 
375  int songLength = 0, songPos = 0;
376  client.getTimes(songLength, songPos);
377  CAPTURE(songLength);
378  CAPTURE(songPos);
379  client.setTime((songLength * 1000) - 500);
380  CAPTURE(client.getTime());
381  Sleep(1000);
382  CAPTURE(client.getTime());
383 
385 
386 }
387 
391 TEST_CASE("Client/TimeSet", "test setTime")
392 {
395 
396  client.startPlaylist();
397  client.pause();
398  client.setTime(3000);
399  CHECK( abs (client.getTime() - 3000 ) < 1000 );
400 }
401 
405 TEST_CASE("Client/Forward5", "test forward5")
406 {
409 
410  client.playSong();
411  client.setTime(7000);
412  Sleep(50);
413  client.forward5();
414  Sleep(50);
415  CHECK( abs ( client.getTime() - 12000) < 1000 );
416 }
417 
421 TEST_CASE("Client/Back5", "test back5")
422 {
425 
426  client.playSong();
427  Sleep(100);
428  client.setTime(13000);
429  Sleep(100);
430  client.back5();
431  Sleep(100);
432  CAPTURE(client.getPlaybackStatus());
433  CAPTURE(client.getTime());
434  CHECK( abs ( client.getTime() - 8000) < 1000 );
435 }
436 
440 TEST_CASE("Client/VolumeUp", "test volumeUp")
441 {
444 
445  int volume = client.getVolume();
446  if (volume == 255)
447  {
448  client.setVolume(254);
449  volume = client.getVolume();
450  }
451  client.volumeUp();
452  CHECK(client.getVolume() == volume + 1);
453 }
454 
458 TEST_CASE("Client/VolumeDown", "test volumeDown")
459 {
462 
463  int volume = client.getVolume();
464  if (volume == 0)
465  {
466  client.setVolume(1);
467  volume = client.getVolume();
468  }
469  client.volumeDown();
470  CHECK(client.getVolume() == volume - 1);
471 }
472 
476 TEST_CASE("Client/VolumeSet", "test setVolume")
477 {
480 
481  client.setVolume(50);
482  CHECK(client.getVolume() == 50);
483 }
484 
488 TEST_CASE("Client/PanningSet", "test setPanning")
489 {
492 
493  client.setPanning(0);
494  CHECK(client.getPanning() == 0);
495 }
496 
497 
501 TEST_CASE("Client/PanningGet", "test getPanning")
502 {
505 
506  int panning = client.getPanning();
507  CHECK(client.getPanning() == panning);
508 }
509 
513 TEST_CASE("Client/ShuffleToggle", "test toggleShuffle")
514 {
517 
518  int shuffle = client.getShuffle();
519  client.toggleShuffle();
520  CHECK(client.getShuffle() != shuffle);
521 }
522 
526 TEST_CASE("Client/ShuffleSet", "test setShuffle")
527 {
530 
531  client.setShuffle(0);
532  CHECK(0 == client.getShuffle());
533  client.setShuffle(1);
534  CHECK(1 == client.getShuffle());
535 
536 }
537 
541 TEST_CASE("Client/ShuffleGet", "test getShuffle")
542 {
545 
546  int shuffle = client.getShuffle();
547  CHECK(shuffle == client.getShuffle());
548 }
549 
553 TEST_CASE("Client/RepeatToggle", "test toggleRepeat")
554 {
557 
558  int repeat = client.getRepeat();
559  client.toggleRepeat();
560  CHECK(client.getRepeat() != repeat);
561 }
562 
566 TEST_CASE("Client/RepeatSet", "test setRepeat")
567 {
570 
571  client.setRepeat(1);
572  CHECK(client.getRepeat() == 1);
573  client.setRepeat(0);
574  CHECK(client.getRepeat() == 0);
575 
576 
577 
578 }
579 
583 TEST_CASE("Client/RepeatGet", "test getRepeat")
584 {
587 
588  int repeat = client.getRepeat();
589  CHECK(repeat == client.getRepeat());
590 
591 }
592 
596 TEST_CASE("Client/AutoloadToggle", "test toggleAutoload")
597 {
600 
601  int autoload = client.getAutoload();
602  client.toggleAutoload();
603  CHECK(client.getAutoload() != autoload);
604 }
605 
609 TEST_CASE("Client/AutoloadSet", "test setAutoload")
610 {
613 
614  client.setAutoload(0);
615  CHECK(client.getAutoload() == 0);
616  client.setAutoload(1);
617  CHECK(client.getAutoload() == 1);
618 }
619 
623 TEST_CASE("Client/AutoloadGet", "test getAutoload")
624 {
627 
628  int current = client.getAutoload();
629  CHECK(current == client.getAutoload());
630 }
631 
635 TEST_CASE("Client/EQOnToggle", "test toggleEQ")
636 {
639 
640  int previous = client.getEQOn();
641  client.toggleEQOn();
642  CHECK(client.getEQOn() != previous);
643 }
644 
648 TEST_CASE("Client/EQOnSet", "test setEQOn")
649 {
652 
653  client.setEQOn(0);
654  CHECK(client.getEQOn() == 0);
655  client.setEQOn(1);
656  CHECK(client.getEQOn() == 1);
657 }
658 
662 TEST_CASE("Client/EQOnGet", "test getAutoload")
663 {
666 
667  int current = client.getEQOn();
668  CHECK(current == client.getEQOn());
669 }
670 
674 TEST_CASE("Client/TimesGet", "test getTimes")
675 {
678 
679  int songLength, songPos;
680  client.startPlaylist();
681  client.getTimes(songLength, songPos);
682  CHECK(songPos > 0);
683  CHECK(songLength > 0);
684 }
685 
689 TEST_CASE("Client/EQGet", "test getEQ")
690 {
693  for (int eqindex = 0 ; eqindex < 11 ; eqindex++)
694  {
695  byte eqvalue = client.getEQData(eqindex);
696  CHECK(eqvalue == (byte) client.getEQData(eqindex));
697  }
698 }
699 
703 TEST_CASE("Client/EQSet", "test setEQ")
704 {
707  int eqvalues[11] = {0};
708  for (int eqindex = 0 ; eqindex < 11 ; eqindex++)
709  {
710  eqvalues[eqindex] = client.getEQData(eqindex);
711  client.setEQData(eqindex, eqvalues[eqindex] + 1);
712  }
713 
714  for (int eqindex = 0 ; eqindex < 11 ; eqindex++)
715  {
716  CHECK(client.getEQData(eqindex) == eqvalues[eqindex] + 1);
717  }
718 
719 }
720 
724 TEST_CASE_NORETURN( "Exception/ERPCException", "ERPCException can be handled" )
725 {
726  REQUIRE_THROWS_AS(throw ERPCException(RPC_S_UNKNOWN_PRINCIPAL), ERPCException);
727 }
728 
729