Merge lp:~renatofilho/indicator-transfer/source-clear-fix into lp:indicator-transfer/15.10

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Charles Kerr
Approved revision: 57
Merged at revision: 34
Proposed branch: lp:~renatofilho/indicator-transfer/source-clear-fix
Merge into: lp:indicator-transfer/15.10
Prerequisite: lp:~charlesk/indicator-transfer/add-plugins
Diff against target: 1004 lines (+198/-123)
21 files modified
CMakeLists.txt (+1/-1)
data/indicator-transfer.pc.in (+3/-0)
debian/changelog (+6/-0)
include/transfer/controller.h (+9/-3)
include/transfer/dm-source.h (+2/-1)
include/transfer/model.h (+2/-0)
include/transfer/multisource.h (+3/-2)
include/transfer/source.h (+2/-1)
include/transfer/view-gmenu.h (+3/-4)
src/controller.cpp (+43/-14)
src/dm-plugin/dm-source.cpp (+23/-13)
src/main.cpp (+2/-3)
src/model.cpp (+10/-0)
src/multisource.cpp (+13/-1)
src/view-gmenu.cpp (+16/-24)
tests/controller-mock.h (+2/-3)
tests/source-mock.h (+9/-2)
tests/test-controller.cpp (+22/-18)
tests/test-multisource.cpp (+8/-8)
tests/test-plugin-source.cpp (+1/-4)
tests/test-view-gmenu.cpp (+18/-21)
To merge this branch: bzr merge lp:~renatofilho/indicator-transfer/source-clear-fix
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+267690@code.launchpad.net

Commit message

Added 'clear' function into the Source interface.
Call 'Source.clear' in the 'Controller.clear_all' function.
Does not keep a separated copy of source model inside of the Controller class.
Changed the return of 'Source.get_model()' to const.
Update unit tests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
54. By Renato Araujo Oliveira Filho

Fix warnings from cppcheck test.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
55. By Renato Araujo Oliveira Filho

[DM-Plugin] Add download on removed list only if it was removed by 'clear' function.

56. By Renato Araujo Oliveira Filho

Avoid pass a model to GMenuView. Instead use the controller model.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
57. By Renato Araujo Oliveira Filho

Fixed cppcheck errors.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Looks great.

Also, the "explicit" warning in cppcheck always bites me too ;)

review: Approve
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

Are there any related MPs required for this MP to build/function as expected?
YES: lp:~charlesk/indicator-transfer/add-plugins

Is your branch in sync with latest trunk?
YES

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
YES

Did you successfully run all tests found in your component's Test Plan on device or emulator?
YES

If you changed the UI, was the change specified/approved by design?
NO UI CHANGED

If you changed UI labels, did you update the pot file?
NO LABEL CHANGED

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
NO PACKAGE CHANGED

58. By Renato Araujo Oliveira Filho

Parent branch merged.

59. By Renato Araujo Oliveira Filho

Added "Requires" packages into .pc file.

60. By Renato Araujo Oliveira Filho

Update version to 0.2

61. By Renato Araujo Oliveira Filho

Added 'plugindir' variable into .pc file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-08-19 18:01:58 +0000
3+++ CMakeLists.txt 2015-08-19 18:01:58 +0000
4@@ -30,7 +30,7 @@
5
6 set(INDICATOR_TRANSFER_VERSION_MAJOR 0)
7 set(INDICATOR_TRANSFER_VERSION_MINOR 0)
8-set(INDICATOR_TRANSFER_VERSION_PATCH 1)
9+set(INDICATOR_TRANSFER_VERSION_PATCH 2)
10 set(INDICATOR_TRANSFER_VERSION "${INDICATOR_TRANSFER_VERSION_MAJOR}.${INDICATOR_TRANSFER_VERSION_MINOR}.${INDICATOR_TRANSFER_VERSION_PATCH}")
11
12 ##
13
14=== modified file 'data/indicator-transfer.pc.in'
15--- data/indicator-transfer.pc.in 2015-08-19 18:01:58 +0000
16+++ data/indicator-transfer.pc.in 2015-08-19 18:01:58 +0000
17@@ -1,8 +1,11 @@
18 libdir=@CMAKE_INSTALL_FULL_LIBDIR@
19 includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/@CMAKE_PROJECT_NAME@
20+plugindir=@CMAKE_INSTALL_FULL_PKGLIBEXECDIR@
21
22 Name: @CMAKE_PROJECT_NAME@
23 Description: Developer files for @CMAKE_PROJECT_NAME@
24 Version: @INDICATOR_TRANSFER_VERSION@
25 Libs: -L${libdir} -lindicator-transfer
26 Cflags: -I${includedir}
27+Requires: properties-cpp, gmodule-2.0
28+
29
30=== modified file 'debian/changelog'
31--- debian/changelog 2015-08-13 14:15:58 +0000
32+++ debian/changelog 2015-08-19 18:01:58 +0000
33@@ -1,3 +1,9 @@
34+indicator-transfer (0.2-0buntu1) UNRELEASED; urgency=medium
35+
36+ * Update version to 0.2
37+
38+ -- Renato Araujo Oliveira Filho <renato.filho@canonical.com> Wed, 19 Aug 2015 14:52:32 -0300
39+
40 indicator-transfer (0.1+15.10.20150727-0ubuntu2~gcc5.1) wily; urgency=medium
41
42 * No change rebuild using GCC 5.
43
44=== modified file 'include/transfer/controller.h'
45--- include/transfer/controller.h 2015-08-19 18:01:58 +0000
46+++ include/transfer/controller.h 2015-08-19 18:01:58 +0000
47@@ -36,8 +36,7 @@
48 class Controller
49 {
50 public:
51- Controller(const std::shared_ptr<MutableModel>& model,
52- const std::shared_ptr<Source>& source);
53+ explicit Controller(const std::shared_ptr<Source>& source);
54 virtual ~Controller();
55
56 virtual void pause_all();
57@@ -48,12 +47,19 @@
58 virtual void pause(const Transfer::Id&);
59 virtual void cancel(const Transfer::Id&);
60 virtual void resume(const Transfer::Id&);
61+ virtual void clear(const Transfer::Id&);
62 virtual void open(const Transfer::Id&);
63 virtual void open_app(const Transfer::Id&);
64
65+ int size() const;
66+ int count(const Transfer::Id&) const;
67+ const std::shared_ptr<const MutableModel> get_model();
68+
69 private:
70- std::shared_ptr<MutableModel> m_model;
71 std::shared_ptr<Source> m_source;
72+
73+ std::set<Transfer::Id> get_ids() const;
74+ std::shared_ptr<Transfer> get(const Transfer::Id& id) const;
75 };
76
77 } // namespace transfer
78
79=== modified file 'include/transfer/dm-source.h'
80--- include/transfer/dm-source.h 2015-08-19 18:01:58 +0000
81+++ include/transfer/dm-source.h 2015-08-19 18:01:58 +0000
82@@ -44,8 +44,9 @@
83 void pause(const Transfer::Id& id) override;
84 void resume(const Transfer::Id& id) override;
85 void cancel(const Transfer::Id& id) override;
86+ void clear(const Transfer::Id& id) override;
87 void open_app(const Transfer::Id& id) override;
88- std::shared_ptr<MutableModel> get_model() override;
89+ const std::shared_ptr<const MutableModel> get_model() override;
90
91 private:
92 class Impl;
93
94=== modified file 'include/transfer/model.h'
95--- include/transfer/model.h 2014-06-17 01:36:16 +0000
96+++ include/transfer/model.h 2015-08-19 18:01:58 +0000
97@@ -42,6 +42,8 @@
98 std::set<Transfer::Id> get_ids() const;
99 std::vector<std::shared_ptr<Transfer>> get_all() const;
100 std::shared_ptr<Transfer> get(const Transfer::Id&) const;
101+ int size() const;
102+ int count(const Transfer::Id&) const;
103
104 const core::Signal<Transfer::Id>& changed() const;
105 const core::Signal<Transfer::Id>& added() const;
106
107=== modified file 'include/transfer/multisource.h'
108--- include/transfer/multisource.h 2015-08-19 18:01:58 +0000
109+++ include/transfer/multisource.h 2015-08-19 18:01:58 +0000
110@@ -35,14 +35,15 @@
111 MultiSource();
112 virtual ~MultiSource();
113
114- // Source
115+ // Source
116 void open(const Transfer::Id& id) override;
117 void start(const Transfer::Id& id) override;
118 void pause(const Transfer::Id& id) override;
119 void resume(const Transfer::Id& id) override;
120 void cancel(const Transfer::Id& id) override;
121+ void clear(const Transfer::Id& id) override;
122 void open_app(const Transfer::Id& id) override;
123- std::shared_ptr<MutableModel> get_model() override;
124+ const std::shared_ptr<const MutableModel> get_model() override;
125
126 void add_source(const std::shared_ptr<Source>& source);
127
128
129=== modified file 'include/transfer/source.h'
130--- include/transfer/source.h 2015-08-19 18:01:58 +0000
131+++ include/transfer/source.h 2015-08-19 18:01:58 +0000
132@@ -50,9 +50,10 @@
133 virtual void pause(const Transfer::Id& id) =0;
134 virtual void resume(const Transfer::Id& id) =0;
135 virtual void cancel(const Transfer::Id& id) =0;
136+ virtual void clear(const Transfer::Id& id) =0;
137 virtual void open_app(const Transfer::Id& id) =0;
138
139- virtual std::shared_ptr<MutableModel> get_model() =0;
140+ virtual const std::shared_ptr<const MutableModel> get_model() =0;
141 };
142
143 } // namespace transfer
144
145=== modified file 'include/transfer/view-gmenu.h'
146--- include/transfer/view-gmenu.h 2014-06-17 01:36:16 +0000
147+++ include/transfer/view-gmenu.h 2015-08-19 18:01:58 +0000
148@@ -32,16 +32,15 @@
149 class GMenuView
150 {
151 public:
152- GMenuView(const std::shared_ptr<Model>& model,
153- const std::shared_ptr<Controller>& controller);
154+ explicit GMenuView(const std::shared_ptr<Controller>& controller);
155 ~GMenuView();
156- void set_controller(const std::shared_ptr<Controller>&);
157- void set_model(const std::shared_ptr<Model>&);
158 const core::Signal<>& name_lost() const;
159
160 private:
161 class Impl;
162 std::unique_ptr<Impl> p;
163+
164+ void set_model(const std::shared_ptr<Model>&);
165 };
166
167 } // namespace transfer
168
169=== modified file 'src/controller.cpp'
170--- src/controller.cpp 2015-08-19 18:01:58 +0000
171+++ src/controller.cpp 2015-08-19 18:01:58 +0000
172@@ -27,9 +27,7 @@
173 ****
174 ***/
175
176-Controller::Controller(const std::shared_ptr<MutableModel>& model,
177- const std::shared_ptr<Source>& source):
178- m_model(model),
179+Controller::Controller(const std::shared_ptr<Source>& source):
180 m_source(source)
181 {
182 }
183@@ -40,26 +38,25 @@
184
185 void Controller::pause_all()
186 {
187- for(const auto& id : m_model->get_ids())
188+ for(const auto& id : get_ids())
189 pause(id);
190 }
191
192 void Controller::resume_all()
193 {
194- for(const auto& id : m_model->get_ids())
195+ for(const auto& id : get_ids())
196 resume(id);
197 }
198
199 void Controller::clear_all()
200 {
201- for (const auto& transfer : m_model->get_all())
202- if (transfer->can_clear())
203- m_model->remove(transfer->id);
204+ for (const auto& id : get_ids())
205+ clear(id);
206 }
207
208 void Controller::tap(const Transfer::Id& id)
209 {
210- const auto transfer = m_model->get(id);
211+ const auto transfer = get(id);
212 g_return_if_fail (transfer);
213
214 if (transfer->can_start())
215@@ -75,28 +72,35 @@
216
217 void Controller::pause(const Transfer::Id& id)
218 {
219- const auto& transfer = m_model->get(id);
220+ const auto& transfer = get(id);
221 if (transfer && transfer->can_pause())
222 m_source->pause(id);
223 }
224
225 void Controller::cancel(const Transfer::Id& id)
226 {
227- const auto& transfer = m_model->get(id);
228+ const auto& transfer = get(id);
229 if (transfer && transfer->can_cancel())
230 m_source->cancel(id);
231 }
232
233+void Controller::clear(const Transfer::Id& id)
234+{
235+ const auto& transfer = get(id);
236+ if (transfer && transfer->can_clear())
237+ m_source->clear(id);
238+}
239+
240 void Controller::resume(const Transfer::Id& id)
241 {
242- const auto& transfer = m_model->get(id);
243+ const auto& transfer = get(id);
244 if (transfer && transfer->can_resume())
245 m_source->resume(id);
246 }
247
248 void Controller::start(const Transfer::Id& id)
249 {
250- const auto& transfer = m_model->get(id);
251+ const auto& transfer = get(id);
252 if (transfer && transfer->can_start())
253 m_source->start(id);
254 }
255@@ -108,7 +112,32 @@
256
257 void Controller::open_app(const Transfer::Id& id)
258 {
259- m_source->open_app(id);
260+ m_source->open_app(id);
261+}
262+
263+int Controller::size() const
264+{
265+ return m_source->get_model()->size();
266+}
267+
268+int Controller::count(const Transfer::Id& id) const
269+{
270+ return m_source->get_model()->count(id);
271+}
272+
273+const std::shared_ptr<const MutableModel> Controller::get_model()
274+{
275+ return m_source->get_model();
276+}
277+
278+std::set<Transfer::Id> Controller::get_ids() const
279+{
280+ return m_source->get_model()->get_ids();
281+}
282+
283+std::shared_ptr<Transfer> Controller::get(const Transfer::Id& id) const
284+{
285+ return m_source->get_model()->get(id);
286 }
287
288 /***
289
290=== modified file 'src/dm-plugin/dm-source.cpp'
291--- src/dm-plugin/dm-source.cpp 2015-08-19 18:01:58 +0000
292+++ src/dm-plugin/dm-source.cpp 2015-08-19 18:01:58 +0000
293@@ -43,7 +43,7 @@
294
295 /**
296 * A Transfer whose state comes from content-hub and ubuntu-download-manager.
297- *
298+ *
299 * Each DMTransfer tracks a com.canonical.applications.Download (ccad) object
300 * from ubuntu-download-manager. The ccad is used for pause/resume/cancel,
301 * state change / download progress signals, etc.
302@@ -85,14 +85,14 @@
303 void start()
304 {
305 g_return_if_fail(can_start());
306-
307+
308 call_ccad_method_no_args_no_response("start");
309 }
310
311 void pause()
312 {
313 g_return_if_fail(can_pause());
314-
315+
316 call_ccad_method_no_args_no_response("pause");
317 }
318
319@@ -359,7 +359,7 @@
320 speed_Bps = 0;
321 m_history.clear();
322 }
323-
324+
325 emit_changed_soon();
326 }
327 }
328@@ -631,12 +631,6 @@
329 m_model(std::make_shared<MutableModel>())
330 {
331 g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this);
332-
333- m_model->removed().connect([this](const Transfer::Id& id){
334- auto transfer = find_transfer_by_id(id);
335- if (transfer)
336- m_removed_ccad.insert(transfer->ccad_path());
337- });
338 }
339
340 ~Impl()
341@@ -675,6 +669,16 @@
342 transfer->cancel();
343 }
344
345+ void clear(const Transfer::Id& id)
346+ {
347+ auto transfer = find_transfer_by_id(id);
348+ if (transfer)
349+ {
350+ m_removed_ccad.insert(transfer->ccad_path());
351+ m_model->remove(id);
352+ }
353+ }
354+
355 void open(const Transfer::Id& id)
356 {
357 auto transfer = find_transfer_by_id(id);
358@@ -812,7 +816,7 @@
359 g_debug("download signal: %s %s %s", ccad_path, signal_name, variant_str);
360 g_free(variant_str);
361
362- // Route this signal to the DMTransfer for processing
363+ // Route this signal to the DMTransfer for processing
364 auto self = static_cast<Impl*>(gself);
365 auto transfer = self->find_transfer_by_ccad_path(ccad_path);
366 if (transfer)
367@@ -927,12 +931,18 @@
368 }
369
370 void
371+DMSource::clear(const Transfer::Id& id)
372+{
373+ impl->clear(id);
374+}
375+
376+void
377 DMSource::open_app(const Transfer::Id& id)
378 {
379- impl->open_app(id);
380+ impl->open_app(id);
381 }
382
383-std::shared_ptr<MutableModel>
384+const std::shared_ptr<const MutableModel>
385 DMSource::get_model()
386 {
387 return impl->get_model();
388
389=== modified file 'src/main.cpp'
390--- src/main.cpp 2015-08-19 18:01:58 +0000
391+++ src/main.cpp 2015-08-19 18:01:58 +0000
392@@ -45,9 +45,8 @@
393
394 // run until we lose the busname
395 auto source = std::make_shared<PluginSource>(PLUGINDIR);
396- auto model = source->get_model();
397- auto controller = std::make_shared<Controller>(model, source);
398- GMenuView menu_view (model, controller);
399+ auto controller = std::make_shared<Controller>(source);
400+ GMenuView menu_view (controller);
401 // FIXME: listen for busname-lost
402 g_main_loop_run(loop);
403
404
405=== modified file 'src/model.cpp'
406--- src/model.cpp 2014-06-17 01:36:16 +0000
407+++ src/model.cpp 2015-08-19 18:01:58 +0000
408@@ -58,6 +58,16 @@
409 return ret;
410 }
411
412+int Model::size() const
413+{
414+ return m_transfers.size();
415+}
416+
417+int Model::count(const Transfer::Id& id) const
418+{
419+ return m_transfers.count(id);
420+}
421+
422 const core::Signal<Transfer::Id>& Model::changed() const
423 {
424 return m_changed;
425
426=== modified file 'src/multisource.cpp'
427--- src/multisource.cpp 2015-08-19 18:01:58 +0000
428+++ src/multisource.cpp 2015-08-19 18:01:58 +0000
429@@ -104,6 +104,13 @@
430 source->cancel(id);
431 }
432
433+ void clear(const Transfer::Id& id)
434+ {
435+ auto source = lookup_source(id);
436+ g_return_if_fail(source);
437+ source->clear(id);
438+ }
439+
440 void open(const Transfer::Id& id)
441 {
442 auto source = lookup_source(id);
443@@ -180,13 +187,18 @@
444 impl->cancel(id);
445 }
446
447+void MultiSource::clear(const Transfer::Id &id)
448+{
449+ impl->clear(id);
450+}
451+
452 void
453 MultiSource::open_app(const Transfer::Id& id)
454 {
455 impl->open_app(id);
456 }
457
458-std::shared_ptr<MutableModel>
459+const std::shared_ptr<const MutableModel>
460 MultiSource::get_model()
461 {
462 return impl->get_model();
463
464=== modified file 'src/view-gmenu.cpp'
465--- src/view-gmenu.cpp 2014-10-03 20:54:45 +0000
466+++ src/view-gmenu.cpp 2015-08-19 18:01:58 +0000
467@@ -43,12 +43,11 @@
468 {
469 public:
470
471- GActions(const std::shared_ptr<Model>& model,
472- const std::shared_ptr<Controller>& controller):
473+ explicit GActions(const std::shared_ptr<Controller>& controller):
474 m_action_group(g_simple_action_group_new()),
475 m_controller(controller)
476 {
477- set_model(model);
478+ set_model(controller->get_model());
479
480 const GActionEntry entries[] = {
481 { "activate-transfer", on_tap, "s", nullptr },
482@@ -75,7 +74,7 @@
483
484 }
485
486- void set_model(const std::shared_ptr<Model>& model)
487+ void set_model(const std::shared_ptr<const Model>& model)
488 {
489 // out with the old...
490 auto& c = m_connections;
491@@ -252,7 +251,7 @@
492 }
493
494 GSimpleActionGroup* m_action_group = nullptr;
495- std::shared_ptr<Model> m_model;
496+ std::shared_ptr<const Model> m_model;
497 std::shared_ptr<Controller> m_controller;
498 std::set<core::ScopedConnection> m_connections;
499
500@@ -279,7 +278,7 @@
501 GMenuModel* menu_model() { return G_MENU_MODEL(m_menu); }
502
503 Menu(const char* name_in,
504- const std::shared_ptr<Model>& model,
505+ const std::shared_ptr<const Model>& model,
506 const std::shared_ptr<GActions>& gactions):
507 m_name{name_in},
508 m_gactions{gactions}
509@@ -296,7 +295,7 @@
510 g_clear_object(&m_menu);
511 }
512
513- void set_model (const std::shared_ptr<Model>& model)
514+ void set_model (const std::shared_ptr<const Model>& model)
515 {
516 auto& c = m_connections;
517 c.clear();
518@@ -563,7 +562,7 @@
519 return item;
520 }
521
522- static bool bulk_menu_item_is_equal(GMenuModel* model,
523+ static bool bulk_menu_item_is_equal(GMenuModel* model,
524 int pos,
525 GMenuItem* item)
526 {
527@@ -772,7 +771,7 @@
528 GMenu* m_menu = nullptr;
529 const char* const m_name;
530
531- std::shared_ptr<Model> m_model;
532+ std::shared_ptr<const Model> m_model;
533 std::shared_ptr<GActions> m_gactions;
534 std::map<Transfer::Id,Section> m_visible_transfers;
535 GMenu* m_submenu = nullptr;
536@@ -936,17 +935,16 @@
537 {
538 public:
539
540- Impl (const std::shared_ptr<Model>& model,
541- const std::shared_ptr<Controller>& controller):
542- m_model(model),
543+ explicit Impl (const std::shared_ptr<Controller>& controller):
544 m_controller(controller),
545- m_gactions(new GActions(model, controller)),
546+ m_gactions(new GActions(controller)),
547 m_exporter(new Exporter)
548 {
549+ set_model(controller->get_model());
550 // create the Menus
551 for(int i=0; i<Menu::NUM_PROFILES; i++)
552 m_menus.push_back(create_menu_for_profile(Menu::Profile(i)));
553-
554+
555 m_exporter->publish(m_gactions, m_menus);
556 }
557
558@@ -954,7 +952,7 @@
559 {
560 }
561
562- void set_model(const std::shared_ptr<Model>& model)
563+ void set_model(const std::shared_ptr<const Model>& model)
564 {
565 m_model = model;
566
567@@ -976,7 +974,7 @@
568 return m;
569 }
570
571- std::shared_ptr<Model> m_model;
572+ std::shared_ptr<const Model> m_model;
573 std::shared_ptr<Controller> m_controller;
574 std::shared_ptr<GActions> m_gactions;
575 std::vector<std::shared_ptr<Menu>> m_menus;
576@@ -987,9 +985,8 @@
577 ****
578 ***/
579
580-GMenuView::GMenuView(const std::shared_ptr<Model>& model,
581- const std::shared_ptr<Controller>& controller):
582- p(new Impl(model, controller))
583+GMenuView::GMenuView(const std::shared_ptr<Controller>& controller):
584+ p(new Impl(controller))
585 {
586 }
587
588@@ -997,11 +994,6 @@
589 {
590 }
591
592-void GMenuView::set_model(const std::shared_ptr<Model>& model)
593-{
594- p->set_model(model);
595-}
596-
597 const core::Signal<>& GMenuView::name_lost() const
598 {
599 return p->name_lost();
600
601=== modified file 'tests/controller-mock.h'
602--- tests/controller-mock.h 2015-08-19 18:01:58 +0000
603+++ tests/controller-mock.h 2015-08-19 18:01:58 +0000
604@@ -31,9 +31,8 @@
605 class MockController: public Controller
606 {
607 public:
608- MockController(const std::shared_ptr<MutableModel>& model,
609- const std::shared_ptr<Source>& source):
610- Controller(model, source) {}
611+ explicit MockController(const std::shared_ptr<Source>& source):
612+ Controller(source) {}
613
614 MOCK_METHOD0(pause_all, void());
615 MOCK_METHOD0(resume_all, void());
616
617=== modified file 'tests/source-mock.h'
618--- tests/source-mock.h 2015-08-19 18:01:58 +0000
619+++ tests/source-mock.h 2015-08-19 18:01:58 +0000
620@@ -34,16 +34,23 @@
621 class MockSource: public Source
622 {
623 public:
624- MockSource(): m_model(new MutableModel) {}
625+ MockSource(): m_model(new MutableModel)
626+ {
627+ // make sure that the transfer get removed from model on clear call
628+ ON_CALL(*this, clear(::testing::_))
629+ .WillByDefault(::testing::Invoke(m_model.get(), &MutableModel::remove));
630+ }
631
632 MOCK_METHOD1(open, void(const Transfer::Id&));
633 MOCK_METHOD1(start, void(const Transfer::Id&));
634 MOCK_METHOD1(pause, void(const Transfer::Id&));
635 MOCK_METHOD1(resume, void(const Transfer::Id&));
636 MOCK_METHOD1(cancel, void(const Transfer::Id&));
637+ MOCK_METHOD1(clear, void(const Transfer::Id&));
638+ MOCK_METHOD1(update, void(const Transfer::Id&));
639 MOCK_METHOD1(open_app, void(const Transfer::Id&));
640
641- std::shared_ptr<MutableModel> get_model() override {return m_model;}
642+ const std::shared_ptr<const MutableModel> get_model() override {return m_model;}
643 std::shared_ptr<MutableModel> m_model;
644 };
645
646
647=== modified file 'tests/test-controller.cpp'
648--- tests/test-controller.cpp 2015-08-19 18:01:58 +0000
649+++ tests/test-controller.cpp 2015-08-19 18:01:58 +0000
650@@ -36,7 +36,6 @@
651 GTestDBus* bus = nullptr;
652
653 std::shared_ptr<MockSource> m_source;
654- std::shared_ptr<MutableModel> m_model;
655 std::shared_ptr<Controller> m_controller;
656
657 void SetUp()
658@@ -44,14 +43,12 @@
659 super::SetUp();
660
661 m_source.reset(new MockSource);
662- m_model.reset(new MutableModel);
663- m_controller.reset(new Controller(m_model, m_source));
664+ m_controller.reset(new Controller(m_source));
665 }
666
667 void TearDown()
668 {
669 m_controller.reset();
670- m_model.reset();
671 m_source.reset();
672
673 super::TearDown();
674@@ -102,22 +99,29 @@
675 auto t = std::make_shared<Transfer>();
676 t->state = transfer.state;
677 t->id = transfer.id;
678- m_model->add(t);
679+ m_source->m_model->add(t);
680 }
681
682 // make sure all the transfers made it into the model
683- auto ids = m_model->get_ids();
684- EXPECT_EQ(G_N_ELEMENTS(transfers), ids.size());
685+ EXPECT_EQ(G_N_ELEMENTS(transfers), m_controller->size());
686 for (const auto& transfer : transfers)
687- EXPECT_EQ(1, ids.count(transfer.id));
688+ {
689+ EXPECT_EQ(1, m_controller->count(transfer.id));
690+ EXPECT_CALL(*m_source, clear(transfer.id)).Times(transfer.can_clear?1:0);
691+ }
692
693 // call clear-all
694 m_controller->clear_all();
695
696- // make sure all the clearable transfers are gone
697- ids = m_model->get_ids();
698+ // make sure all the clearable transfers are gone from controler and source
699+ auto source_ids = m_source->get_model()->get_ids();
700+
701 for (const auto& transfer : transfers)
702- EXPECT_EQ((transfer.can_clear ? 0 : 1), ids.count(transfer.id));
703+ {
704+ int expect_count = (transfer.can_clear ? 0 : 1);
705+ EXPECT_EQ(source_ids.count(transfer.id), expect_count);
706+ EXPECT_EQ(m_controller->count(transfer.id), expect_count);
707+ }
708 }
709
710 /**
711@@ -145,7 +149,7 @@
712 auto t = std::make_shared<Transfer>();
713 t->state = transfer.state;
714 t->id = transfer.id;
715- m_model->add(t);
716+ m_source->m_model->add(t);
717 EXPECT_EQ(transfer.can_pause, t->can_pause());
718 EXPECT_CALL(*m_source, pause(transfer.id)).Times(transfer.can_pause?1:0);
719 }
720@@ -178,7 +182,7 @@
721 auto t = std::make_shared<Transfer>();
722 t->state = transfer.state;
723 t->id = transfer.id;
724- m_model->add(t);
725+ m_source->m_model->add(t);
726 EXPECT_EQ(transfer.can_resume, t->can_resume());
727 EXPECT_CALL(*m_source, resume(transfer.id)).Times(transfer.can_resume?1:0);
728 }
729@@ -196,7 +200,7 @@
730 auto t = std::make_shared<Transfer>();
731 t->state = Transfer::QUEUED;
732 t->id = id;
733- m_model->add(t);
734+ m_source->m_model->add(t);
735
736 t->state = Transfer::QUEUED;
737 EXPECT_CALL(*m_source, start(id)).Times(1);
738@@ -269,7 +273,7 @@
739 auto t = std::make_shared<Transfer>();
740 t->id = id;
741 t->state = Transfer::QUEUED;
742- m_model->add(t);
743+ m_source->m_model->add(t);
744
745 for (const auto& state : all_states)
746 {
747@@ -289,7 +293,7 @@
748 auto t = std::make_shared<Transfer>();
749 t->id = id;
750 t->state = Transfer::QUEUED;
751- m_model->add(t);
752+ m_source->m_model->add(t);
753
754 for (const auto& state : all_states)
755 {
756@@ -309,7 +313,7 @@
757 auto t = std::make_shared<Transfer>();
758 t->id = id;
759 t->state = Transfer::QUEUED;
760- m_model->add(t);
761+ m_source->m_model->add(t);
762
763 for (const auto& state : all_states)
764 {
765@@ -329,7 +333,7 @@
766 auto t = std::make_shared<Transfer>();
767 t->id = id;
768 t->state = Transfer::QUEUED;
769- m_model->add(t);
770+ m_source->m_model->add(t);
771
772 for (const auto& state : all_states)
773 {
774
775=== modified file 'tests/test-multisource.cpp'
776--- tests/test-multisource.cpp 2015-08-19 18:01:58 +0000
777+++ tests/test-multisource.cpp 2015-08-19 18:01:58 +0000
778@@ -40,7 +40,7 @@
779 bool operator==(const Event& that) const { return type==that.type && id==that.id; }
780 };
781
782- bool model_consists_of(const std::shared_ptr<Model>& model, std::initializer_list<std::shared_ptr<Transfer>> list) const
783+ bool model_consists_of(const std::shared_ptr<const Model>& model, std::initializer_list<std::shared_ptr<Transfer>> list) const
784 {
785 // test get_all()
786 std::vector<std::shared_ptr<Transfer>> transfers(list);
787@@ -82,7 +82,7 @@
788 const Transfer::Id aid {"aid"};
789 auto at = std::make_shared<Transfer>();
790 at->id = aid;
791- a->get_model()->add(at);
792+ a->m_model->add(at);
793 expected_events.push_back(Event{Event::ADDED,aid});
794
795 // confirm that the multimodel sees the new transfer
796@@ -94,7 +94,7 @@
797 const Transfer::Id bid {"bid"};
798 auto bt = std::make_shared<Transfer>();
799 bt->id = bid;
800- b->get_model()->add(bt);
801+ b->m_model->add(bt);
802 expected_events.push_back(Event{Event::ADDED,bid});
803
804 // confirm that the multimodel sees the new transfer
805@@ -104,20 +104,20 @@
806
807 // poke transfer 'at'...
808 at->progress = 50.0;
809- a->get_model()->emit_changed(aid);
810+ a->m_model->emit_changed(aid);
811 expected_events.push_back(Event{Event::CHANGED,aid});
812 EXPECT_EQ(expected_events, events);
813 EXPECT_TRUE(model_consists_of(multimodel, {at, bt}));
814
815 // remove transfer 'at'...
816- a->get_model()->remove(aid);
817+ a->m_model->remove(aid);
818 expected_events.push_back(Event{Event::REMOVED,aid});
819 EXPECT_EQ(expected_events, events);
820 EXPECT_FALSE(a->get_model()->get(aid));
821 EXPECT_TRUE(model_consists_of(multimodel, {bt}));
822
823 // remove transfer 'bt'...
824- b->get_model()->remove(bid);
825+ b->m_model->remove(bid);
826 expected_events.push_back(Event{Event::REMOVED,bid});
827 EXPECT_EQ(expected_events, events);
828 EXPECT_FALSE(b->get_model()->get(aid));
829@@ -139,13 +139,13 @@
830 const Transfer::Id aid {"aid"};
831 auto at = std::make_shared<Transfer>();
832 at->id = aid;
833- a->get_model()->add(at);
834+ a->m_model->add(at);
835
836 // add a transfer to the 'b' source...
837 const Transfer::Id bid {"bid"};
838 auto bt = std::make_shared<Transfer>();
839 bt->id = bid;
840- b->get_model()->add(bt);
841+ b->m_model->add(bt);
842
843 // confirm that multisource method calls are delegated to 'a'
844 EXPECT_CALL(*a, open(aid)); multisource.open(aid);
845
846=== modified file 'tests/test-plugin-source.cpp'
847--- tests/test-plugin-source.cpp 2015-08-19 18:01:58 +0000
848+++ tests/test-plugin-source.cpp 2015-08-19 18:01:58 +0000
849@@ -34,7 +34,6 @@
850
851 GTestDBus* bus = nullptr;
852
853- std::shared_ptr<MutableModel> m_model;
854 std::shared_ptr<Source> m_source;
855 std::shared_ptr<Controller> m_controller;
856
857@@ -44,15 +43,13 @@
858
859 auto plugin_dir = g_get_current_dir();
860 m_source.reset(new PluginSource(plugin_dir));
861- m_model = m_source->get_model();
862- m_controller.reset(new Controller(m_model, m_source));
863+ m_controller.reset(new Controller(m_source));
864 g_clear_pointer(&plugin_dir, g_free);
865 }
866
867 void TearDown()
868 {
869 m_controller.reset();
870- m_model.reset();
871 m_source.reset();
872
873 super::TearDown();
874
875=== modified file 'tests/test-view-gmenu.cpp'
876--- tests/test-view-gmenu.cpp 2015-08-19 18:01:58 +0000
877+++ tests/test-view-gmenu.cpp 2015-08-19 18:01:58 +0000
878@@ -37,7 +37,6 @@
879
880 GTestDBus* bus = nullptr;
881 std::shared_ptr<MockSource> m_source;
882- std::shared_ptr<MutableModel> m_model;
883 std::shared_ptr<MockController> m_controller;
884 std::shared_ptr<GMenuView> m_view;
885
886@@ -54,22 +53,21 @@
887
888 // bring up the source
889 m_source.reset(new MockSource);
890- m_model.reset(new MutableModel);
891 std::shared_ptr<Transfer> t;
892 t.reset(new Transfer);
893 t->id = "a";
894 t->state = Transfer::RUNNING;
895- m_model->add(t);
896+ m_source->m_model->add(t);
897 t.reset(new Transfer);
898 t->id = "b";
899 t->state = Transfer::PAUSED;
900- m_model->add(t);
901+ m_source->m_model->add(t);
902 t.reset(new Transfer);
903 t->id = "c";
904 t->state = Transfer::FINISHED;
905- m_model->add(t);
906- m_controller.reset(new MockController(m_model, m_source));
907- m_view.reset(new GMenuView(m_model, m_controller));
908+ m_source->m_model->add(t);
909+ m_controller.reset(new MockController(m_source));
910+ m_view.reset(new GMenuView(m_controller));
911 }
912
913 void TearDown()
914@@ -77,7 +75,6 @@
915 // empty the source
916 m_view.reset();
917 m_controller.reset();
918- m_model.reset();
919 m_source.reset();
920
921 // bring down the bus
922@@ -147,9 +144,9 @@
923 "resume-all",
924 "resume-transfer"
925 };
926- for (const auto& id : m_model->get_ids())
927+ for (const auto& id : m_source->get_model()->get_ids())
928 expected_actions.insert("transfer-state." + id);
929-
930+
931 auto connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
932 auto exported = g_dbus_action_group_get(connection, BUS_NAME, BUS_PATH);
933 auto names_strv = g_action_group_list_actions(G_ACTION_GROUP(exported));
934@@ -205,14 +202,14 @@
935
936 // try tapping a transfer that can be resumed
937 const char* id = "b";
938- EXPECT_TRUE(m_model->get(id)->can_resume());
939+ EXPECT_TRUE(m_source->get_model()->get(id)->can_resume());
940 EXPECT_CALL(*m_controller, tap(id)).Times(1);
941 g_action_group_activate_action(action_group, "activate-transfer", g_variant_new_string(id));
942 wait_msec();
943
944 // try tapping a transfer that CAN'T be resumed
945 id = "c";
946- EXPECT_TRUE(!m_model->get(id)->can_resume());
947+ EXPECT_TRUE(!m_source->get_model()->get(id)->can_resume());
948 EXPECT_CALL(*m_controller, tap(id)).Times(1);
949 g_action_group_activate_action(action_group, "activate-transfer", g_variant_new_string(id));
950 wait_msec();
951@@ -270,7 +267,7 @@
952 /***
953 ****
954 **** Header
955-****
956+****
957 ***/
958
959 namespace
960@@ -352,10 +349,10 @@
961 // Visibility test #1:
962 // Change the model to all transfers finished.
963 // Confirm that the header is not visible.
964- for (auto& transfer : m_model->get_all())
965+ for (auto& transfer : m_source->get_model()->get_all())
966 {
967 transfer->state = Transfer::FINISHED;
968- m_model->emit_changed(transfer->id);
969+ m_source->m_model->emit_changed(transfer->id);
970 }
971
972 wait_msec(200);
973@@ -364,26 +361,26 @@
974 // Visibility test #2:
975 // Change the model to all transfers finished except one running.
976 // Confirm that the header is visible.
977- auto transfer = m_model->get("a");
978+ auto transfer = m_source->get_model()->get("a");
979 transfer->state = Transfer::RUNNING;
980- m_model->emit_changed(transfer->id);
981+ m_source->m_model->emit_changed(transfer->id);
982 wait_msec(200);
983 EXPECT_TRUE(is_header_visible(action_group, action_name));
984
985 // Visibility test #3:
986 // Change the model to all transfers finished except one paused.
987 // Confirm that the header is visible.
988- transfer = m_model->get("a");
989+ transfer = m_source->get_model()->get("a");
990 transfer->state = Transfer::PAUSED;
991- m_model->emit_changed(transfer->id);
992+ m_source->m_model->emit_changed(transfer->id);
993 wait_msec(200);
994 EXPECT_TRUE(is_header_visible(action_group, action_name));
995
996 // Visibility test #4:
997 // Remove all the transfers from the menu.
998 // Confirm that the header is not visible.
999- for (const auto& id : m_model->get_ids())
1000- m_model->remove(id);
1001+ for (const auto& id : m_source->get_model()->get_ids())
1002+ m_source->m_model->remove(id);
1003 wait_msec(200);
1004 EXPECT_FALSE(is_header_visible(action_group, action_name));
1005

Subscribers

People subscribed via source and target branches