~ps-jenkins/indicator-transfer/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to tests/test-actions-live.cpp

  • Committer: Charles Kerr
  • Date: 2014-06-17 01:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2.
  • Revision ID: charles.kerr@canonical.com-20140617013616-7fcd22wh3hbgaovh
code drop

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2014 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as published
6
 
 * by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authors:
17
 
 *   Charles Kerr <charles.kerr@canonical.com>
18
 
 */
19
 
 
20
 
#include <transfer/actions-live.h>
21
 
#include <transfer/transfer-mock.h>
22
 
 
23
 
#include "glib-fixture.h"
24
 
 
25
 
#include <functional>
26
 
 
27
 
using namespace unity::indicator::transfer;
28
 
using namespace std::placeholders;
29
 
 
30
 
class ActionsFixture: public GlibFixture
31
 
{
32
 
    typedef GlibFixture super;
33
 
 
34
 
protected:
35
 
 
36
 
    const std::vector<MockTransfer::Action> empty_history;
37
 
 
38
 
    std::shared_ptr<MockTransfer> m_transfer_a;
39
 
    std::shared_ptr<MockTransfer> m_transfer_b;
40
 
    std::shared_ptr<Transfers> m_transfers;
41
 
    std::shared_ptr<LiveActions> m_live_actions;
42
 
    std::shared_ptr<Actions> m_actions;
43
 
 
44
 
    virtual void SetUp()
45
 
    {
46
 
        super::SetUp();
47
 
 
48
 
        m_transfer_a.reset(new MockTransfer{"id-a", "/usr/share/icons/ubuntu-mobile/status/scalable/search.svg"});
49
 
        m_transfer_b.reset(new MockTransfer{"id-b", "/usr/share/icons/ubuntu-mobile/status/scalable/syncing.svg"});
50
 
        m_transfers.reset(new Transfers({std::dynamic_pointer_cast<Transfer>(m_transfer_a),
51
 
                                         std::dynamic_pointer_cast<Transfer>(m_transfer_b)}));
52
 
        m_live_actions.reset(new LiveActions{m_transfers});
53
 
        m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions);
54
 
    }
55
 
 
56
 
    virtual void TearDown()
57
 
    {
58
 
        m_actions.reset();
59
 
        m_live_actions.reset();
60
 
        m_transfers.reset();
61
 
        m_transfer_b.reset();
62
 
        m_transfer_a.reset();
63
 
 
64
 
        super::TearDown();
65
 
    }
66
 
 
67
 
    void TestIdFunc(std::function<void(const Transfer::Id&)> callme, MockTransfer::Action expected_action)
68
 
    {
69
 
        const std::vector<MockTransfer::Action> expected_history{expected_action};
70
 
 
71
 
        EXPECT_EQ(empty_history, m_transfer_a->history());
72
 
        EXPECT_EQ(empty_history, m_transfer_b->history());
73
 
 
74
 
        callme(m_transfer_a->id());
75
 
        EXPECT_EQ(expected_history, m_transfer_a->history());
76
 
        EXPECT_EQ(empty_history, m_transfer_b->history());
77
 
 
78
 
        callme(m_transfer_b->id());
79
 
        EXPECT_EQ(expected_history, m_transfer_a->history());
80
 
        EXPECT_EQ(expected_history, m_transfer_b->history());
81
 
    }
82
 
 
83
 
    void TestBatchFunc(std::function<void()> callme, MockTransfer::Action expected_action)
84
 
    {
85
 
        EXPECT_EQ(empty_history, m_transfer_a->history());
86
 
        EXPECT_EQ(empty_history, m_transfer_b->history());
87
 
 
88
 
        callme();
89
 
 
90
 
        const std::vector<MockTransfer::Action> expected_history({expected_action});
91
 
        EXPECT_EQ(expected_history, m_transfer_a->history());
92
 
        EXPECT_EQ(expected_history, m_transfer_b->history());
93
 
    }
94
 
};
95
 
 
96
 
/***
97
 
****
98
 
***/
99
 
 
100
 
TEST_F(ActionsFixture, Pause)
101
 
{
102
 
    TestIdFunc(std::bind(&LiveActions::pause, *m_live_actions, _1),
103
 
               MockTransfer::Pause);
104
 
}
105
 
 
106
 
TEST_F(ActionsFixture, Cancel)
107
 
{
108
 
    TestIdFunc(std::bind(&LiveActions::cancel, *m_live_actions, _1),
109
 
               MockTransfer::Cancel);
110
 
}
111
 
 
112
 
TEST_F(ActionsFixture, Resume)
113
 
{
114
 
    TestIdFunc(std::bind(&LiveActions::resume, *m_live_actions, _1),
115
 
               MockTransfer::Resume);
116
 
}
117
 
 
118
 
TEST_F(ActionsFixture, PauseAll)
119
 
{
120
 
    TestBatchFunc(std::bind(&LiveActions::pause_all, *m_live_actions),
121
 
                  MockTransfer::Pause);
122
 
}
123
 
 
124
 
TEST_F(ActionsFixture, ResumeAll)
125
 
{
126
 
    TestBatchFunc(std::bind(&LiveActions::resume_all, *m_live_actions),
127
 
                  MockTransfer::Resume);
128
 
}
129
 
 
130
 
TEST_F(ActionsFixture, ClearAll)
131
 
{
132
 
    TestBatchFunc(std::bind(&LiveActions::clear_all, *m_live_actions),
133
 
                  MockTransfer::Clear);
134
 
}
135
 
 
136
 
TEST_F(ActionsFixture, Activate)
137
 
{
138
 
    std::vector<MockTransfer::Action> expected_history;
139
 
    EXPECT_EQ(expected_history, m_transfer_a->history());
140
 
 
141
 
    m_live_actions->activate(m_transfer_a->id());
142
 
    expected_history.push_back(MockTransfer::Pause);
143
 
    EXPECT_EQ(expected_history, m_transfer_a->history());
144
 
 
145
 
    m_live_actions->activate(m_transfer_a->id());
146
 
    expected_history.push_back(MockTransfer::Resume);
147
 
    EXPECT_EQ(expected_history, m_transfer_a->history());
148
 
 
149
 
    m_transfer_a->state().set(Transfer::DONE);
150
 
    m_live_actions->activate(m_transfer_a->id());
151
 
    expected_history.push_back(MockTransfer::Open);
152
 
    EXPECT_EQ(expected_history, m_transfer_a->history());
153
 
 
154
 
    m_transfer_a->state().set(Transfer::CANCELING);
155
 
    m_live_actions->activate(m_transfer_a->id());
156
 
    expected_history.push_back(MockTransfer::Clear);
157
 
    EXPECT_EQ(expected_history, m_transfer_a->history());
158
 
}
159
 
 
160
 
TEST_F(ActionsFixture, InvalidId)
161
 
{
162
 
    EXPECT_EQ(empty_history, m_transfer_a->history());
163
 
    EXPECT_EQ(empty_history, m_transfer_b->history());
164
 
 
165
 
    m_live_actions->pause("unknown-id");
166
 
    increment_expected_errors(G_LOG_LEVEL_CRITICAL);
167
 
    EXPECT_EQ(empty_history, m_transfer_a->history());
168
 
    EXPECT_EQ(empty_history, m_transfer_b->history());
169
 
 
170
 
    m_live_actions->resume("unknown-id");
171
 
    increment_expected_errors(G_LOG_LEVEL_CRITICAL);
172
 
    EXPECT_EQ(empty_history, m_transfer_a->history());
173
 
    EXPECT_EQ(empty_history, m_transfer_b->history());
174
 
 
175
 
    m_live_actions->cancel("unknown-id");
176
 
    increment_expected_errors(G_LOG_LEVEL_CRITICAL);
177
 
    EXPECT_EQ(empty_history, m_transfer_a->history());
178
 
    EXPECT_EQ(empty_history, m_transfer_b->history());
179
 
 
180
 
    m_live_actions->resume("unknown-id");
181
 
    increment_expected_errors(G_LOG_LEVEL_CRITICAL);
182
 
    EXPECT_EQ(empty_history, m_transfer_a->history());
183
 
    EXPECT_EQ(empty_history, m_transfer_b->history());
184
 
}