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