Merge lp:~xavi-garcia-mena/gmenuharness/ends-with-mode into lp:gmenuharness

Proposed by Xavi Garcia
Status: Merged
Approved by: Pete Woods
Approved revision: 12
Merged at revision: 12
Proposed branch: lp:~xavi-garcia-mena/gmenuharness/ends-with-mode
Merge into: lp:gmenuharness
Diff against target: 56 lines (+28/-1)
2 files modified
include/unity/gmenuharness/MenuItemMatcher.h (+2/-1)
src/MenuItemMatcher.cpp (+26/-0)
To merge this branch: bzr merge lp:~xavi-garcia-mena/gmenuharness/ends-with-mode
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
Review via email: mp+270027@code.launchpad.net

Commit message

I've added a ends_with Mode, so we can match the last N items.

Description of the change

I've added a ends_with Mode, so we can match the last N items.
In the case of the sound indicator it starts with something fixed, then adds the players items (which depend on the players the user have installed) and finally it adds a Sounds Settings section at the very end.

To post a comment you must log in.
Revision history for this message
Pete Woods (pete-woods) :
review: Approve
Revision history for this message
Pete Woods (pete-woods) :
review: Needs Information
11. By Xavi Garcia

Fix issue with index not being incremented

12. By Xavi Garcia

Added limit check for j index at endsWith

Revision history for this message
Pete Woods (pete-woods) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/unity/gmenuharness/MenuItemMatcher.h'
2--- include/unity/gmenuharness/MenuItemMatcher.h 2015-09-01 09:52:39 +0000
3+++ include/unity/gmenuharness/MenuItemMatcher.h 2015-09-03 12:26:02 +0000
4@@ -38,7 +38,8 @@
5 enum class Mode
6 {
7 all,
8- starts_with
9+ starts_with,
10+ ends_with
11 };
12
13 enum class Type
14
15=== modified file 'src/MenuItemMatcher.cpp'
16--- src/MenuItemMatcher.cpp 2015-09-01 12:52:38 +0000
17+++ src/MenuItemMatcher.cpp 2015-09-03 12:26:02 +0000
18@@ -147,6 +147,29 @@
19 }
20 }
21
22+ void endsWith(MatchResult& matchResult, const vector<unsigned int>& location,
23+ const shared_ptr<GMenuModel>& menu,
24+ map<string, shared_ptr<GActionGroup>>& actions)
25+ {
26+ int count = g_menu_model_get_n_items(menu.get());
27+ if (m_items.size() > (unsigned int) count)
28+ {
29+ matchResult.failure(
30+ location,
31+ "Expected at least " + to_string(m_items.size())
32+ + " children, but found " + to_string(count));
33+ return;
34+ }
35+
36+ // match the last N items
37+ size_t j;
38+ for (size_t i = count - m_items.size(), j = 0; i < count && j < m_items.size(); ++i, ++j)
39+ {
40+ const auto& matcher = m_items.at(j);
41+ matcher.match(matchResult, location, menu, actions, i);
42+ }
43+ }
44+
45 Type m_type = Type::plain;
46
47 Mode m_mode = Mode::all;
48@@ -758,6 +781,9 @@
49 case Mode::starts_with:
50 p->startsWith(childMatchResult, location, link, actions);
51 break;
52+ case Mode::ends_with:
53+ p->endsWith(childMatchResult, location, link, actions);
54+ break;
55 }
56 }
57

Subscribers

People subscribed via source and target branches