Merge lp:~3v1n0/unity/keep-priority-launcher-model into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Timo Jyrinki
Approved revision: no longer in the source branch.
Merged at revision: 2660
Proposed branch: lp:~3v1n0/unity/keep-priority-launcher-model
Merge into: lp:unity
Diff against target: 1314 lines (+513/-454)
7 files modified
launcher/Launcher.cpp (+2/-1)
launcher/LauncherController.cpp (+1/-6)
launcher/LauncherModel.cpp (+191/-202)
launcher/LauncherModel.h (+19/-20)
launcher/MockLauncherIcon.h (+9/-9)
tests/test_launcher.cpp (+0/-4)
tests/test_launcher_model.cpp (+291/-212)
To merge this branch: bzr merge lp:~3v1n0/unity/keep-priority-launcher-model
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
jenkins continuous-integration Pending
Review via email: mp+122699@code.launchpad.net

Commit message

LauncherModel: rewrite the Reordering functions to keep the icon priority deltas

The priority of the icons added to the model was reset every time the model
was reordered; we should otherwise keep the priority deltas between icons
so that we can safely set them without be worried that a reorder would completely
reset them.
Also add IconIndex method to get the positio of a given icon.

Description of the change

The unity LauncherModel used the IconPriority value to sort icons, however it was resetting this value every time the model was reordered, and was not possible to keep the priority deltas between the icons.
I've rewritten the model functions to make them change the priority to a relative value, instead of absolute ones.

This work is preliminary to the work needed for bug #761155

Unit tests added and updated.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM... Discussed and reviewed on IRC.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1181/console reported an error when processing this lp:~3v1n0/unity/keep-priority-launcher-model branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1203/console reported an error when processing this lp:~3v1n0/unity/keep-priority-launcher-model branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1209/console reported an error when processing this lp:~3v1n0/unity/keep-priority-launcher-model branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1212/console reported an error when processing this lp:~3v1n0/unity/keep-priority-launcher-model branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/Launcher.cpp'
--- launcher/Launcher.cpp 2012-09-03 08:47:49 +0000
+++ launcher/Launcher.cpp 2012-09-04 16:43:33 +0000
@@ -1981,7 +1981,8 @@
19811981
1982 // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying1982 // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying
1983 // on an internal Launcher property then1983 // on an internal Launcher property then
1984 if (drag_icon && _last_button_press == 1 && _model->IconHasSister(drag_icon))1984 bool can_drag = (_model->IconHasSister(drag_icon) || drag_icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE);
1985 if (drag_icon && _last_button_press == 1 && can_drag)
1985 {1986 {
1986 SetActionState(ACTION_DRAG_ICON);1987 SetActionState(ACTION_DRAG_ICON);
1987 StartIconDrag(drag_icon);1988 StartIconDrag(drag_icon);
19881989
=== modified file 'launcher/LauncherController.cpp'
--- launcher/LauncherController.cpp 2012-08-30 21:09:02 +0000
+++ launcher/LauncherController.cpp 2012-09-04 16:43:33 +0000
@@ -688,10 +688,6 @@
688 GList* apps, *l;688 GList* apps, *l;
689 BamfApplication* app;689 BamfApplication* app;
690690
691 // Sufficiently large number such that we ensure proper sorting
692 // (avoids case where first item gets tacked onto end rather than start)
693 int priority = 100;
694
695 FavoriteList const& favs = FavoriteStore::Instance().GetFavorites();691 FavoriteList const& favs = FavoriteStore::Instance().GetFavorites();
696692
697 for (FavoriteList::const_iterator i = favs.begin(), end = favs.end();693 for (FavoriteList::const_iterator i = favs.begin(), end = favs.end();
@@ -701,9 +697,8 @@
701697
702 if (fav)698 if (fav)
703 {699 {
704 fav->SetSortPriority(priority);700 fav->SetSortPriority(sort_priority_++);
705 RegisterIcon(fav);701 RegisterIcon(fav);
706 priority++;
707 }702 }
708 }703 }
709704
710705
=== modified file 'launcher/LauncherModel.cpp'
--- launcher/LauncherModel.cpp 2012-08-31 19:35:46 +0000
+++ launcher/LauncherModel.cpp 2012-09-04 16:43:33 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,6 +15,7 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#include "LauncherModel.h"21#include "LauncherModel.h"
@@ -30,8 +31,7 @@
3031
31LauncherModel::LauncherModel()32LauncherModel::LauncherModel()
32 : selection_(0)33 : selection_(0)
33{34{}
34}
3535
36std::string LauncherModel::GetName() const36std::string LauncherModel::GetName() const
37{37{
@@ -54,12 +54,12 @@
54 return introspection_results_;54 return introspection_results_;
55}55}
5656
57bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr icon) const57bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const
58{58{
59 return icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH;59 return icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH;
60}60}
6161
62bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second)62bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second)
63{63{
64 if (first->GetIconType() < second->GetIconType())64 if (first->GetIconType() < second->GetIconType())
65 return true;65 return true;
@@ -69,36 +69,43 @@
69 return first->SortPriority() < second->SortPriority();69 return first->SortPriority() < second->SortPriority();
70}70}
7171
72bool72void LauncherModel::PopulatePart(iterator begin, iterator end)
73LauncherModel::Populate()73{
74 AbstractLauncherIcon::Ptr prev_icon;
75 for (auto it = begin; it != end; ++it)
76 {
77 auto const& icon = *it;
78 _inner.push_back(icon);
79
80 if (prev_icon)
81 {
82 // Ensuring that the current icon has higher priority than previous one
83 if (icon->SortPriority() < prev_icon->SortPriority())
84 {
85 int new_priority = prev_icon->SortPriority() + 1;
86 icon->SetSortPriority(new_priority);
87 }
88 }
89
90 prev_icon = icon;
91 }
92}
93
94bool LauncherModel::Populate()
74{95{
75 Base copy = _inner;96 Base copy = _inner;
76
77 _inner.clear();97 _inner.clear();
7898 PopulatePart(main_begin(), main_end());
79 iterator it, it2;99 PopulatePart(shelf_begin(), shelf_end());
80
81 int i = 0;
82 for (it = main_begin(); it != main_end(); ++it)
83 {
84 _inner.push_back(*it);
85 (*it)->SetSortPriority(i);
86 ++i;
87 }
88
89 for (it = shelf_begin(); it != shelf_end(); ++it)
90 {
91 _inner.push_back(*it);
92 (*it)->SetSortPriority(i);
93 ++i;
94 }
95100
96 return copy.size() == _inner.size() && !std::equal(begin(), end(), copy.begin());101 return copy.size() == _inner.size() && !std::equal(begin(), end(), copy.begin());
97}102}
98103
99void104void LauncherModel::AddIcon(AbstractLauncherIcon::Ptr const& icon)
100LauncherModel::AddIcon(AbstractLauncherIcon::Ptr icon)
101{105{
106 if (!icon || std::find(begin(), end(), icon) != end())
107 return;
108
102 if (IconShouldShelf(icon))109 if (IconShouldShelf(icon))
103 _inner_shelf.push_back(icon);110 _inner_shelf.push_back(icon);
104 else111 else
@@ -113,8 +120,7 @@
113 icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove));120 icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove));
114}121}
115122
116void123void LauncherModel::RemoveIcon(AbstractLauncherIcon::Ptr const& icon)
117LauncherModel::RemoveIcon(AbstractLauncherIcon::Ptr icon)
118{124{
119 size_t size;125 size_t size;
120126
@@ -130,23 +136,20 @@
130 }136 }
131}137}
132138
133void139void LauncherModel::OnIconRemove(AbstractLauncherIcon::Ptr const& icon)
134LauncherModel::OnIconRemove(AbstractLauncherIcon::Ptr icon)
135{140{
136 timeouts_.AddTimeout(1000, [&, icon] {141 timeouts_.AddTimeout(1000, [this, icon] {
137 RemoveIcon(icon);142 RemoveIcon(icon);
138 return false;143 return false;
139 });144 });
140}145}
141146
142void147void LauncherModel::Save()
143LauncherModel::Save()
144{148{
145 saved.emit();149 saved.emit();
146}150}
147151
148void152void LauncherModel::Sort()
149LauncherModel::Sort()
150{153{
151 std::stable_sort(_inner_shelf.begin(), _inner_shelf.end(), &LauncherModel::CompareIcons);154 std::stable_sort(_inner_shelf.begin(), _inner_shelf.end(), &LauncherModel::CompareIcons);
152 std::stable_sort(_inner_main.begin(), _inner_main.end(), &LauncherModel::CompareIcons);155 std::stable_sort(_inner_main.begin(), _inner_main.end(), &LauncherModel::CompareIcons);
@@ -155,15 +158,14 @@
155 order_changed.emit();158 order_changed.emit();
156}159}
157160
158bool161bool LauncherModel::IconHasSister(AbstractLauncherIcon::Ptr const& icon) const
159LauncherModel::IconHasSister(AbstractLauncherIcon::Ptr icon) const
160{162{
163 if (!icon)
164 return false;
165
161 const_iterator it;166 const_iterator it;
162 const_iterator end;167 const_iterator end;
163168
164 if (icon && icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE)
165 return true;
166
167 if (IconShouldShelf(icon))169 if (IconShouldShelf(icon))
168 {170 {
169 it = _inner_shelf.begin();171 it = _inner_shelf.begin();
@@ -177,144 +179,125 @@
177179
178 for (; it != end; ++it)180 for (; it != end; ++it)
179 {181 {
180 AbstractLauncherIcon::Ptr iter_icon = *it;182 AbstractLauncherIcon::Ptr const& iter_icon = *it;
181 if ((iter_icon != icon)183
182 && iter_icon->GetIconType() == icon->GetIconType())184 if (iter_icon != icon && iter_icon->GetIconType() == icon->GetIconType())
183 return true;185 return true;
184 }186 }
185187
186 return false;188 return false;
187}189}
188190
189void191void LauncherModel::ReorderAfter(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other)
190LauncherModel::ReorderAfter(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other)192{
191{193 if (icon == other || icon.IsNull() || other.IsNull())
192 if (icon == other || icon.IsNull() || other.IsNull())194 return;
193 return;195
194196 if (icon->GetIconType() != other->GetIconType())
195 if (icon->GetIconType() != other->GetIconType())197 return;
196 return;198
197199 icon->SetSortPriority(other->SortPriority() + 1);
198 int i = 0;200
199 for (LauncherModel::iterator it = begin(); it != end(); ++it)201 for (auto it = std::next(std::find(begin(), end(), other)); it != end(); ++it)
200 {202 {
201 if ((*it) == icon)203 // Increasing the priority of the icons next to the other one
202 continue;204 auto const& icon_it = *it;
203205 int new_priority = icon_it->SortPriority() + 1;
204 if ((*it) == other)206 icon_it->SetSortPriority(new_priority);
205 {207 }
206 (*it)->SetSortPriority(i);208
207 ++i;209 Sort();
208210}
209 icon->SetSortPriority(i);211
210 ++i;212void LauncherModel::ReorderBefore(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate)
211 }213{
212 else214 if (icon == other || icon.IsNull() || other.IsNull())
213 {215 return;
214 (*it)->SetSortPriority(i);216
215 ++i;217 if (icon->GetIconType() != other->GetIconType())
216 }218 return;
217 }219
218220 bool found_target = false;
219 Sort();221 bool center = false;
220}222
221223 for (auto const& icon_it : _inner)
222void224 {
223LauncherModel::ReorderBefore(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save)225 if (icon_it == icon)
224{226 {
225 if (icon == other || icon.IsNull() || other.IsNull())227 center = !center;
226 return;228 continue;
227229 }
228 if (icon->GetIconType() != other->GetIconType())230
229 return;231 int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1);
230232 icon_it->SetSortPriority(new_priority);
231 int i = 0;233
232 int j = 0;234 if (icon_it == other)
233 for (auto icon_it : _inner)235 {
234 {236 if (animate && center)
235 if (icon_it == icon)237 icon_it->SaveCenter();
236 {238
237 j++;239 center = !center;
238 continue;240 new_priority = new_priority - 1;
239 }241 icon->SetSortPriority(new_priority);
240242
241 if (icon_it == other)243 if (animate && center)
242 {244 icon_it->SaveCenter();
243 icon->SetSortPriority(i);245
244 if (i != j && save)246 found_target = true;
245 icon_it->SaveCenter();247 }
246 i++;248 else
247249 {
248 icon_it->SetSortPriority(i);250 if (animate && center)
249 if (i != j && save)251 icon_it->SaveCenter();
250 icon_it->SaveCenter();252 }
251 i++;253 }
252 }254
253 else255 Sort();
254 {256}
255 icon_it->SetSortPriority(i);257
256 if (i != j && save)258void LauncherModel::ReorderSmart(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate)
257 icon_it->SaveCenter();259{
258 i++;260 if (icon == other || icon.IsNull() || other.IsNull())
259 }261 return;
260 j++;262
261 }263 if (icon->GetIconType() != other->GetIconType())
262264 return;
263 Sort();265
264}266 bool found_icon = false;
265267 bool found_target = false;
266void268 bool center = false;
267LauncherModel::ReorderSmart(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save)269
268{270 for (auto const& icon_it : _inner)
269 if (icon == other || icon.IsNull() || other.IsNull())271 {
270 return;272 if (icon_it == icon)
271273 {
272 if (icon->GetIconType() != other->GetIconType())274 found_icon = true;
273 return;275 center = !center;
274276 continue;
275 int i = 0;277 }
276 int j = 0;278
277 bool skipped = false;279 int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1);
278 for (auto icon_it : _inner)280 icon_it->SetSortPriority(new_priority);
279 {281
280 if (icon_it == icon)282 if (icon_it == other)
281 {283 {
282 skipped = true;284 if (animate && center)
283 j++;285 icon_it->SaveCenter();
284 continue;286
285 }287 center = !center;
286288 new_priority = new_priority + (found_icon ? 1 : -1);
287 if (icon_it == other)289 icon->SetSortPriority(new_priority);
288 {290
289 if (!skipped)291 if (animate && center)
290 {292 icon_it->SaveCenter();
291 icon->SetSortPriority(i);293
292 if (i != j && save)294 found_target = true;
293 icon_it->SaveCenter();295 }
294 i++;296 else
295 }297 {
296298 if (animate && center)
297 icon_it->SetSortPriority(i);299 icon_it->SaveCenter();
298 if (i != j && save)300 }
299 icon_it->SaveCenter();
300 i++;
301
302 if (skipped)
303 {
304 icon->SetSortPriority(i);
305 if (i != j && save)
306 icon_it->SaveCenter();
307 i++;
308 }
309 }
310 else
311 {
312 icon_it->SetSortPriority(i);
313 if (i != j && save)
314 icon_it->SaveCenter();
315 i++;
316 }
317 j++;
318 }301 }
319302
320 Sort();303 Sort();
@@ -357,7 +340,7 @@
357 if (temp >= Size())340 if (temp >= Size())
358 temp = 0;341 temp = 0;
359342
360 if (_inner[temp]->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE))343 if (_inner[temp]->IsVisible())
361 {344 {
362 selection_ = temp;345 selection_ = temp;
363 selection_changed.emit(Selection());346 selection_changed.emit(Selection());
@@ -377,7 +360,7 @@
377 if (temp < 0)360 if (temp < 0)
378 temp = Size() - 1;361 temp = Size() - 1;
379362
380 if (_inner[temp]->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE))363 if (_inner[temp]->IsVisible())
381 {364 {
382 selection_ = temp;365 selection_ = temp;
383 selection_changed.emit(Selection());366 selection_changed.emit(Selection());
@@ -387,7 +370,7 @@
387 }370 }
388}371}
389372
390AbstractLauncherIcon::Ptr LauncherModel::GetClosestIcon(AbstractLauncherIcon::Ptr icon, bool& is_before) const373AbstractLauncherIcon::Ptr LauncherModel::GetClosestIcon(AbstractLauncherIcon::Ptr const& icon, bool& is_before) const
391{374{
392 AbstractLauncherIcon::Ptr prev, next;375 AbstractLauncherIcon::Ptr prev, next;
393 bool found_target = false;376 bool found_target = false;
@@ -423,22 +406,38 @@
423 return is_before ? prev : next;406 return is_before ? prev : next;
424}407}
425408
409int LauncherModel::IconIndex(AbstractLauncherIcon::Ptr const& target) const
410{
411 int pos = 0;
412 bool found = false;
413
414 for (auto const& icon : _inner)
415 {
416 if (icon == target)
417 {
418 found = true;
419 break;
420 }
421
422 ++pos;
423 }
424
425 return found ? pos : -1;
426}
427
426/* iterators */428/* iterators */
427429
428LauncherModel::iterator430LauncherModel::iterator LauncherModel::begin()
429LauncherModel::begin()
430{431{
431 return _inner.begin();432 return _inner.begin();
432}433}
433434
434LauncherModel::iterator435LauncherModel::iterator LauncherModel::end()
435LauncherModel::end()
436{436{
437 return _inner.end();437 return _inner.end();
438}438}
439439
440LauncherModel::iterator440LauncherModel::iterator LauncherModel::at(int index)
441LauncherModel::at(int index)
442{441{
443 LauncherModel::iterator it;442 LauncherModel::iterator it;
444 int i;443 int i;
@@ -453,62 +452,52 @@
453 return (LauncherModel::iterator)NULL;452 return (LauncherModel::iterator)NULL;
454}453}
455454
456LauncherModel::reverse_iterator455LauncherModel::reverse_iterator LauncherModel::rbegin()
457LauncherModel::rbegin()
458{456{
459 return _inner.rbegin();457 return _inner.rbegin();
460}458}
461459
462LauncherModel::reverse_iterator460LauncherModel::reverse_iterator LauncherModel::rend()
463LauncherModel::rend()
464{461{
465 return _inner.rend();462 return _inner.rend();
466}463}
467464
468LauncherModel::iterator465LauncherModel::iterator LauncherModel::main_begin()
469LauncherModel::main_begin()
470{466{
471 return _inner_main.begin();467 return _inner_main.begin();
472}468}
473469
474LauncherModel::iterator470LauncherModel::iterator LauncherModel::main_end()
475LauncherModel::main_end()
476{471{
477 return _inner_main.end();472 return _inner_main.end();
478}473}
479474
480LauncherModel::reverse_iterator475LauncherModel::reverse_iterator LauncherModel::main_rbegin()
481LauncherModel::main_rbegin()
482{476{
483 return _inner_main.rbegin();477 return _inner_main.rbegin();
484}478}
485479
486LauncherModel::reverse_iterator480LauncherModel::reverse_iterator LauncherModel::main_rend()
487LauncherModel::main_rend()
488{481{
489 return _inner_main.rend();482 return _inner_main.rend();
490}483}
491484
492LauncherModel::iterator485LauncherModel::iterator LauncherModel::shelf_begin()
493LauncherModel::shelf_begin()
494{486{
495 return _inner_shelf.begin();487 return _inner_shelf.begin();
496}488}
497489
498LauncherModel::iterator490LauncherModel::iterator LauncherModel::shelf_end()
499LauncherModel::shelf_end()
500{491{
501 return _inner_shelf.end();492 return _inner_shelf.end();
502}493}
503494
504LauncherModel::reverse_iterator495LauncherModel::reverse_iterator LauncherModel::shelf_rbegin()
505LauncherModel::shelf_rbegin()
506{496{
507 return _inner_shelf.rbegin();497 return _inner_shelf.rbegin();
508}498}
509499
510LauncherModel::reverse_iterator500LauncherModel::reverse_iterator LauncherModel::shelf_rend()
511LauncherModel::shelf_rend()
512{501{
513 return _inner_shelf.rend();502 return _inner_shelf.rend();
514}503}
515504
=== modified file 'launcher/LauncherModel.h'
--- launcher/LauncherModel.h 2012-08-31 19:35:46 +0000
+++ launcher/LauncherModel.h 2012-09-04 16:43:33 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,6 +15,7 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#ifndef LAUNCHERMODEL_H21#ifndef LAUNCHERMODEL_H
@@ -41,20 +42,18 @@
4142
42 LauncherModel();43 LauncherModel();
4344
44 void AddIcon(AbstractLauncherIcon::Ptr icon);45 void AddIcon(AbstractLauncherIcon::Ptr const& icon);
45 void RemoveIcon(AbstractLauncherIcon::Ptr icon);46 void RemoveIcon(AbstractLauncherIcon::Ptr const& icon);
46 void Save();47 void Save();
47 void Sort();48 void Sort();
48 int Size() const;49 int Size() const;
4950
50 void OnIconRemove(AbstractLauncherIcon::Ptr icon);51 bool IconHasSister(AbstractLauncherIcon::Ptr const& icon) const;
5152 int IconIndex(AbstractLauncherIcon::Ptr const& icon) const;
52 bool IconHasSister(AbstractLauncherIcon::Ptr icon) const;53
5354 void ReorderAfter(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other);
54 void ReorderAfter(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other);55 void ReorderBefore(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate);
55 void ReorderBefore(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save);56 void ReorderSmart(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate);
56
57 void ReorderSmart(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save);
5857
59 AbstractLauncherIcon::Ptr Selection() const;58 AbstractLauncherIcon::Ptr Selection() const;
60 int SelectionIndex() const;59 int SelectionIndex() const;
@@ -62,7 +61,7 @@
62 void SelectNext();61 void SelectNext();
63 void SelectPrevious();62 void SelectPrevious();
6463
65 AbstractLauncherIcon::Ptr GetClosestIcon(AbstractLauncherIcon::Ptr icon, bool& is_before) const;64 AbstractLauncherIcon::Ptr GetClosestIcon(AbstractLauncherIcon::Ptr const& icon, bool& is_before) const;
6665
67 iterator begin();66 iterator begin();
68 iterator end();67 iterator end();
@@ -80,17 +79,17 @@
80 reverse_iterator shelf_rbegin();79 reverse_iterator shelf_rbegin();
81 reverse_iterator shelf_rend();80 reverse_iterator shelf_rend();
8281
83 sigc::signal<void, AbstractLauncherIcon::Ptr> icon_added;82 sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_added;
84 sigc::signal<void, AbstractLauncherIcon::Ptr> icon_removed;83 sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_removed;
84 sigc::signal<void, AbstractLauncherIcon::Ptr const&> selection_changed;
85 sigc::signal<void> order_changed;85 sigc::signal<void> order_changed;
86 sigc::signal<void> saved;86 sigc::signal<void> saved;
87 sigc::signal<void, AbstractLauncherIcon::Ptr> selection_changed;
8887
89 IntrospectableList GetIntrospectableChildren();
90protected:88protected:
91 // Introspectable methods89 // Introspectable methods
92 std::string GetName() const;90 std::string GetName() const;
93 void AddProperties(GVariantBuilder* builder);91 void AddProperties(GVariantBuilder* builder);
92 IntrospectableList GetIntrospectableChildren();
9493
95private:94private:
96 Base _inner;95 Base _inner;
@@ -101,10 +100,10 @@
101 glib::SourceManager timeouts_;100 glib::SourceManager timeouts_;
102101
103 bool Populate();102 bool Populate();
104103 void PopulatePart(iterator begin, iterator end);
105 bool IconShouldShelf(AbstractLauncherIcon::Ptr icon) const;104 void OnIconRemove(AbstractLauncherIcon::Ptr const& icon);
106105 bool IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const;
107 static bool CompareIcons(AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second);106 static bool CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second);
108107
109 /* Template Methods */108 /* Template Methods */
110public:109public:
111110
=== modified file 'launcher/MockLauncherIcon.h'
--- launcher/MockLauncherIcon.h 2012-08-31 18:00:29 +0000
+++ launcher/MockLauncherIcon.h 2012-09-04 16:43:33 +0000
@@ -44,12 +44,12 @@
44{44{
45 NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon);45 NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon);
46public:46public:
47 MockLauncherIcon()47 MockLauncherIcon(IconType type = IconType::APPLICATION)
48 : icon_(0)48 : type_(type)
49 , sort_priority_(0)
50 , icon_(0)
49 {51 {
50 tooltip_text = "Mock Icon";52 tooltip_text = "Mock Icon";
51 sort_priority_ = 0;
52 type_ = IconType::APPLICATION;
5353
54 for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i)54 for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i)
55 {55 {
@@ -58,7 +58,7 @@
58 }58 }
5959
60 std::string GetName() const { return "MockLauncherIcon"; }60 std::string GetName() const { return "MockLauncherIcon"; }
61 61
62 void AddProperties(GVariantBuilder* builder) {}62 void AddProperties(GVariantBuilder* builder) {}
6363
64 void HideTooltip() {}64 void HideTooltip() {}
@@ -293,9 +293,9 @@
293 bool IsVisible() const { return false; }293 bool IsVisible() const { return false; }
294294
295 void AboutToRemove() {}295 void AboutToRemove() {}
296 296
297 void Stick(bool save = true) {}297 void Stick(bool save = true) {}
298 298
299 void UnStick() {}299 void UnStick() {}
300300
301private:301private:
@@ -346,9 +346,9 @@
346 return result;346 return result;
347 }347 }
348348
349 IconType type_;
350 int sort_priority_;
349 nux::BaseTexture* icon_;351 nux::BaseTexture* icon_;
350 int sort_priority_;
351 IconType type_;
352 bool quirks_[unsigned(Quirk::LAST)];352 bool quirks_[unsigned(Quirk::LAST)];
353 timespec quirk_times_[unsigned(Quirk::LAST)];353 timespec quirk_times_[unsigned(Quirk::LAST)];
354 std::map<int, nux::Point3> center_;354 std::map<int, nux::Point3> center_;
355355
=== modified file 'tests/test_launcher.cpp'
--- tests/test_launcher.cpp 2012-09-01 14:09:20 +0000
+++ tests/test_launcher.cpp 2012-09-04 16:43:33 +0000
@@ -210,10 +210,6 @@
210 MockMockLauncherIcon::Ptr icon2(new MockMockLauncherIcon);210 MockMockLauncherIcon::Ptr icon2(new MockMockLauncherIcon);
211 MockMockLauncherIcon::Ptr icon3(new MockMockLauncherIcon);211 MockMockLauncherIcon::Ptr icon3(new MockMockLauncherIcon);
212212
213 icon1->SetSortPriority(0);
214 icon2->SetSortPriority(1);
215 icon3->SetSortPriority(2);
216
217 model_->AddIcon(icon1);213 model_->AddIcon(icon1);
218 model_->AddIcon(icon2);214 model_->AddIcon(icon2);
219 model_->AddIcon(icon3);215 model_->AddIcon(icon3);
220216
=== modified file 'tests/test_launcher_model.cpp'
--- tests/test_launcher_model.cpp 2012-08-31 19:35:46 +0000
+++ tests/test_launcher_model.cpp 2012-09-04 16:43:33 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2011 Canonical Ltd.2 * Copyright 2011-2012 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it4 * 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 published5 * under the terms of the GNU General Public License version 3, as published
@@ -15,7 +15,7 @@
15 * <http://www.gnu.org/licenses/>15 * <http://www.gnu.org/licenses/>
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 *18 * Marco Trevisan <marco.trevisan@canonical.com>
19 */19 */
2020
21#include <gtest/gtest.h>21#include <gtest/gtest.h>
@@ -32,229 +32,308 @@
32namespace32namespace
33{33{
3434
35class EventListener35class TestLauncherModel : public testing::Test
36{36{
37 public:37public:
38 EventListener()38 TestLauncherModel()
39 {39 : icon1(new MockLauncherIcon())
40 icon_added = false;40 , icon2(new MockLauncherIcon())
41 icon_removed = false;41 , icon3(new MockLauncherIcon())
42 }42 , icon4(new MockLauncherIcon())
4343 {}
44 void OnIconAdded (AbstractLauncherIcon::Ptr icon)44
45 {45 AbstractLauncherIcon::Ptr icon1;
46 icon_added = true;46 AbstractLauncherIcon::Ptr icon2;
47 }47 AbstractLauncherIcon::Ptr icon3;
4848 AbstractLauncherIcon::Ptr icon4;
49 void OnIconRemoved (AbstractLauncherIcon::Ptr icon)49
50 {50 LauncherModel model;
51 icon_removed = true;
52 }
53
54 bool icon_added;
55 bool icon_removed;
56};51};
57//bool seen_result;52
5853TEST_F(TestLauncherModel, Constructor)
59TEST(TestLauncherModel, TestConstructor)54{
60{55 EXPECT_EQ(model.Size(), 0);
61 LauncherModel::Ptr model(new LauncherModel());56}
62 EXPECT_EQ(model->Size(), 0);57
63}58TEST_F(TestLauncherModel, Add)
6459{
65TEST(TestLauncherModel, TestAdd)60 model.AddIcon(icon1);
66{61 EXPECT_EQ(model.Size(), 1);
67 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());62
68 LauncherModel::Ptr model(new LauncherModel());63 model.AddIcon(icon1);
6964 EXPECT_EQ(model.Size(), 1);
70 EXPECT_EQ(model->Size(), 0);65
71 model->AddIcon(first);66 model.AddIcon(AbstractLauncherIcon::Ptr());
72 EXPECT_EQ(model->Size(), 1);67 EXPECT_EQ(model.Size(), 1);
73}68}
7469
75TEST(TestLauncherModel, TestRemove)70TEST_F(TestLauncherModel, Remove)
76{71{
77 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());72 model.AddIcon(icon1);
78 LauncherModel::Ptr model(new LauncherModel());73 EXPECT_EQ(model.Size(), 1);
7974
80 EXPECT_EQ(model->Size(), 0);75 model.RemoveIcon(icon1);
81 model->AddIcon(first);76 EXPECT_EQ(model.Size(), 0);
82 EXPECT_EQ(model->Size(), 1);77}
83 model->RemoveIcon(first);78
84 EXPECT_EQ(model->Size(), 0);79TEST_F(TestLauncherModel, AddSignal)
85}80{
8681 bool icon_added = false;
87TEST(TestLauncherModel, TestAddSignal)82 model.icon_added.connect([&icon_added] (AbstractLauncherIcon::Ptr) { icon_added = true; });
88{83
89 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());84 model.AddIcon(icon1);
90 LauncherModel::Ptr model(new LauncherModel());85 EXPECT_TRUE(icon_added);
9186
92 EventListener *listener = new EventListener();87 icon_added = false;
9388 model.AddIcon(icon1);
94 model->icon_added.connect(sigc::mem_fun(listener, &EventListener::OnIconAdded));89 EXPECT_FALSE(icon_added);
95 model->AddIcon(first);90
96 EXPECT_EQ(listener->icon_added, true);91 icon_added = false;
9792 model.AddIcon(AbstractLauncherIcon::Ptr());
98 delete listener;93 EXPECT_FALSE(icon_added);
99}94}
10095
101TEST(TestLauncherModel, TestRemoveSignal)96TEST_F(TestLauncherModel, RemoveSignal)
102{97{
103 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());98 bool icon_removed = false;
104 LauncherModel::Ptr model(new LauncherModel());99 model.icon_removed.connect([&icon_removed] (AbstractLauncherIcon::Ptr) { icon_removed = true; });
105100
106 EventListener *listener = new EventListener();101 model.AddIcon(icon1);
107102 EXPECT_FALSE(icon_removed);
108 model->icon_removed.connect(sigc::mem_fun(listener, &EventListener::OnIconRemoved));103 model.RemoveIcon(icon1);
109 model->AddIcon(first);104 EXPECT_TRUE(icon_removed);
110 EXPECT_EQ(listener->icon_removed, false);105}
111 model->RemoveIcon(first);106
112 EXPECT_EQ(listener->icon_removed, true);107TEST_F(TestLauncherModel, Sort)
113108{
114 delete listener;109 icon2->SetSortPriority(0);
115}110 model.AddIcon(icon2);
116111
117TEST(TestLauncherModel, TestSort)112 icon1->SetSortPriority(-1);
118{113 model.AddIcon(icon1);
119 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());114
120 AbstractLauncherIcon::Ptr second(new MockLauncherIcon());115 icon4->SetSortPriority(2);
121 AbstractLauncherIcon::Ptr third(new MockLauncherIcon());116 model.AddIcon(icon4);
122 AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());117
123118 icon3->SetSortPriority(0);
124 LauncherModel::Ptr model(new LauncherModel());119 model.AddIcon(icon3);
125120
126 third->SetSortPriority(0);121 LauncherModel::iterator it;
127 model->AddIcon(third);122 it = model.begin();
128123
129 first->SetSortPriority(-1);124 EXPECT_EQ(icon1, *it);
130 model->AddIcon(first);125 it++;
131126 EXPECT_EQ(icon2, *it);
132 fourth->SetSortPriority(2);127 it++;
133 model->AddIcon(fourth);128 EXPECT_EQ(icon3, *it);
134129 it++;
135 second->SetSortPriority(0);130 EXPECT_EQ(icon4, *it);
136 model->AddIcon(second);131}
137132
138 LauncherModel::iterator it;133TEST_F(TestLauncherModel, ModelKeepsPriorityDeltas)
139 it = model->begin();134{
140135 icon2->SetSortPriority(0);
141 EXPECT_EQ(first, *it);136 icon1->SetSortPriority(-1);
142 it++;137 icon4->SetSortPriority(2);
143 EXPECT_EQ(second, *it);138 icon3->SetSortPriority(0);
144 it++;139
145 EXPECT_EQ(third, *it);140 model.AddIcon(icon2);
146 it++;141 model.AddIcon(icon1);
147 EXPECT_EQ(fourth, *it);142 model.AddIcon(icon4);
148}143 model.AddIcon(icon3);
149144
150TEST(TestLauncherModel, TestReorderBefore)145 auto it = model.begin();
151{146 EXPECT_EQ(icon1, *it);
152 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());147 it++;
153 AbstractLauncherIcon::Ptr second(new MockLauncherIcon());148 EXPECT_EQ(icon2, *it);
154 AbstractLauncherIcon::Ptr third(new MockLauncherIcon());149 it++;
155 AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());150 EXPECT_EQ(icon3, *it);
156151 it++;
157 LauncherModel::Ptr model(new LauncherModel());152 EXPECT_EQ(icon4, *it);
158153
159 first->SetSortPriority(0);154 EXPECT_GT(icon2->SortPriority(), icon1->SortPriority());
160 second->SetSortPriority(1);155 EXPECT_EQ(icon2->SortPriority(), icon3->SortPriority());
161 third->SetSortPriority(2);156 EXPECT_LT(icon3->SortPriority(), icon4->SortPriority());
162 fourth->SetSortPriority(3);157}
163158
164 model->AddIcon(first);159TEST_F(TestLauncherModel, ReorderBefore)
165 model->AddIcon(second);160{
166 model->AddIcon(third);161 icon1->SetSortPriority(0);
167 model->AddIcon(fourth);162 icon2->SetSortPriority(1);
168163 icon3->SetSortPriority(2);
169 model->ReorderBefore(third, second, false);164 icon4->SetSortPriority(3);
170165
171 LauncherModel::iterator it;166 model.AddIcon(icon1);
172 it = model->begin();167 model.AddIcon(icon2);
173168 model.AddIcon(icon3);
174 EXPECT_EQ(first, *it);169 model.AddIcon(icon4);
175 it++;170
176 EXPECT_EQ(third, *it);171 model.ReorderBefore(icon3, icon2, false);
177 it++;172
178 EXPECT_EQ(second, *it);173 LauncherModel::iterator it;
179 it++;174 it = model.begin();
180 EXPECT_EQ(fourth, *it);175
181}176 EXPECT_EQ(icon1, *it);
182177 it++;
183TEST(TestLauncherModel, TestReorderSmart)178 EXPECT_EQ(icon3, *it);
184{179 it++;
185 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());180 EXPECT_EQ(icon2, *it);
186 AbstractLauncherIcon::Ptr second(new MockLauncherIcon());181 it++;
187 AbstractLauncherIcon::Ptr third(new MockLauncherIcon());182 EXPECT_EQ(icon4, *it);
188 AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());183}
189184
190 LauncherModel::Ptr model(new LauncherModel());185TEST_F(TestLauncherModel, ReorderAfter)
191186{
192 first->SetSortPriority(0);187 model.AddIcon(icon1);
193 second->SetSortPriority(1);188 model.AddIcon(icon3);
194 third->SetSortPriority(2);189 model.AddIcon(icon2);
195 fourth->SetSortPriority(3);190 model.AddIcon(icon4);
196191
197 model->AddIcon(first);192 model.ReorderAfter(icon3, icon2);
198 model->AddIcon(second);193
199 model->AddIcon(third);194 LauncherModel::iterator it;
200 model->AddIcon(fourth);195 it = model.begin();
201196
202 model->ReorderSmart(third, second, false);197 EXPECT_EQ(icon1, *it);
203198 it++;
204 LauncherModel::iterator it;199 EXPECT_EQ(icon2, *it);
205 it = model->begin();200 it++;
206201 EXPECT_EQ(icon3, *it);
207 EXPECT_EQ(first, *it);202 it++;
208 it++;203 EXPECT_EQ(icon4, *it);
209 EXPECT_EQ(third, *it);204}
210 it++;205
211 EXPECT_EQ(second, *it);206TEST_F(TestLauncherModel, ReorderSmart)
212 it++;207{
213 EXPECT_EQ(fourth, *it);208 icon1->SetSortPriority(0);
214}209 icon2->SetSortPriority(1);
215210 icon3->SetSortPriority(2);
216TEST(TestLauncherModel, TestGetClosestIcon)211 icon4->SetSortPriority(3);
217{212
218 LauncherModel::Ptr model(new LauncherModel());213 model.AddIcon(icon1);
219 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());214 model.AddIcon(icon2);
220 AbstractLauncherIcon::Ptr second(new MockLauncherIcon());215 model.AddIcon(icon3);
221 AbstractLauncherIcon::Ptr third(new MockLauncherIcon());216 model.AddIcon(icon4);
222 AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());217
223218 model.ReorderSmart(icon3, icon2, false);
224 first->SetSortPriority(0);219
225 second->SetSortPriority(1);220 LauncherModel::iterator it;
226 third->SetSortPriority(2);221 it = model.begin();
227 fourth->SetSortPriority(3);222
228223 EXPECT_EQ(icon1, *it);
229 model->AddIcon(first);224 it++;
230 model->AddIcon(second);225 EXPECT_EQ(icon3, *it);
231 model->AddIcon(third);226 it++;
232 model->AddIcon(fourth);227 EXPECT_EQ(icon2, *it);
228 it++;
229 EXPECT_EQ(icon4, *it);
230}
231
232TEST_F(TestLauncherModel, OrderByType)
233{
234 AbstractLauncherIcon::Ptr icon1(new MockLauncherIcon(AbstractLauncherIcon::IconType::HOME));
235 AbstractLauncherIcon::Ptr icon2(new MockLauncherIcon(AbstractLauncherIcon::IconType::APPLICATION));
236 AbstractLauncherIcon::Ptr icon3(new MockLauncherIcon(AbstractLauncherIcon::IconType::EXPO));
237 AbstractLauncherIcon::Ptr icon4(new MockLauncherIcon(AbstractLauncherIcon::IconType::DEVICE));
238 AbstractLauncherIcon::Ptr icon5(new MockLauncherIcon(AbstractLauncherIcon::IconType::TRASH));
239
240 model.AddIcon(icon3);
241 model.AddIcon(icon4);
242 model.AddIcon(icon2);
243 model.AddIcon(icon1);
244 model.AddIcon(icon5);
245
246 auto it = model.begin();
247 EXPECT_EQ(icon1, *it);
248 it++;
249 EXPECT_EQ(icon2, *it);
250 it++;
251 EXPECT_EQ(icon3, *it);
252 it++;
253 EXPECT_EQ(icon4, *it);
254 it++;
255 EXPECT_EQ(icon5, *it);
256 it++;
257 EXPECT_EQ(it, model.end());
258
259 auto it_main = model.main_begin();
260 EXPECT_EQ(icon1, *it_main);
261 it_main++;
262 EXPECT_EQ(icon2, *it_main);
263 it_main++;
264 EXPECT_EQ(icon3, *it_main);
265 it_main++;
266 EXPECT_EQ(icon4, *it_main);
267 it_main++;
268 EXPECT_EQ(it_main, model.main_end());
269
270 auto it_shelf = model.shelf_begin();
271 EXPECT_EQ(icon5, *it_shelf);
272 it_shelf++;
273 EXPECT_EQ(it_shelf, model.shelf_end());
274}
275
276TEST_F(TestLauncherModel, GetClosestIcon)
277{
278 model.AddIcon(icon1);
279 model.AddIcon(icon2);
280 model.AddIcon(icon3);
281 model.AddIcon(icon4);
233282
234 bool before;283 bool before;
235 EXPECT_EQ(model->GetClosestIcon(first, before), second);284 EXPECT_EQ(model.GetClosestIcon(icon1, before), icon2);
236 EXPECT_FALSE(before);285 EXPECT_FALSE(before);
237286
238 EXPECT_EQ(model->GetClosestIcon(second, before), first);287 EXPECT_EQ(model.GetClosestIcon(icon2, before), icon1);
239 EXPECT_TRUE(before);288 EXPECT_TRUE(before);
240289
241 EXPECT_EQ(model->GetClosestIcon(third, before), second);290 EXPECT_EQ(model.GetClosestIcon(icon3, before), icon2);
242 EXPECT_TRUE(before);291 EXPECT_TRUE(before);
243292
244 EXPECT_EQ(model->GetClosestIcon(fourth, before), third);293 EXPECT_EQ(model.GetClosestIcon(icon4, before), icon3);
245 EXPECT_TRUE(before);294 EXPECT_TRUE(before);
246}295}
247296
248TEST(TestLauncherModel, TestGetClosestIconWithOneIcon)297TEST_F(TestLauncherModel, GetClosestIconWithOneIcon)
249{298{
250 LauncherModel::Ptr model(new LauncherModel());299 model.AddIcon(icon1);
251 AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
252
253 model->AddIcon(first);
254300
255 bool before;301 bool before;
256 EXPECT_EQ(model->GetClosestIcon(first, before), nullptr);302 EXPECT_EQ(model.GetClosestIcon(icon1, before), nullptr);
257 EXPECT_TRUE(before);303 EXPECT_TRUE(before);
258}304}
259305
306TEST_F(TestLauncherModel, IconIndex)
307{
308 model.AddIcon(icon1);
309 model.AddIcon(icon2);
310 model.AddIcon(icon3);
311 model.AddIcon(icon4);
312
313 EXPECT_EQ(model.IconIndex(icon1), 0);
314 EXPECT_EQ(model.IconIndex(icon2), 1);
315 EXPECT_EQ(model.IconIndex(icon3), 2);
316 EXPECT_EQ(model.IconIndex(icon4), 3);
317
318 AbstractLauncherIcon::Ptr icon5(new MockLauncherIcon());
319 EXPECT_EQ(model.IconIndex(icon5), -1);
320}
321
322TEST_F(TestLauncherModel, IconHasSister)
323{
324 model.AddIcon(icon1);
325 EXPECT_FALSE(model.IconHasSister(icon1));
326
327 model.AddIcon(icon2);
328 model.AddIcon(icon3);
329 model.AddIcon(icon4);
330
331 EXPECT_TRUE(model.IconHasSister(icon1));
332 EXPECT_TRUE(model.IconHasSister(icon2));
333 EXPECT_TRUE(model.IconHasSister(icon3));
334 EXPECT_TRUE(model.IconHasSister(icon4));
335
336 EXPECT_FALSE(AbstractLauncherIcon::Ptr());
337}
338
260}339}