summaryrefslogtreecommitdiff
path: root/src/ItemViewPresenter_test.cc
blob: 4551109a09b13952bd652029d615a22bbfd384f3 (plain)
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
/*
 * 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 <string>
#include "Item.h"
#include "ItemView.h"
#include "ItemViewPresenter.h"
#include "ConfigurationStub.h"
#include "RefPtr.h"

using namespace std;

namespace
{

class ItemViewStub : public IItemView
{
public:
    string description;
    string title;
    string redHelp;
    string greenHelp;
    string yellowHelp;

public:
    // <IItemView>
    void SetDescription(string description)
    {
        this->description = description;
    }

    void SetTitle(string title)
    {
        this->title = title;
    }

    void SetRedHelp(string text)
    {
        redHelp = text;
    }

    void SetGreenHelp(string text)
    {
        greenHelp = text;
    }

    void SetYellowHelp(string text)
    {
        yellowHelp = text;
    }
    void SetBlueHelp(string text)
    {
    }
    // </IItemView>
};

class An_ItemViewPresenter_for_any_item : public CxxTest::TestSuite
{
private:
    ItemViewStub view;
    RefPtr<ItemViewPresenter> _presenter;
    RefPtr<ConfigurationStub> _configuration;

public:
    void setUp()
    {
        view.title = "";
        view.description = "";
        Item item("title", Rfc822DateTime("long_date"), "description");
        _configuration = new ConfigurationStub();
        _presenter = new ItemViewPresenter("FeedTitle", item, *_configuration);
    }
    
    void Should_show_the_item_description()
    {
        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS("long_date\n\ntitle\n\ndescription", view.description);
    }
    
    void Should_display_the_feed_title_as_menu_title()
    {
        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS("FeedTitle", view.title);
    }

    void Should_ignore_already_processed_keys()
    {
        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS(osBack, _presenter->ProcessKey(osBack, kOk));
    }
};

class An_ItemViewPresenter_for_a_non_videocast_item : public CxxTest::TestSuite
{
private:
    ItemViewStub view;
    RefPtr<ItemViewPresenter> _presenter;
    RefPtr<ConfigurationStub> _configuration;

public:
    void setUp()
    {
        view.title = "";
        view.description = "";
        Item item("title", Rfc822DateTime("long_date"), "description");
        _configuration = new ConfigurationStub();
        _configuration->SetPlayBackQuality(High);
        _presenter = new ItemViewPresenter("", item, *_configuration);
    }

    void Should_not_display_the_Play_and_Record_help_for_a_non_videocast_item()
    {
        view.redHelp = view.greenHelp = view.yellowHelp = "dummy";

        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS("", view.greenHelp);
        TS_ASSERT_EQUALS("", view.redHelp);
        TS_ASSERT_EQUALS("", view.yellowHelp);
    }
};

class An_ItemViewPresenter_for_a_videocast_item : public CxxTest::TestSuite
{
private:
    ItemViewStub view;
    RefPtr<ItemViewPresenter> _presenter;
    RefPtr<ConfigurationStub> _configuration;

public:
    void setUp()
    {
        view.title = "";
        view.description = "";
        Item item("title", Rfc822DateTime("long_date"), "description");
        item.SetVideoCastStream(High, "streamUrl");
        _configuration = new ConfigurationStub();
        _configuration->SetPlayBackQuality(High);
        _presenter = new ItemViewPresenter("", item, *_configuration);
    }

    void Should_display_the_Play_Record_and_quality_help_for_a_videocast_item()
    {
        view.redHelp = view.greenHelp = view.yellowHelp = "dummy";
        _configuration->SetPlayBackQuality(High);

        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS("i18n:Play", view.greenHelp);
        TS_ASSERT_EQUALS("i18n:Record", view.redHelp);
        TS_ASSERT_EQUALS("i18n:High", view.yellowHelp);
    }

    void Should_let_the_parent_menu_handle_play_and_record()
    {
        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(osContinue, kRed));
        TS_ASSERT_EQUALS(osUnknown, _presenter->ProcessKey(osContinue, kGreen));
    }

    void Should_toggle_the_quality_when_pressing_the_yellow_key()
    {
        _presenter->Initialize(&view);

        TS_ASSERT_EQUALS("i18n:High", view.yellowHelp);

        _presenter->ProcessKey(osContinue, kYellow);
        TS_ASSERT_EQUALS("i18n:Medium", view.yellowHelp);

        _presenter->ProcessKey(osContinue, kYellow);
        TS_ASSERT_EQUALS("i18n:Low", view.yellowHelp);

        _presenter->ProcessKey(osContinue, kYellow);
        TS_ASSERT_EQUALS("i18n:High", view.yellowHelp);
    }
};

};