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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/*
* vdr-vodcatcher - A plugin for the Linux Video Disk Recorder
* Copyright (c) 2007 - 2009 Tobias Grimm <vdr@e-tobi.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <cxxtest/TestSuite.h>
#include "ItemMenuPresenter.h"
#include "ServiceLocatorStub.h"
#include "ListMenuMock.h"
#include "DownloadPoolMock.h"
#include "DownloadCacheMock.h"
#include "vdr-stub/ccontrolstub.h"
#include "IMediaPlayer.h"
#include "IFeedRepository.h"
#include "ConfigurationStub.h"
#include "IVdrInterface.h"
using namespace std;
namespace
{
class An_ItemMenuPresenter_for_an_empty_feed: public CxxTest::TestSuite
{
private:
ServiceLocatorStub _serviceLocator;
DownloadCacheMock _downloadCache;
DownloadPoolMock _downloadPool;
RefPtr<IMediaPlayer> _mplayerPlugin;
RefPtr<ListMenuMock> _menu;
RefPtr<Feed> _feed;
RefPtr<ItemMenuPresenter> _presenter;
RefPtr<IFeedRepository> _feedRepository;
RefPtr<IConfiguration> _configuration;
RefPtr<IVdrInterface> _vdrInterface;
public:
void setUp()
{
_menu = new ListMenuMock();
_feed = new Feed("");
_feed->SetTitle("dummy title");
_presenter = new ItemMenuPresenter(_serviceLocator, *_feed, _feedRepository, *_configuration, _mplayerPlugin, _vdrInterface);
_serviceLocator.downloadPool = &_downloadPool;
}
void Should_do_nothing()
{
_presenter->Initialize(_menu.get());
_menu->isActiveMenu = true;
TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(-1, kOk, osUnknown));
}
void Should_display_the_feed_title_as_the_menu_title()
{
_menu->ExpectMethod("SetTitle", "dummy title");
_presenter->Initialize(_menu.get());
VERIFY_EXPECTATIONS(*_menu);
}
void Should_display_a_no_entries_message_as_the_first_menu_entry()
{
_menu->ExpectMethod("AddItem", "i18n:No entries!");
_presenter->Initialize(_menu.get());
VERIFY_EXPECTATIONS(*_menu);
}
};
class FeedRepositoryMock: public IFeedRepository
{
public:
Feed GetFeed(std::string url) { return Feed(""); }
const FeedList GetRootFeeds() const { return FeedList(); }
};
class MplayerPluginMock: public IMediaPlayer, public StringMessageMock
{
public:
bool PlayResult;
MplayerPluginMock() :
PlayResult(true)
{
}
bool Play(string url)
{
AddMethod("Play", url);
return PlayResult;
}
};
class VdrInterfaceMock: public IVdrInterface, public StringMessageMock
{
public:
void ShowMessage(const string& message)
{
AddMethod("ShowMessage", message);
}
void ShowErrorMessage(const string& message)
{
AddMethod("ShowErrorMessage", message);
}
};
class An_ItemMenuPresenter_for_a_nonempty_feed : public CxxTest::TestSuite
{
private:
ServiceLocatorStub _serviceLocator;
DownloadCacheMock _downloadCache;
DownloadPoolMock _downloadPool;
RefPtr<MplayerPluginMock> _mplayerPlugin;
RefPtr<ListMenuMock> _menu;
RefPtr<Feed> _feed;
RefPtr<ItemMenuPresenter> _presenter;
RefPtr<IFeedRepository> _feedRepository;
RefPtr<ConfigurationStub> _configuration;
RefPtr<VdrInterfaceMock> _vdrInterface;
public:
void setUp()
{
_menu = new ListMenuMock();
_menu->isActiveMenu = true;
_feed = new Feed("");
Item item1("item1", Rfc822DateTime("Tue, 10 Jun 2003 04:00:00 GMT"), "");
Item item2("item2", Rfc822DateTime("Tue, 11 Jun 2003 04:00:00 GMT"), "");
Item item3("item2", Rfc822DateTime("Tue, 11 Jun 2003 04:00:00 GMT"), "");
item2.SetVideoCastStream(High, "streamUrlHigh");
item2.SetVideoCastStream(Medium, "streamUrlMedium");
item2.SetVideoCastStream(Low, "streamUrlLow");
item2.SetStreamLength("12 min");
item3.SetSubFeedUrl("linkUrl");
_feed->AddItem(item1);
_feed->AddItem(item2);
_feed->AddItem(item3);
_mplayerPlugin = new MplayerPluginMock();
_configuration = new ConfigurationStub();
_configuration->SetPlayBackQuality(High);
_vdrInterface = new VdrInterfaceMock();
_presenter = new ItemMenuPresenter(_serviceLocator, *_feed, _feedRepository, *_configuration, _mplayerPlugin, _vdrInterface);
_feedRepository = new FeedRepositoryMock();
_serviceLocator.downloadPool = &_downloadPool;
}
void Should_display_the_item_dates_titels_and_lengths_as_menu_entries()
{
_menu->ExpectMethod("AddItem", "10.06.03\titem1");
_menu->ExpectMethod("AddItem", "11.06.03\titem2 (12 min)");
_presenter->Initialize(_menu.get());
VERIFY_EXPECTATIONS(*_menu);
}
void Should_set_the_green_help_button_to_play_when_moving_the_selection_to_a_videocast_item()
{
_menu->ExpectMethod("SetGreenHelp", "i18n:Play");
_presenter->Initialize(_menu.get());
_presenter->ProcessKey(1, kDown, osContinue);
VERIFY_EXPECTATIONS(*_menu);
}
void Should_set_the_red_help_button_to_record_when_moving_the_selection_to_a_videocast_item()
{
_menu->ExpectMethod("SetRedHelp", "i18n:Record");
_presenter->Initialize(_menu.get());
_presenter->ProcessKey(1, kDown, osContinue);
VERIFY_EXPECTATIONS(*_menu);
}
void Should_set_the_yellow_help_button_to_the_last_selected_quality_when_moving_the_selection_to_a_videocast_item()
{
_configuration->SetPlayBackQuality(Medium);
_menu->ExpectMethod("SetYellowHelp", "i18n:Medium");
_presenter->Initialize(_menu.get());
_presenter->ProcessKey(1, kDown, osContinue);
VERIFY_EXPECTATIONS(*_menu);
}
void Should_open_a_submenu_when_selecting_a_category_item()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_menu->ExpectMethod("ShowSubMenu", _menu->MakeString(&itemMenu));
_presenter->Initialize(_menu.get());
TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(2, kOk, osUnknown));
VERIFY_EXPECTATIONS(*_menu);
}
void Should_play_a_stream_in_the_selected_quality_when_pressing_green()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Medium);
_mplayerPlugin->ExpectMethod("Play", "streamUrlMedium");
_presenter->Initialize(_menu.get());
_presenter->ProcessKey(1, kGreen, osUnknown);
VERIFY_EXPECTATIONS(*_mplayerPlugin);
}
void Should_leave_the_osd_menu_when_playing_a_stream()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Medium);
_presenter->Initialize(_menu.get());
TS_ASSERT_EQUALS(osEnd, _presenter->ProcessKey(1, kGreen, osUnknown));
}
void Should_display_a_message_when_playing_a_stream()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Medium);
_presenter->Initialize(_menu.get());
_vdrInterface->ExpectMethod("ShowMessage", "i18n:Starting playback, please wait...");
_presenter->ProcessKey(1, kGreen, osUnknown);
VERIFY(*_vdrInterface);
}
void Should_display_a_message_when_playing_a_stream_failed()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Medium);
_presenter->Initialize(_menu.get());
_mplayerPlugin->PlayResult = false;
_vdrInterface->ExpectMethod("ShowErrorMessage", "i18n:Playback failed!");
_presenter->ProcessKey(1, kGreen, osUnknown);
VERIFY(*_vdrInterface);
}
void Should_not_leave_the_menu_when_playing_a_stream_failed()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Medium);
_presenter->Initialize(_menu.get());
_mplayerPlugin->PlayResult = false;
TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kGreen, osUnknown));
}
void Should_toggle_the_quality_when_pressing_the_yellow_key()
{
cOsdMenu itemMenu("");
_serviceLocator.itemMenu = &itemMenu;
_configuration->SetPlayBackQuality(Low);
_presenter->Initialize(_menu.get());
_menu->ResetMock();
_menu->ExpectMethod("SetYellowHelp", "i18n:High");
_menu->ExpectMethod("SetYellowHelp", "i18n:Medium");
_menu->ExpectMethod("SetYellowHelp", "i18n:Low");
TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown));
TS_ASSERT_EQUALS(High, _configuration->GetPlayBackQuality());
TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown));
TS_ASSERT_EQUALS(Medium, _configuration->GetPlayBackQuality());
TS_ASSERT_EQUALS(osContinue, _presenter->ProcessKey(1, kYellow, osUnknown));
TS_ASSERT_EQUALS(Low, _configuration->GetPlayBackQuality());
VERIFY_EXPECTATIONS(*_menu);
}
};
};
|