814a4e7e79a9df87ce0735613db577fe16bff3ea
[test/tct/csharp/api.git] /
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16
17 using NUnit.Framework;
18 using NUnit.Framework.TUnit;
19 using System;
20 using System.Threading;
21 using System.Threading.Tasks;
22 using Tizen;
23 using Tizen.Common;
24
25 using Tizen.Applications.Notifications;
26 using Tizen.Applications.NotificationEventListener;
27
28 namespace Tizen.Applications.NotificationEventListener.Tests
29 {
30     [TestFixture]
31     [Description("NotificationEventArgs.ButtonActionArgs Api Tests")]
32     public class NotificationEventArgsButtonActionArgsTests
33     {
34         private static NotificationEventListener.ButtonIndex _buttonindex;
35         private static string _buttonimagepath;
36         private static string _buttontext;
37         private static AppControl _buttonaction;
38
39         [SetUp]
40         public static void Init()
41         {
42             LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for each TEST");
43         }
44
45         [TearDown]
46         public static void Destroy()
47         {
48             LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for each TEST");
49         }
50
51         private static void ChangedEventForButtonIndex(object sender, NotificationEventArgs args)
52         {
53             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
54
55             foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
56             {
57                 _buttonindex = btn.Index;
58             }
59         }
60
61         private static void ChangedEventForButtonText(object sender, NotificationEventArgs args)
62         {
63             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
64
65             foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
66             {
67                 _buttontext = btn.Text;
68             }
69         }
70
71         private static void ChangedEventForButtonImagePath(object sender, NotificationEventArgs args)
72         {
73             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
74
75             foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
76             {
77                 _buttonimagepath = btn.ImagePath;
78             }
79         }
80
81         private static void ChangedEventForButtonAction(object sender, NotificationEventArgs args)
82         {
83             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
84
85             foreach (NotificationEventArgs.ButtonActionArgs btn in style.Button)
86             {
87                 _buttonaction = btn.Action;
88             }
89         }
90
91         [Test]
92         [Category("P1")]
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()
99         {
100             NotificationEventArgs.ButtonActionArgs button = new NotificationEventArgs.ButtonActionArgs();
101             Assert.IsInstanceOf<NotificationEventArgs.ButtonActionArgs>(button, "ButtonActionArgs object is not of correct instance");
102         }
103
104         [Test]
105         [Category("P1")]
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()
112         {
113             try
114             {
115                 NotificationListenerManager.Added += ChangedEventForButtonIndex;
116
117                 Notification noti = new Notification
118                 {
119                     Title = "Notification"
120                 };
121
122                 Notification.ActiveStyle style = new Notification.ActiveStyle();
123                 style.IsAutoRemove = false;
124                 style.BackgroundImage = "test";
125
126                 Notification.ButtonAction button = new Notification.ButtonAction();
127                 button.Index = Notifications.ButtonIndex.First;
128                 button.Text = "Reply";
129                 button.ImagePath = "test";
130
131                 AppControl appcontrol = new AppControl();
132                 appcontrol.ApplicationId = "ButtonTest";
133
134                 button.Action = appcontrol;
135
136                 style.AddButtonAction(button);
137
138                 noti.AddStyle(style);
139
140                 NotificationManager.Post(noti);
141                 await Task.Delay(1000);
142
143                 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.First, "the set value and the get value should be equal");
144
145                 NotificationManager.Delete(noti);
146
147                 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
148             }
149             catch (Exception e)
150             {
151                 Assert.True(false, e.Message);
152             }
153         }
154
155         [Test]
156         [Category("P1")]
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()
163         {
164             try
165             {
166                 NotificationListenerManager.Added += ChangedEventForButtonIndex;
167
168                 Notification noti = new Notification
169                 {
170                     Title = "Notification"
171                 };
172
173                 Notification.ActiveStyle style = new Notification.ActiveStyle();
174                 style.IsAutoRemove = false;
175                 style.BackgroundImage = "test";
176
177                 Notification.ButtonAction button = new Notification.ButtonAction();
178                 button.Index = Notifications.ButtonIndex.Second;
179                 button.Text = "Reply";
180                 button.ImagePath = "test";
181
182                 AppControl appcontrol = new AppControl();
183                 appcontrol.ApplicationId = "ButtonTest";
184
185                 button.Action = appcontrol;
186
187                 style.AddButtonAction(button);
188
189                 noti.AddStyle(style);
190
191                 NotificationManager.Post(noti);
192                 await Task.Delay(1000);
193
194                 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.Second, "the set value and the get value should be equal");
195
196                 NotificationManager.Delete(noti);
197
198                 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
199             }
200             catch (Exception e)
201             {
202                 Assert.True(false, e.Message);
203             }
204         }
205
206
207
208         [Test]
209         [Category("P1")]
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()
216         {
217             try
218             {
219                 NotificationListenerManager.Added += ChangedEventForButtonIndex;
220
221                 Notification noti = new Notification
222                 {
223                     Title = "Notification"
224                 };
225
226                 Notification.ActiveStyle style = new Notification.ActiveStyle();
227                 style.IsAutoRemove = false;
228                 style.BackgroundImage = "test";
229
230                 Notification.ButtonAction button = new Notification.ButtonAction();
231                 button.Index = Notifications.ButtonIndex.Third;
232                 button.Text = "Reply";
233                 button.ImagePath = "test";
234
235                 AppControl appcontrol = new AppControl();
236                 appcontrol.ApplicationId = "ButtonTest";
237
238                 button.Action = appcontrol;
239
240                 style.AddButtonAction(button);
241
242                 noti.AddStyle(style);
243
244                 NotificationManager.Post(noti);
245                 await Task.Delay(1000);
246
247                 Assert.AreEqual((int)_buttonindex, (int)Notifications.ButtonIndex.Third, "the set value and the get value should be equal");
248
249                 NotificationManager.Delete(noti);
250
251                 NotificationListenerManager.Added -= ChangedEventForButtonIndex;
252             }
253             catch (Exception e)
254             {
255                 Assert.True(false, e.Message);
256             }
257         }
258
259         [Test]
260         [Category("P1")]
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()
267         {
268             try
269             {
270                 NotificationListenerManager.Added += ChangedEventForButtonText;
271
272                 Notification noti = new Notification
273                 {
274                     Title = "Notification"
275                 };
276
277                 Notification.ActiveStyle style = new Notification.ActiveStyle();
278                 style.IsAutoRemove = false;
279                 style.BackgroundImage = "test";
280
281                 Notification.ButtonAction button = new Notification.ButtonAction();
282                 button.Index = Notifications.ButtonIndex.First;
283                 button.Text = "Reply";
284                 button.ImagePath = "test";
285
286                 AppControl appcontrol = new AppControl();
287                 appcontrol.ApplicationId = "ButtonTest";
288
289                 button.Action = appcontrol;
290
291                 style.AddButtonAction(button);
292
293                 noti.AddStyle(style);
294
295                 NotificationManager.Post(noti);
296                 await Task.Delay(1000);
297
298                 Assert.AreEqual(_buttontext, "Reply", "the set value and the get value should be equal");
299
300                 NotificationManager.Delete(noti);
301
302                 NotificationListenerManager.Added -= ChangedEventForButtonText;
303             }
304             catch (Exception e)
305             {
306                 Assert.True(false, e.Message);
307             }
308         }
309
310         [Test]
311         [Category("P1")]
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()
318         {
319             try
320             {
321                 NotificationListenerManager.Added += ChangedEventForButtonImagePath;
322
323                 Notification noti = new Notification
324                 {
325                     Title = "Notification"
326                 };
327
328                 Notification.ActiveStyle style = new Notification.ActiveStyle();
329                 style.IsAutoRemove = false;
330                 style.BackgroundImage = "test";
331
332                 Notification.ButtonAction button = new Notification.ButtonAction();
333                 button.Index = Notifications.ButtonIndex.First;
334                 button.Text = "Reply";
335                 button.ImagePath = "test";
336
337                 AppControl appcontrol = new AppControl();
338                 appcontrol.ApplicationId = "ButtonTest";
339
340                 button.Action = appcontrol;
341
342                 style.AddButtonAction(button);
343
344                 noti.AddStyle(style);
345
346                 NotificationManager.Post(noti);
347                 await Task.Delay(1000);
348
349                 Assert.AreEqual(_buttonimagepath, "test", "the set value and the get value should be equal");
350
351                 NotificationManager.Delete(noti);
352
353                 NotificationListenerManager.Added -= ChangedEventForButtonImagePath;
354             }
355             catch (Exception e)
356             {
357                 Assert.True(false, e.Message);
358             }
359         }
360
361         [Test]
362         [Category("P1")]
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()
369         {
370             try
371             {
372                 NotificationListenerManager.Added += ChangedEventForButtonAction;
373
374                 AppControl appcontrol = new AppControl();
375                 appcontrol.ApplicationId = "ButtonTest";
376
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;
382
383                 Notification.ActiveStyle style = new Notification.ActiveStyle();
384                 style.IsAutoRemove = false;
385                 style.BackgroundImage = "test";
386                 style.AddButtonAction(button);
387
388                 Notification noti = new Notification();
389                 noti.Title = "Notification";
390                 noti.AddStyle(style);
391
392                 NotificationManager.Post(noti);
393                 await Task.Delay(1000);
394
395                 Assert.AreEqual(_buttonaction.ApplicationId, "ButtonTest", "the set value and the get value should be equal");
396
397                 NotificationManager.Delete(noti);
398
399                 NotificationListenerManager.Added -= ChangedEventForButtonAction;
400             }
401             catch (Exception e)
402             {
403                 Assert.True(false, e.Message);
404             }
405         }
406     }
407 }