-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerTest.cpp
174 lines (145 loc) · 4.65 KB
/
PlayerTest.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//---------------------------------------------------------------------------
#include "../lib/Exceptions.h"
#pragma hdrstop
#include <iostream.h>
#include <vcl.h>
#include "../lib/Constants.h"
#include "../lib/extlib.h"
#include "PlayerFacade.h"
#include "ConcretePlayerFacade.h"
#include "Player.h"
//---------------------------------------------------------------------------
const AnsiString song1 = "E:\\MP3\\Klassiskt\\Arméns musikpluton - Under blågul fana.mp3";
const AnsiString song2 = "E:\\MP3\\Hårdrock\\ACDC - TNT.mp3";
const AnsiString song3 = "E:\\MP3\\(album)\\Absolute Relaxed 2002\\cd2\\07 - Michael Nyman - The heart asks pleasure first the piano.mp3";
const AnsiString song4 = "E:\\MP3\\Folkmusik\\Orsa spelmän - Brudmarsch från Delsbo.mp3";
void testCreation();
void testWithExternalPlayerShutdown(PlayerFacade *);
void testBasicFunctions(PlayerFacade *);
#pragma argsused
int main(int argc, char* argv[])
{
bool failed;
PlayerFacade *pPlayerFacade;
pPlayerFacade = new ConcretePlayerFacade();
pPlayerFacade->setPlayer("Winamp2", "C:\\Program Files\\Winamp\\Winamp.exe");
try {
testCreation();
testWithExternalPlayerShutdown(pPlayerFacade);
testBasicFunctions(pPlayerFacade);
}
catch(Exception &) {
cout << "Ett oväntat undantag inträffade!";
}
char c;
cout << "done.\n";
cin >> c;
delete pPlayerFacade;
pPlayerFacade = 0;
return 0;
}
//---------------------------------------------------------------------------
void testCreation()
{
bool fail;
PlayerFacade *pPlayerFacade = 0;
try {
fail = true;
pPlayerFacade = new ConcretePlayerFacade();
pPlayerFacade->setPlayer("k", "C:\\Program Files\\Winamp\\Winamp.exe");
}
catch(InvalidPlayerTypeException &) {
fail = false;
}
Assert(fail != true, "testCreation 1");
try {
fail = true;
pPlayerFacade = new ConcretePlayerFacade();
pPlayerFacade->setPlayer("Winamp2", "?åäö\\\\\\§..//+~");
}
catch(FileNotFoundException &) {
fail = false;
}
Assert(fail != true, "testCreation 2");
if(pPlayerFacade)
delete pPlayerFacade;
}
//---------------------------------------------------------------------------
void testWithExternalPlayerShutdown(PlayerFacade *pPf)
{
bool fail;
pPf->close();
Sleep(1000);
try {
fail = true;
pPf->getStatus();
}
catch(PlayerNotAvailableException &) {
fail = false;
}
Assert(fail != true, "testWithExternalPlayerShutdown 1");
try {
fail = true;
pPf->play();
}
catch(PlayerNotAvailableException &) {
fail = false;
}
Assert(fail != true, "testWithExternalPlayerShutdown 2");
try {
fail = true;
pPf->getPlayedFile();
}
catch(PlayerNotAvailableException &) {
fail = false;
}
Assert(fail != true, "testWithExternalPlayerShutdown 3");
}
//---------------------------------------------------------------------------
void testBasicFunctions(PlayerFacade *pPf)
{
bool fail;
pPf->play(song1);
Sleep(2000);
Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 1");
Assert(pPf->getPlayedFile() == song1, "testBasicFunctions 2");
pPf->enqueue(song2);
Sleep(500);
Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 3");
Assert(pPf->getPlayedFile() == song1, "testBasicFunctions 4");
pPf->pause();
Sleep(100);
Assert(pPf->getStatus() == PLAYER_PAUSED, "testBasicFunctions 5");
pPf->pause();
Sleep(100);
Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 6");
pPf->stop();
Sleep(100);
Assert(pPf->getStatus() == PLAYER_STOPPED, "testBasicFunctions 7");
pPf->nextTrack();
Sleep(100);
Assert(pPf->getPlayedFile() == song2, "testBasicFunctions 8");
pPf->previousTrack();
pPf->play();
Sleep(200);
Assert(pPf->getPlayedFile() == song1, "testBasicFunctions 9");
Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 10");
pPf->saveAndStop();
Sleep(100);
Assert(pPf->getStatus() == PLAYER_STOPPED, "testBasicFunctions 11");
pPf->resumePlay();
Sleep(100);
Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 12");
Assert(pPf->getPlayedFile() == song1, "testBasicFunctions 13");
// TStringList *list = new TStringList;
// list->Add(song4);
// list->Add(song3);
// list->Add(song2);
// list->Add(song1);
//
// pPf->playMultiple(list);
// delete list;
// Sleep(100);
// Assert(pPf->getPlayedFile() == song4, "testBasicFunctions 14");
// Assert(pPf->getStatus() == PLAYER_PLAYING, "testBasicFunctions 15");
}