Merge lp:~unity-team/unity/unity.panel-indicator-test into lp:unity

Proposed by Jay Taoko
Status: Merged
Merged at revision: 308
Proposed branch: lp:~unity-team/unity/unity.panel-indicator-test
Merge into: lp:unity
Diff against target: 224 lines (+181/-0)
4 files modified
tests/unit/Makefile.am (+1/-0)
tests/unit/test-panel-indicator-object-view.vala (+149/-0)
tests/unit/test-unit.vala (+4/-0)
unity-private/panel/panel-indicator-object-view.vala (+27/-0)
To merge this branch: bzr merge lp:~unity-team/unity/unity.panel-indicator-test
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+26811@code.launchpad.net

Description of the change

Test IndicatorObjectView. Create a fake indicator object and an entry to it.

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/unit/Makefile.am'
2--- tests/unit/Makefile.am 2010-06-03 17:13:55 +0000
3+++ tests/unit/Makefile.am 2010-06-04 14:22:25 +0000
4@@ -50,6 +50,7 @@
5 test_unit_SOURCES = \
6 test-launcher.vala \
7 test-panel-indicator-object-entry-view.vala \
8+ test-panel-indicator-object-view.vala \
9 test-places.vala \
10 test-unit.vala
11
12
13=== added file 'tests/unit/test-panel-indicator-object-view.vala'
14--- tests/unit/test-panel-indicator-object-view.vala 1970-01-01 00:00:00 +0000
15+++ tests/unit/test-panel-indicator-object-view.vala 2010-06-04 14:22:25 +0000
16@@ -0,0 +1,149 @@
17+/*
18+ * Copyright (C) 2009 Canonical Ltd
19+ *
20+ * This program is free software: you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License version 3 as
22+ * published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by Neil Jay Taoko <jay.taoko.patel@canonical.com>
33+ *
34+ */
35+using Unity;
36+using Unity.Testing;
37+using Unity.Panel.Indicators;
38+
39+namespace Unity.Tests.Unit
40+{
41+ public class FakeIndicatorObject: Indicator.Object
42+ {
43+ public Gee.ArrayList<Indicator.ObjectEntry> indicator_entry_array;
44+ public Gtk.Label _label;
45+ public Gtk.Image _image;
46+ public Gtk.Menu _menu;
47+
48+ public FakeIndicatorObject ()
49+ {
50+ Object();
51+ }
52+
53+ construct
54+ {
55+ START_FUNCTION ();
56+ indicator_entry_array = new Gee.ArrayList< unowned Indicator.ObjectEntry> ();
57+
58+ _label = new Gtk.Label ("Test Label");
59+ _image = new Gtk.Image.from_icon_name ("gtk-apply", Gtk.IconSize.MENU);
60+ _menu = new Gtk.Menu ();
61+ END_FUNCTION ();
62+ }
63+
64+ public void add_entry(Indicator.ObjectEntry entry)
65+ {
66+ int pos = indicator_entry_array.index_of (entry);
67+ if (pos != -1)
68+ return;
69+
70+ indicator_entry_array.add (entry);
71+ entry_added (entry);
72+ }
73+
74+ public void remove_entry(Indicator.ObjectEntry entry)
75+ {
76+ int pos = indicator_entry_array.index_of (entry);
77+ if (pos != -1)
78+ {
79+ indicator_entry_array.remove_at (pos);
80+ entry_removed (entry);
81+ }
82+ }
83+
84+ public override unowned Gtk.Label get_label ()
85+ {
86+ return this._label;
87+ }
88+
89+ public override unowned Gtk.Image get_image ()
90+ {
91+ return this._image;
92+ }
93+
94+ public override unowned Gtk.Menu get_menu ()
95+ {
96+ return this._menu;
97+ }
98+
99+/* public override unowned GLib.List get_entries ()
100+ {
101+
102+ }*/
103+ }
104+
105+ public class PanelIndicatorObjectViewSuite : Object
106+ {
107+ public const string DOMAIN = "/Unit/Panel/Indicator/ObjectView";
108+
109+ private Indicator.ObjectEntry entry;
110+ private Gtk.Menu menu;
111+ private Gtk.Label label;
112+ private Gtk.Image image;
113+
114+ public PanelIndicatorObjectViewSuite ()
115+ {
116+ Logging.init_fatal_handler ();
117+
118+ entry = new Indicator.ObjectEntry ();
119+
120+ menu = new Gtk.Menu ();
121+ entry.menu = menu;
122+
123+ label = new Gtk.Label ("Test Label");
124+ entry.label = label;
125+
126+ image = new Gtk.Image.from_icon_name ("gtk-apply", Gtk.IconSize.MENU);
127+ entry.image = image;
128+
129+ Test.add_data_func (DOMAIN + "/FakeIndicator", test_fake_indicator_object);
130+ Test.add_data_func (DOMAIN + "/FakeIndicatorAddEntry", test_indicator_add_entry);
131+ Test.add_data_func (DOMAIN + "/TestEntryView", test_indicator_enty_view);
132+ }
133+
134+ private void test_fake_indicator_object ()
135+ {
136+ var fakeobject = new FakeIndicatorObject ();
137+
138+ assert (fakeobject is FakeIndicatorObject);
139+ }
140+
141+ private void test_indicator_add_entry ()
142+ {
143+ var fakeobject = new FakeIndicatorObject ();
144+ var e = new IndicatorObjectView (fakeobject);
145+
146+ fakeobject.add_entry (entry);
147+
148+ assert (e.find_entry (entry));
149+ }
150+
151+ private void test_indicator_enty_view ()
152+ {
153+ var fakeobject = new FakeIndicatorObject ();
154+ var e = new IndicatorObjectView (fakeobject);
155+
156+ fakeobject.add_entry (entry);
157+ IndicatorObjectEntryView? entry_view = e.get_entry_view (entry);
158+
159+ assert (entry_view.entry == entry);
160+ assert (entry_view.entry.label == entry.label);
161+ assert (entry_view.entry.image == entry.image);
162+ assert (entry_view.entry.menu == entry.menu);
163+ }
164+ }
165+}
166
167=== modified file 'tests/unit/test-unit.vala'
168--- tests/unit/test-unit.vala 2010-06-03 17:13:55 +0000
169+++ tests/unit/test-unit.vala 2010-06-04 14:22:25 +0000
170@@ -25,6 +25,8 @@
171 public static int main (string[] args)
172 {
173 PanelIndicatorObjectEntryViewSuite panel_object_entry_view_suite;
174+ PanelIndicatorObjectViewSuite panel_object_view_suite;
175+
176 PlacesSuite places;
177 LauncherSuite launcher;
178
179@@ -33,6 +35,8 @@
180 Test.init (ref args);
181
182 panel_object_entry_view_suite = new PanelIndicatorObjectEntryViewSuite ();
183+ panel_object_view_suite = new PanelIndicatorObjectViewSuite ();
184+
185 launcher = new LauncherSuite ();
186 places = new PlacesSuite ();
187
188
189=== modified file 'unity-private/panel/panel-indicator-object-view.vala'
190--- unity-private/panel/panel-indicator-object-view.vala 2010-06-02 22:24:35 +0000
191+++ unity-private/panel/panel-indicator-object-view.vala 2010-06-04 14:22:25 +0000
192@@ -166,5 +166,32 @@
193 object_entry_view.show_menu ();
194 }
195 }
196+
197+ public bool find_entry (Indicator.ObjectEntry entry)
198+ {
199+ for (int i = 0; i < indicator_entry_array.size; i++)
200+ {
201+ IndicatorObjectEntryView object_entry_view = this.indicator_entry_array.get (i) as IndicatorObjectEntryView;
202+ if (object_entry_view.entry == entry)
203+ {
204+ return true;
205+ }
206+ }
207+ return false;
208+ }
209+
210+ public IndicatorObjectEntryView? get_entry_view (Indicator.ObjectEntry entry)
211+ {
212+ for (int i = 0; i < indicator_entry_array.size; i++)
213+ {
214+ IndicatorObjectEntryView object_entry_view = this.indicator_entry_array.get (i) as IndicatorObjectEntryView;
215+ if (object_entry_view.entry == entry)
216+ {
217+ return object_entry_view;
218+ }
219+ }
220+ return null;
221+ }
222+
223 }
224 }