2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 using NUnit.Framework;
18 using NUnit.Framework.TUnit;
20 using System.Threading;
21 using System.Threading.Tasks;
25 using Tizen.Applications.Notifications;
26 using Tizen.Applications.NotificationEventListener;
28 namespace Tizen.Applications.NotificationEventListener.Tests
31 [Description("NotificationEventArgs.ButtonActionArgs Api Tests")]
32 public class NotificationEventArgsButtonActionArgsTests
34 private static NotificationEventListener.ButtonIndex _buttonindex;
35 private static string _buttonimagepath;
36 private static string _buttontext;
37 private static AppControl _buttonaction;
40 public static void Init()
42 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for each TEST");
46 public static void Destroy()
48 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for each TEST");
51 private static void ChangedEventForButtonIndex(object sender, NotificationEventArgs args)
53 NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
55 foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
57 _buttonindex = btn.Index;
61 private static void ChangedEventForButtonText(object sender, NotificationEventArgs args)
63 NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
65 foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
67 _buttontext = btn.Text;
71 private static void ChangedEventForButtonImagePath(object sender, NotificationEventArgs args)
73 NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
75 foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
77 _buttonimagepath = btn.ImagePath;
81 private static void ChangedEventForButtonAction(object sender, NotificationEventArgs args)
83 NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
85 foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
87 _buttonaction = btn.Action;
93 [Description("ButtonActionArgs constructor")]
94 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.ButtonActionArgs C")]
95 [Property("SPEC_URL", "-")]
96 [Property("CRITERIA", "CONSTR")]
97 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
98 public static void ButtonActionArgs_INIT()
100 NotificationEventArgs.ButtonActionArgs button = new NotificationEventArgs.ButtonActionArgs();
101 Assert.IsInstanceOf<NotificationEventArgs.ButtonActionArgs>(button, "ButtonActionArgs object is not of correct instance");
106 [Description("Check whether Index of Button returns expected value or not")]
107 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.Index A")]
108 [Property("SPEC_URL", "-")]
109 [Property("CRITERIA", "PRO,PRE")]
110 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
111 public static async Task Index_GET_ENUM_FIRST()
115 NotificationListenerManager.Added += ChangedEventForButtonIndex;
117 Notification noti = new Notification
119 Title = "Notification"
122 Notification.ActiveStyle style = new Notification.ActiveStyle();
123 style.IsAutoRemove = false;
124 style.BackgroundImage = "test";
126 Notification.ButtonAction button = new Notification.ButtonAction();
127 button.Index = Notifications.ButtonIndex.First;
128 button.Text = "Reply";
129 button.ImagePath = "test";
131 AppControl appcontrol = new AppControl();
132 appcontrol.ApplicationId = "ButtonTest";
134 button.Action = appcontrol;
136 style.AddButtonAction(button);
138 noti.AddStyle(style);
140 NotificationManager.Post(noti);
141 await Task.Delay(1000);
143 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.First, "the set value and the get value should be equal");
145 NotificationManager.Delete(noti);
147 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
151 Assert.True(false, e.Message);
157 [Description("Check whether Index of Button returns expected value or not")]
158 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.Index A")]
159 [Property("SPEC_URL", "-")]
160 [Property("CRITERIA", "PRO,PRE")]
161 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
162 public static async Task Index_GET_ENUM_SECOND()
166 NotificationListenerManager.Added += ChangedEventForButtonIndex;
168 Notification noti = new Notification
170 Title = "Notification"
173 Notification.ActiveStyle style = new Notification.ActiveStyle();
174 style.IsAutoRemove = false;
175 style.BackgroundImage = "test";
177 Notification.ButtonAction button = new Notification.ButtonAction();
178 button.Index = Notifications.ButtonIndex.Second;
179 button.Text = "Reply";
180 button.ImagePath = "test";
182 AppControl appcontrol = new AppControl();
183 appcontrol.ApplicationId = "ButtonTest";
185 button.Action = appcontrol;
187 style.AddButtonAction(button);
189 noti.AddStyle(style);
191 NotificationManager.Post(noti);
192 await Task.Delay(1000);
194 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.Second, "the set value and the get value should be equal");
196 NotificationManager.Delete(noti);
198 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
202 Assert.True(false, e.Message);
210 [Description("Check whether Index of Button returns expected value or not")]
211 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.Index A")]
212 [Property("SPEC_URL", "-")]
213 [Property("CRITERIA", "PRO,PRE")]
214 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
215 public static async Task Index_GET_ENUM_THIRD()
219 NotificationListenerManager.Added += ChangedEventForButtonIndex;
221 Notification noti = new Notification
223 Title = "Notification"
226 Notification.ActiveStyle style = new Notification.ActiveStyle();
227 style.IsAutoRemove = false;
228 style.BackgroundImage = "test";
230 Notification.ButtonAction button = new Notification.ButtonAction();
231 button.Index = Notifications.ButtonIndex.Third;
232 button.Text = "Reply";
233 button.ImagePath = "test";
235 AppControl appcontrol = new AppControl();
236 appcontrol.ApplicationId = "ButtonTest";
238 button.Action = appcontrol;
240 style.AddButtonAction(button);
242 noti.AddStyle(style);
244 NotificationManager.Post(noti);
245 await Task.Delay(1000);
247 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.Third, "the set value and the get value should be equal");
249 NotificationManager.Delete(noti);
251 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
255 Assert.True(false, e.Message);
261 [Description("Check whether Text of Button returns expected value or not")]
262 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.Text A")]
263 [Property("SPEC_URL", "-")]
264 [Property("CRITERIA", "PRO")]
265 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
266 public static async Task Text_PROPERTY_READ_ONLY()
270 NotificationListenerManager.Added += ChangedEventForButtonText;
272 Notification noti = new Notification
274 Title = "Notification"
277 Notification.ActiveStyle style = new Notification.ActiveStyle();
278 style.IsAutoRemove = false;
279 style.BackgroundImage = "test";
281 Notification.ButtonAction button = new Notification.ButtonAction();
282 button.Index = Notifications.ButtonIndex.First;
283 button.Text = "Reply";
284 button.ImagePath = "test";
286 AppControl appcontrol = new AppControl();
287 appcontrol.ApplicationId = "ButtonTest";
289 button.Action = appcontrol;
291 style.AddButtonAction(button);
293 noti.AddStyle(style);
295 NotificationManager.Post(noti);
296 await Task.Delay(1000);
298 Assert.AreEqual(_buttontext, "Reply", "the set value and the get value should be equal");
300 NotificationManager.Delete(noti);
302 NotificationListenerManager.Added -= ChangedEventForButtonText;
306 Assert.True(false, e.Message);
312 [Description("Check whether ImagePath of Button returns expected value or not")]
313 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.ImagePath A")]
314 [Property("SPEC_URL", "-")]
315 [Property("CRITERIA", "PRO")]
316 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
317 public static async Task ImagePath_PROPERTY_READ_ONLY()
321 NotificationListenerManager.Added += ChangedEventForButtonImagePath;
323 Notification noti = new Notification
325 Title = "Notification"
328 Notification.ActiveStyle style = new Notification.ActiveStyle();
329 style.IsAutoRemove = false;
330 style.BackgroundImage = "test";
332 Notification.ButtonAction button = new Notification.ButtonAction();
333 button.Index = Notifications.ButtonIndex.First;
334 button.Text = "Reply";
335 button.ImagePath = "test";
337 AppControl appcontrol = new AppControl();
338 appcontrol.ApplicationId = "ButtonTest";
340 button.Action = appcontrol;
342 style.AddButtonAction(button);
344 noti.AddStyle(style);
346 NotificationManager.Post(noti);
347 await Task.Delay(1000);
349 Assert.AreEqual(_buttonimagepath, "test", "the set value and the get value should be equal");
351 NotificationManager.Delete(noti);
353 NotificationListenerManager.Added -= ChangedEventForButtonImagePath;
357 Assert.True(false, e.Message);
363 [Description("Check whether Action of Button returns expected value or not")]
364 [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ButtonActionArgs.Action A")]
365 [Property("SPEC_URL", "-")]
366 [Property("CRITERIA", "PRO")]
367 [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
368 public static async Task Action_PROPERTY_READ_ONLY()
372 NotificationListenerManager.Added += ChangedEventForButtonAction;
374 AppControl appcontrol = new AppControl();
375 appcontrol.ApplicationId = "ButtonTest";
377 Notification.ButtonAction button = new Notification.ButtonAction();
378 button.Index = Notifications.ButtonIndex.First;
379 button.Text = "Reply";
380 button.ImagePath = "test";
381 button.Action = appcontrol;
383 Notification.ActiveStyle style = new Notification.ActiveStyle();
384 style.IsAutoRemove = false;
385 style.BackgroundImage = "test";
386 style.AddButtonAction(button);
388 Notification noti = new Notification();
389 noti.Title = "Notification";
390 noti.AddStyle(style);
392 NotificationManager.Post(noti);
393 await Task.Delay(1000);
395 Assert.AreEqual(_buttonaction.ApplicationId, "ButtonTest", "the set value and the get value should be equal");
397 NotificationManager.Delete(noti);
399 NotificationListenerManager.Added -= ChangedEventForButtonAction;
403 Assert.True(false, e.Message);