~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_launcher_entry_remote.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
 
/*
3
 
 * Copyright (C) 2012 Canonical Ltd
4
 
 *
5
 
 * This program is free software: you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 3 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 *
17
 
 * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
18
 
 */
19
 
 
20
 
#include <gmock/gmock.h>
21
 
 
22
 
#include "LauncherEntryRemote.h"
23
 
 
24
 
using namespace std;
25
 
using namespace unity;
26
 
using namespace testing;
27
 
 
28
 
namespace
29
 
{
30
 
 
31
 
GVariant* BuildVariantParameters(std::string const& app_uri = "app_uri",
32
 
                                 std::string const& emblem = "emblem",
33
 
                                 bool emblem_visible = false,
34
 
                                 long long count = 0,
35
 
                                 bool count_visible = false,
36
 
                                 double progress = 0.0f,
37
 
                                 bool progress_visible = false,
38
 
                                 bool urgent = false,
39
 
                                 std::string const& quicklist_path = "/my/quicklist/path")
40
 
{
41
 
  GVariantBuilder b;
42
 
 
43
 
  g_variant_builder_init(&b, G_VARIANT_TYPE ("a{sv}"));
44
 
  g_variant_builder_add(&b, "{sv}", "emblem", g_variant_new_string(emblem.c_str()));
45
 
  g_variant_builder_add(&b, "{sv}", "emblem-visible", g_variant_new_boolean(emblem_visible));
46
 
  g_variant_builder_add(&b, "{sv}", "count", g_variant_new_int64(count));
47
 
  g_variant_builder_add(&b, "{sv}", "count-visible", g_variant_new_boolean(count_visible));
48
 
  g_variant_builder_add(&b, "{sv}", "progress", g_variant_new_double(progress));
49
 
  g_variant_builder_add(&b, "{sv}", "progress-visible", g_variant_new_boolean(progress_visible));
50
 
  g_variant_builder_add(&b, "{sv}", "urgent", g_variant_new_boolean(urgent));
51
 
  g_variant_builder_add(&b, "{sv}", "quicklist", g_variant_new_string(quicklist_path.c_str()));
52
 
 
53
 
  return g_variant_new("(sa{sv})", app_uri.c_str(), &b);
54
 
}
55
 
 
56
 
TEST(TestLauncherEntryRemote, DummyConstruction)
57
 
{
58
 
  LauncherEntryRemote entry("TestName", nullptr);
59
 
 
60
 
  EXPECT_EQ(entry.DBusName(), "TestName");
61
 
  EXPECT_TRUE(entry.AppUri().empty());
62
 
  EXPECT_TRUE(entry.Emblem().empty());
63
 
  EXPECT_EQ(entry.Count(), 0);
64
 
  EXPECT_EQ(entry.Progress(), 0.0f);
65
 
  EXPECT_THAT(entry.Quicklist().RawPtr(), IsNull());
66
 
  EXPECT_FALSE(entry.EmblemVisible());
67
 
  EXPECT_FALSE(entry.CountVisible());
68
 
  EXPECT_FALSE(entry.ProgressVisible());
69
 
  EXPECT_FALSE(entry.Urgent());
70
 
}
71
 
 
72
 
TEST(TestLauncherEntryRemote, Construction)
73
 
{
74
 
  LauncherEntryRemote entry("TestName", BuildVariantParameters());
75
 
 
76
 
  EXPECT_EQ(entry.DBusName(), "TestName");
77
 
  EXPECT_EQ(entry.AppUri(), "app_uri");
78
 
  EXPECT_EQ(entry.Emblem(), "emblem");
79
 
  EXPECT_EQ(entry.Count(), 0);
80
 
  EXPECT_EQ(entry.Progress(), 0.0f);
81
 
  EXPECT_THAT(entry.Quicklist().RawPtr(), NotNull());
82
 
  EXPECT_FALSE(entry.EmblemVisible());
83
 
  EXPECT_FALSE(entry.CountVisible());
84
 
  EXPECT_FALSE(entry.ProgressVisible());
85
 
  EXPECT_FALSE(entry.Urgent());
86
 
}
87
 
 
88
 
TEST(TestLauncherEntryRemote, CustomConstruction)
89
 
{
90
 
  GVariant* parameters;
91
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
92
 
                                      true, true, "/My/DBus/Menu/For/QL");
93
 
  LauncherEntryRemote entry("CustomName", parameters);
94
 
 
95
 
  EXPECT_EQ(entry.DBusName(), "CustomName");
96
 
  EXPECT_EQ(entry.AppUri(), "Uri");
97
 
  EXPECT_EQ(entry.Emblem(), "TestEmblem");
98
 
  EXPECT_EQ(entry.Count(), 55);
99
 
  EXPECT_EQ(entry.Progress(), 31.12f);
100
 
  EXPECT_THAT(entry.Quicklist().RawPtr(), NotNull());
101
 
  EXPECT_TRUE(entry.EmblemVisible());
102
 
  EXPECT_TRUE(entry.CountVisible());
103
 
  EXPECT_TRUE(entry.ProgressVisible());
104
 
  EXPECT_TRUE(entry.Urgent());
105
 
}
106
 
 
107
 
TEST(TestLauncherEntryRemote, UpdateFromOther)
108
 
{
109
 
  LauncherEntryRemote entry1("Entry1", BuildVariantParameters("AppURI1"));
110
 
 
111
 
  ASSERT_EQ(entry1.DBusName(), "Entry1");
112
 
  ASSERT_EQ(entry1.AppUri(), "AppURI1");
113
 
  auto old_ql1 = entry1.Quicklist();
114
 
  ASSERT_THAT(old_ql1.RawPtr(), NotNull());
115
 
 
116
 
  GVariant* parameters;
117
 
  parameters = BuildVariantParameters("Uri2", "TestEmblem", false, 5, true, 0.12f,
118
 
                                      true, false, "/My/DBus/Menu/For/QL");
119
 
 
120
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
121
 
  ASSERT_EQ(entry2->AppUri(), "Uri2");
122
 
 
123
 
  entry1.Update(entry2);
124
 
 
125
 
  EXPECT_EQ(entry1.DBusName(), "Entry2");
126
 
  EXPECT_EQ(entry1.AppUri(), "AppURI1");
127
 
  EXPECT_EQ(entry1.Emblem(), "TestEmblem");
128
 
  EXPECT_EQ(entry1.Count(), 5);
129
 
  EXPECT_EQ(entry1.Progress(), 0.12f);
130
 
  EXPECT_THAT(entry1.Quicklist().RawPtr(), NotNull());
131
 
  EXPECT_NE(old_ql1, entry1.Quicklist());
132
 
  EXPECT_FALSE(entry1.EmblemVisible());
133
 
  EXPECT_TRUE(entry1.CountVisible());
134
 
  EXPECT_TRUE(entry1.ProgressVisible());
135
 
  EXPECT_FALSE(entry1.Urgent());
136
 
}
137
 
 
138
 
TEST(TestLauncherEntryRemote, UpdateFromVariantIter)
139
 
{
140
 
  LauncherEntryRemote entry1("Entry1", BuildVariantParameters("AppURI1"));
141
 
 
142
 
  ASSERT_EQ(entry1.DBusName(), "Entry1");
143
 
  ASSERT_EQ(entry1.AppUri(), "AppURI1");
144
 
  auto old_ql1 = entry1.Quicklist();
145
 
  ASSERT_THAT(old_ql1.RawPtr(), NotNull());
146
 
 
147
 
  GVariant* parameters;
148
 
  parameters = BuildVariantParameters("Uri2", "TestEmblem", false, 5, true, 0.12f,
149
 
                                      true, false, "/My/DBus/Menu/For/QL");
150
 
 
151
 
  gchar* app_uri;
152
 
  GVariantIter* prop_iter;
153
 
  g_variant_get(parameters, "(&sa{sv})", &app_uri, &prop_iter);
154
 
  entry1.Update(prop_iter);
155
 
  g_variant_iter_free(prop_iter);
156
 
 
157
 
  EXPECT_EQ(entry1.DBusName(), "Entry1");
158
 
  EXPECT_EQ(entry1.AppUri(), "AppURI1");
159
 
  EXPECT_EQ(entry1.Emblem(), "TestEmblem");
160
 
  EXPECT_EQ(entry1.Count(), 5);
161
 
  EXPECT_EQ(entry1.Progress(), 0.12f);
162
 
  EXPECT_THAT(entry1.Quicklist().RawPtr(), NotNull());
163
 
  EXPECT_NE(old_ql1, entry1.Quicklist());
164
 
  EXPECT_FALSE(entry1.EmblemVisible());
165
 
  EXPECT_TRUE(entry1.CountVisible());
166
 
  EXPECT_TRUE(entry1.ProgressVisible());
167
 
  EXPECT_FALSE(entry1.Urgent());
168
 
}
169
 
 
170
 
TEST(TestLauncherEntryRemote, ChangeDBusName)
171
 
{
172
 
  LauncherEntryRemote entry("Entry", BuildVariantParameters("AppURI"));
173
 
 
174
 
  bool name_changed = false;
175
 
  std::string old_name;
176
 
  entry.dbus_name_changed.connect([&] (LauncherEntryRemote*, std::string s) {
177
 
    name_changed = true;
178
 
    old_name = s;
179
 
  });
180
 
 
181
 
  auto old_ql = entry.Quicklist();
182
 
  ASSERT_THAT(old_ql.RawPtr(), NotNull());
183
 
  ASSERT_EQ(entry.DBusName(), "Entry");
184
 
 
185
 
  entry.SetDBusName("NewEntryName");
186
 
  ASSERT_EQ(entry.DBusName(), "NewEntryName");
187
 
 
188
 
  EXPECT_THAT(entry.Quicklist().RawPtr(), IsNull());
189
 
  EXPECT_NE(old_ql, entry.Quicklist());
190
 
 
191
 
  EXPECT_TRUE(name_changed);
192
 
  EXPECT_EQ(old_name, "Entry");
193
 
}
194
 
 
195
 
TEST(TestLauncherEntryRemote, EmblemChangedSignal)
196
 
{
197
 
  GVariant* parameters;
198
 
  parameters = BuildVariantParameters("Uri", "TestEmblem1", true, 55, true, 31.12f,
199
 
                                      true, true, "/My/DBus/Menu/For/QL");
200
 
 
201
 
  LauncherEntryRemote entry1("Entry1", parameters);
202
 
 
203
 
  bool value_changed = false;
204
 
  entry1.emblem_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
205
 
 
206
 
  parameters = BuildVariantParameters("Uri", "TestEmblem2", true, 55, true, 31.12f,
207
 
                                      true, true, "/My/DBus/Menu/For/QL");
208
 
 
209
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
210
 
 
211
 
  ASSERT_EQ(entry1.Emblem(), "TestEmblem1");
212
 
 
213
 
  entry1.Update(entry2);
214
 
 
215
 
  EXPECT_TRUE(value_changed);
216
 
  EXPECT_EQ(entry1.Emblem(), "TestEmblem2");
217
 
}
218
 
 
219
 
TEST(TestLauncherEntryRemote, CountChangedSignal)
220
 
{
221
 
  GVariant* parameters;
222
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
223
 
                                      true, true, "/My/DBus/Menu/For/QL");
224
 
 
225
 
  LauncherEntryRemote entry1("Entry1", parameters);
226
 
 
227
 
  bool value_changed = false;
228
 
  entry1.count_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
229
 
 
230
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 155, true, 31.12f,
231
 
                                      true, true, "/My/DBus/Menu/For/QL");
232
 
 
233
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
234
 
 
235
 
  ASSERT_EQ(entry1.Count(), 55);
236
 
 
237
 
  entry1.Update(entry2);
238
 
 
239
 
  EXPECT_TRUE(value_changed);
240
 
  EXPECT_EQ(entry1.Count(), 155);
241
 
}
242
 
 
243
 
TEST(TestLauncherEntryRemote, ProgressChangedSignal)
244
 
{
245
 
  GVariant* parameters;
246
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 0.12f,
247
 
                                      true, true, "/My/DBus/Menu/For/QL");
248
 
 
249
 
  LauncherEntryRemote entry1("Entry1", parameters);
250
 
 
251
 
  bool value_changed = false;
252
 
  entry1.progress_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
253
 
 
254
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
255
 
                                      true, true, "/My/DBus/Menu/For/QL");
256
 
 
257
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
258
 
 
259
 
  ASSERT_EQ(entry1.Progress(), 0.12f);
260
 
 
261
 
  entry1.Update(entry2);
262
 
 
263
 
  EXPECT_TRUE(value_changed);
264
 
  EXPECT_EQ(entry1.Progress(), 31.12f);
265
 
}
266
 
 
267
 
TEST(TestLauncherEntryRemote, QuicklistChangedSignal)
268
 
{
269
 
  GVariant* parameters;
270
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
271
 
                                      true, true, "/My/DBus/Menu/For/QL1");
272
 
 
273
 
  LauncherEntryRemote entry1("Entry1", parameters);
274
 
 
275
 
  bool value_changed = false;
276
 
  entry1.quicklist_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
277
 
 
278
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
279
 
                                      true, true, "/My/DBus/Menu/For/QL2");
280
 
 
281
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
282
 
 
283
 
  auto old_ql1 = entry1.Quicklist();
284
 
  ASSERT_THAT(old_ql1.RawPtr(), NotNull());
285
 
 
286
 
  entry1.Update(entry2);
287
 
 
288
 
  EXPECT_TRUE(value_changed);
289
 
  EXPECT_NE(entry1.Quicklist(), old_ql1);
290
 
  EXPECT_EQ(entry1.Quicklist(), entry2->Quicklist());
291
 
}
292
 
 
293
 
TEST(TestLauncherEntryRemote, EmblemVisibilityChanged)
294
 
{
295
 
  GVariant* parameters;
296
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, true, 31.12f,
297
 
                                      true, true, "/My/DBus/Menu/For/QL");
298
 
 
299
 
  LauncherEntryRemote entry1("Entry1", parameters);
300
 
 
301
 
  bool value_changed = false;
302
 
  entry1.emblem_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
303
 
 
304
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
305
 
                                      true, true, "/My/DBus/Menu/For/QL");
306
 
 
307
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
308
 
 
309
 
  ASSERT_FALSE(entry1.EmblemVisible());
310
 
 
311
 
  entry1.Update(entry2);
312
 
 
313
 
  EXPECT_TRUE(value_changed);
314
 
  EXPECT_TRUE(entry1.EmblemVisible());
315
 
}
316
 
 
317
 
TEST(TestLauncherEntryRemote, CountVisibilityChanged)
318
 
{
319
 
  GVariant* parameters;
320
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
321
 
                                      true, true, "/My/DBus/Menu/For/QL");
322
 
 
323
 
  LauncherEntryRemote entry1("Entry1", parameters);
324
 
 
325
 
  bool value_changed = false;
326
 
  entry1.count_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
327
 
 
328
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, true, 31.12f,
329
 
                                      true, true, "/My/DBus/Menu/For/QL");
330
 
 
331
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
332
 
 
333
 
  ASSERT_FALSE(entry1.CountVisible());
334
 
 
335
 
  entry1.Update(entry2);
336
 
 
337
 
  EXPECT_TRUE(value_changed);
338
 
  EXPECT_TRUE(entry1.CountVisible());
339
 
}
340
 
 
341
 
TEST(TestLauncherEntryRemote, ProgressVisibilityChanged)
342
 
{
343
 
  GVariant* parameters;
344
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
345
 
                                      false, true, "/My/DBus/Menu/For/QL");
346
 
 
347
 
  LauncherEntryRemote entry1("Entry1", parameters);
348
 
 
349
 
  bool value_changed = false;
350
 
  entry1.progress_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
351
 
 
352
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
353
 
                                      true, true, "/My/DBus/Menu/For/QL");
354
 
 
355
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
356
 
 
357
 
  ASSERT_FALSE(entry1.ProgressVisible());
358
 
 
359
 
  entry1.Update(entry2);
360
 
 
361
 
  EXPECT_TRUE(value_changed);
362
 
  EXPECT_TRUE(entry1.ProgressVisible());
363
 
}
364
 
 
365
 
TEST(TestLauncherEntryRemote, UrgentChanged)
366
 
{
367
 
  GVariant* parameters;
368
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
369
 
                                      false, false, "/My/DBus/Menu/For/QL");
370
 
 
371
 
  LauncherEntryRemote entry1("Entry1", parameters);
372
 
 
373
 
  bool value_changed = false;
374
 
  entry1.urgent_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
375
 
 
376
 
  parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
377
 
                                      false, true, "/My/DBus/Menu/For/QL");
378
 
 
379
 
  LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
380
 
 
381
 
  ASSERT_FALSE(entry1.Urgent());
382
 
 
383
 
  entry1.Update(entry2);
384
 
 
385
 
  EXPECT_TRUE(value_changed);
386
 
  EXPECT_TRUE(entry1.Urgent());
387
 
}
388
 
 
389
 
} // Namespace