~indicator-applet-developers/indicator-datetime/trunk.15.04

« back to all changes in this revision

Viewing changes to tests/test-actions.cpp

  • Committer: Charles Kerr
  • Date: 2014-03-22 07:25:50 UTC
  • mto: This revision was merged to the branch mainline in revision 332.
  • Revision ID: charles.kerr@canonical.com-20140322072550-5qwg2pkpigb4b0qv
make the phone and desktop actions more consistent with each other; eg, 'indicator.desktop.open-calendar-app' + 'indicator.phone.open-calendar-app'

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
using namespace unity::indicator::datetime;
25
25
 
26
 
typedef StateFixture ActionsFixture;
 
26
class ActionsFixture: public StateFixture
 
27
{
 
28
    typedef StateFixture super;
 
29
 
 
30
    std::vector<Appointment> build_some_appointments()
 
31
    {
 
32
        const auto now = m_state->clock->localtime();
 
33
        auto gdt_tomorrow = g_date_time_add_days(now.get(), 1);
 
34
        const auto tomorrow = DateTime(gdt_tomorrow);
 
35
        g_date_time_unref(gdt_tomorrow);
 
36
 
 
37
        Appointment a1; // an alarm clock appointment
 
38
        a1.color = "red";
 
39
        a1.summary = "Alarm";
 
40
        a1.summary = "http://www.example.com/";
 
41
        a1.uid = "example";
 
42
        a1.has_alarms = true;
 
43
        a1.begin = a1.end = tomorrow;
 
44
 
 
45
        Appointment a2; // a non-alarm appointment
 
46
        a2.color = "green";
 
47
        a2.summary = "Other Text";
 
48
        a2.summary = "http://www.monkey.com/";
 
49
        a2.uid = "monkey";
 
50
        a2.has_alarms = false;
 
51
        a2.begin = a2.end = tomorrow;
 
52
 
 
53
        return std::vector<Appointment>({a1, a2});
 
54
    }
 
55
 
 
56
protected:
 
57
 
 
58
    virtual void SetUp()
 
59
    {
 
60
        super::SetUp();
 
61
    }
 
62
 
 
63
    virtual void TearDown()
 
64
    {
 
65
        super::TearDown();
 
66
    }
 
67
 
 
68
    void test_action_with_no_args(const char * action_name,
 
69
                                  MockActions::Action expected_action)
 
70
    {
 
71
        // preconditions
 
72
        EXPECT_TRUE(m_mock_actions->history().empty());
 
73
        auto action_group = m_actions->action_group();
 
74
        EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
 
75
 
 
76
        // run the test
 
77
        g_action_group_activate_action(action_group, action_name, nullptr);
 
78
 
 
79
        // test the results
 
80
        EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
 
81
                  m_mock_actions->history());
 
82
    }
 
83
 
 
84
    void test_action_with_time_arg(const char * action_name,
 
85
                                   MockActions::Action expected_action)
 
86
    {
 
87
        // preconditions
 
88
        EXPECT_TRUE(m_mock_actions->history().empty());
 
89
        auto action_group = m_actions->action_group();
 
90
        EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
 
91
 
 
92
        // activate the action
 
93
        const auto now = DateTime::NowLocal();
 
94
        auto v = g_variant_new_int64(now.to_unix());
 
95
        g_action_group_activate_action(action_group, action_name, v);
 
96
 
 
97
        // test the results
 
98
        EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
 
99
                  m_mock_actions->history());
 
100
        EXPECT_EQ(now.format("%F %T"),
 
101
                  m_mock_actions->date_time().format("%F %T"));
 
102
    }
 
103
 
 
104
    void test_action_with_appt_arg(const char * action_name,
 
105
                                   MockActions::Action expected_action)
 
106
    {
 
107
        ///
 
108
        ///  Test 1: activate an appointment that we know about
 
109
        ///
 
110
 
 
111
        // preconditions
 
112
        EXPECT_TRUE(m_mock_actions->history().empty());
 
113
        auto action_group = m_actions->action_group();
 
114
        EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
 
115
 
 
116
        // init some appointments to the state
 
117
        const auto appointments = build_some_appointments();
 
118
        m_mock_state->mock_range_planner->appointments().set(appointments);
 
119
 
 
120
        // activate the action
 
121
        auto v = g_variant_new_string(appointments[0].uid.c_str());
 
122
        g_action_group_activate_action(action_group, action_name, v);
 
123
 
 
124
        // test the results
 
125
        EXPECT_EQ(std::vector<MockActions::Action>({expected_action}),
 
126
                  m_mock_actions->history());
 
127
        EXPECT_EQ(appointments[0],
 
128
                  m_mock_actions->appointment());
 
129
 
 
130
        ///
 
131
        ///  Test 2: activate an appointment we *don't* know about
 
132
        ///
 
133
 
 
134
        // setup
 
135
        m_mock_actions->clear();
 
136
        EXPECT_TRUE(m_mock_actions->history().empty());
 
137
 
 
138
        // activate the action
 
139
        v = g_variant_new_string("this-uid-is-not-one-that-we-have");
 
140
        g_action_group_activate_action(action_group, action_name, v);
 
141
 
 
142
        // test the results
 
143
        EXPECT_TRUE(m_mock_actions->history().empty());
 
144
    }
 
145
};
 
146
 
 
147
/***
 
148
****
 
149
***/
27
150
 
28
151
TEST_F(ActionsFixture, ActionsExist)
29
152
{
32
155
    const char* names[] = { "desktop-header",
33
156
                            "calendar",
34
157
                            "set-location",
35
 
                            "activate-planner",
36
 
                            "activate-appointment",
37
 
                            "activate-phone-clock-app",
38
 
                            "phone.open-settings",
39
 
                            "desktop.open-settings" };
 
158
                            "desktop.open-appointment",
 
159
                            "desktop.open-alarm-app",
 
160
                            "desktop.open-calendar-app",
 
161
                            "desktop.open-settings-app",
 
162
                            "phone.open-appointment",
 
163
                            "phone.open-alarm-app",
 
164
                            "phone.open-calendar-app",
 
165
                            "phone.open-settings-app" };
 
166
 
40
167
    for(const auto& name: names)
41
168
    {
42
169
        EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), name));
43
170
    }
44
171
}
45
172
 
46
 
TEST_F(ActionsFixture, DesktopOpenSettings)
47
 
{
48
 
    const auto action_name = "desktop.open-settings";
49
 
    const auto expected_action = MockActions::OpenDesktopSettings;
50
 
 
51
 
    auto action_group = m_actions->action_group();
52
 
    auto history = m_mock_actions->history();
53
 
    EXPECT_EQ(0, history.size());
54
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
55
 
 
56
 
    g_action_group_activate_action(action_group, action_name, nullptr);
57
 
    history = m_mock_actions->history();
58
 
    EXPECT_EQ(1, history.size());
59
 
    EXPECT_EQ(expected_action, history[0]);
60
 
}
61
 
 
62
 
TEST_F(ActionsFixture, PhoneOpenSettings)
63
 
{
64
 
    const auto action_name = "phone.open-settings";
65
 
    const auto expected_action = MockActions::OpenPhoneSettings;
66
 
 
67
 
    auto action_group = m_actions->action_group();
68
 
    EXPECT_TRUE(m_mock_actions->history().empty());
69
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
70
 
 
71
 
    g_action_group_activate_action(action_group, action_name, nullptr);
72
 
    auto history = m_mock_actions->history();
73
 
    EXPECT_EQ(1, history.size());
74
 
    EXPECT_EQ(expected_action, history[0]);
75
 
}
76
 
 
77
 
TEST_F(ActionsFixture, ActivatePhoneClockApp)
78
 
{
79
 
    const auto action_name = "activate-phone-clock-app";
80
 
    const auto expected_action = MockActions::OpenPhoneClockApp;
81
 
 
82
 
    auto action_group = m_actions->action_group();
83
 
    EXPECT_TRUE(m_mock_actions->history().empty());
84
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
85
 
 
86
 
    g_action_group_activate_action(action_group, action_name, nullptr);
87
 
    auto history = m_mock_actions->history();
88
 
    EXPECT_EQ(1, history.size());
89
 
    EXPECT_EQ(expected_action, history[0]);
90
 
}
91
 
 
92
 
TEST_F(ActionsFixture, ActivatePlanner)
93
 
{
94
 
    const auto action_name = "activate-planner";
95
 
    auto action_group = m_actions->action_group();
96
 
    EXPECT_TRUE(m_mock_actions->history().empty());
97
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
98
 
 
99
 
    const auto expected_action = MockActions::OpenPlanner;
100
 
    auto v = g_variant_new_int64(0);
101
 
    g_action_group_activate_action(action_group, action_name, v);
102
 
    auto history = m_mock_actions->history();
103
 
    EXPECT_EQ(1, history.size());
104
 
    EXPECT_EQ(expected_action, history[0]);
105
 
}
106
 
 
107
 
TEST_F(ActionsFixture, ActivatePlannerAt)
108
 
{
109
 
    const auto action_name = "activate-planner";
110
 
    auto action_group = m_actions->action_group();
111
 
    EXPECT_TRUE(m_mock_actions->history().empty());
112
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
113
 
 
114
 
    const auto now = DateTime::NowLocal();
115
 
    auto v = g_variant_new_int64(now.to_unix());
116
 
    g_action_group_activate_action(action_group, action_name, v);
117
 
    const auto a = MockActions::OpenPlannerAt;
118
 
    EXPECT_EQ(std::vector<MockActions::Action>({a}), m_mock_actions->history());
119
 
    EXPECT_EQ(now.to_unix(), m_mock_actions->date_time().to_unix());
120
 
}
 
173
/***
 
174
****
 
175
***/
 
176
 
 
177
TEST_F(ActionsFixture, DesktopOpenAlarmApp)
 
178
{
 
179
    test_action_with_no_args("desktop.open-alarm-app",
 
180
                             MockActions::DesktopOpenAlarmApp);
 
181
}
 
182
 
 
183
TEST_F(ActionsFixture, DesktopOpenAppointment)
 
184
{
 
185
    test_action_with_appt_arg("desktop.open-appointment",
 
186
                              MockActions::DesktopOpenAppt);
 
187
}
 
188
 
 
189
TEST_F(ActionsFixture, DesktopOpenCalendarApp)
 
190
{
 
191
    test_action_with_time_arg("desktop.open-calendar-app",
 
192
                              MockActions::DesktopOpenCalendarApp);
 
193
}
 
194
 
 
195
TEST_F(ActionsFixture, DesktopOpenSettingsApp)
 
196
{
 
197
    test_action_with_no_args("desktop.open-settings-app",
 
198
                             MockActions::DesktopOpenSettingsApp);
 
199
}
 
200
 
 
201
/***
 
202
****
 
203
***/
 
204
 
 
205
TEST_F(ActionsFixture, PhoneOpenAlarmApp)
 
206
{
 
207
    test_action_with_no_args("phone.open-alarm-app",
 
208
                             MockActions::PhoneOpenAlarmApp);
 
209
}
 
210
 
 
211
TEST_F(ActionsFixture, PhoneOpenAppointment)
 
212
{
 
213
    test_action_with_appt_arg("phone.open-appointment",
 
214
                              MockActions::PhoneOpenAppt);
 
215
}
 
216
 
 
217
TEST_F(ActionsFixture, PhoneOpenCalendarApp)
 
218
{
 
219
    test_action_with_time_arg("phone.open-calendar-app",
 
220
                              MockActions::PhoneOpenCalendarApp);
 
221
}
 
222
 
 
223
TEST_F(ActionsFixture, PhoneOpenSettingsApp)
 
224
{
 
225
    test_action_with_no_args("phone.open-settings-app",
 
226
                             MockActions::PhoneOpenSettingsApp);
 
227
}
 
228
 
 
229
/***
 
230
****
 
231
***/
121
232
 
122
233
TEST_F(ActionsFixture, SetLocation)
123
234
{
209
320
    g_clear_pointer(&calendar_state, g_variant_unref);
210
321
 
211
322
}
212
 
 
213
 
 
214
 
TEST_F(ActionsFixture, OpenAppointment)
215
 
{
216
 
    Appointment appt;
217
 
    appt.uid = "some arbitrary uid";
218
 
    appt.url = "http://www.canonical.com/";
219
 
    appt.begin = m_state->clock->localtime();
220
 
    m_state->calendar_upcoming->appointments().set(std::vector<Appointment>({appt}));
221
 
 
222
 
    const auto action_name = "activate-appointment";
223
 
    auto action_group = m_actions->action_group();
224
 
    EXPECT_TRUE(m_mock_actions->history().empty());
225
 
    EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
226
 
 
227
 
    auto v = g_variant_new_string(appt.uid.c_str());
228
 
    g_action_group_activate_action(action_group, action_name, v);
229
 
    const auto a = MockActions::OpenAppointment;
230
 
    ASSERT_EQ(1, m_mock_actions->history().size());
231
 
    ASSERT_EQ(a, m_mock_actions->history()[0]);
232
 
    EXPECT_EQ(appt.url, m_mock_actions->url());
233
 
}
234