81bfff9303ee59a666afca7010e543d9b0e1335b
[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.AccessoryArgs Api Tests")]
32     public class NotificationEventArgsAccessoryArgsTests
33     {
34         private static NotificationEventListener.AccessoryOption _soundoption;
35         private static string _soundpath;
36         private static bool _isvibration = false;
37         private static NotificationEventListener.AccessoryOption _ledoption;
38         private static int _ledonms;
39         private static int _ledoffms;
40         private static Color _ledcolor;
41
42         [SetUp]
43         public static void Init()
44         {
45             LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for each TEST");
46         }
47
48         [TearDown]
49         public static void Destroy()
50         {
51             LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for each TEST");
52         }
53
54         private static void ChangedEventForSoundOption(object sender, NotificationEventArgs args)
55         {
56             _soundoption = args.Accessory.SoundOption;
57         }
58
59         private static void ChangedEventForSoundPath(object sender, NotificationEventArgs args)
60         {
61             _soundpath = args.Accessory.SoundPath;
62         }
63
64         private static void ChangedEventForCanVibrate(object sender, NotificationEventArgs args)
65         {
66             _isvibration = args.Accessory.CanVibrate;
67         }
68
69         private static void ChangedEventForLedOption(object sender, NotificationEventArgs args)
70         {
71             _ledoption = args.Accessory.LedOption;
72         }
73
74         private static void ChangedEventForLedOnMs(object sender, NotificationEventArgs args)
75         {
76             _ledonms = args.Accessory.LedOnMillisecond;
77         }
78
79         private static void ChangedEventForLedOffMs(object sender, NotificationEventArgs args)
80         {
81             _ledoffms = args.Accessory.LedOffMillisecond;
82         }
83
84         private static void ChangedEventForLedColor(object sender, NotificationEventArgs args)
85         {
86             _ledcolor = args.Accessory.LedColor;
87         }
88
89         [Test]
90         [Category("P1")]
91         [Description("AccessoryArgs constructor")]
92         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.AccessoryArgs C")]
93         [Property("SPEC_URL", "-")]
94         [Property("CRITERIA", "CONSTR")]
95         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
96         public static void AccessoryArgs_INIT()
97         {
98             NotificationEventArgs.AccessoryArgs accessoryArgs = new NotificationEventArgs.AccessoryArgs();
99             Assert.IsInstanceOf<NotificationEventArgs.AccessoryArgs>(accessoryArgs, "AccessoryArgs object is not of correct instance");
100         }
101
102         [Test]
103         [Category("P1")]
104         [Description("Check whether SoundOption returns expected value or not")]
105         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.SoundOption A")]
106         [Property("SPEC_URL", "-")]
107         [Property("CRITERIA", "PRO,PRE")]
108         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
109         public static async Task SoundOption_GET_ENUM_OFF()
110         {
111             try
112             {
113                 NotificationListenerManager.Added += ChangedEventForSoundOption;
114
115                 Notification noti = new Notification
116                 {
117                     Title = "Notification"
118                 };
119
120                 Notification.AccessorySet accessory = new Notification.AccessorySet();
121                 accessory.SoundOption = Notifications.AccessoryOption.Off;
122                 accessory.SoundPath = "Test";
123
124                 noti.Accessory = accessory;
125
126                 NotificationManager.Post(noti);
127                 await Task.Delay(1000);
128
129                 Assert.AreEqual((int)_soundoption, (int)Notifications.AccessoryOption.Off, "the set value and the get value should be equal");
130
131                 NotificationManager.Delete(noti);
132
133                 NotificationListenerManager.Added -= ChangedEventForSoundOption;
134             }
135             catch (Exception e)
136             {
137                 Assert.True(false, e.Message);
138             }
139         }
140
141         [Test]
142         [Category("P1")]
143         [Description("Check whether SoundOption returns expected value or not")]
144         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.SoundOption A")]
145         [Property("SPEC_URL", "-")]
146         [Property("CRITERIA", "PRO,PRE")]
147         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
148         public static async Task SoundOption_GET_ENUM_ON()
149         {
150             try
151             {
152                 NotificationListenerManager.Added += ChangedEventForSoundOption;
153
154                 Notification noti = new Notification
155                 {
156                     Title = "Notification"
157                 };
158
159                 Notification.AccessorySet accessory = new Notification.AccessorySet();
160                 accessory.SoundOption = Notifications.AccessoryOption.On;
161                 accessory.SoundPath = "Test";
162
163                 noti.Accessory = accessory;
164
165                 NotificationManager.Post(noti);
166                 await Task.Delay(1000);
167
168                 Assert.AreEqual((int)_soundoption, (int)Notifications.AccessoryOption.On, "the set value and the get value should be equal");
169
170                 NotificationManager.Delete(noti);
171
172                 NotificationListenerManager.Added -= ChangedEventForSoundOption;
173             }
174             catch (Exception e)
175             {
176                 Assert.True(false, e.Message);
177             }
178         }
179
180         [Test]
181         [Category("P1")]
182         [Description("Check whether SoundOption returns expected value or not")]
183         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.SoundOption A")]
184         [Property("SPEC_URL", "-")]
185         [Property("CRITERIA", "PRO,PRE")]
186         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
187         public static async Task SoundOption_GET_ENUM_CUSTOM()
188         {
189             try
190             {
191                 NotificationListenerManager.Added += ChangedEventForSoundOption;
192
193                 Notification noti = new Notification
194                 {
195                     Title = "Notification"
196                 };
197
198                 Notification.AccessorySet accessory = new Notification.AccessorySet();
199                 accessory.SoundOption = Notifications.AccessoryOption.Custom;
200                 accessory.SoundPath = "Test";
201
202                 noti.Accessory = accessory;
203
204                 NotificationManager.Post(noti);
205                 await Task.Delay(1000);
206
207                 Assert.AreEqual((int)_soundoption, (int)Notifications.AccessoryOption.Custom, "the set value and the get value should be equal");
208
209                 NotificationManager.Delete(noti);
210
211                 NotificationListenerManager.Added -= ChangedEventForSoundOption;
212             }
213             catch (Exception e)
214             {
215                 Assert.True(false, e.Message);
216             }
217         }
218
219         [Test]
220         [Category("P1")]
221         [Description("Check whether SoundPath returns expected value or not")]
222         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.SoundPath A")]
223         [Property("SPEC_URL", "-")]
224         [Property("CRITERIA", "PRO")]
225         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
226         public static async Task SoundPath_PROPERTY_READ_ONLY()
227         {
228             try
229             {
230                 NotificationListenerManager.Added += ChangedEventForSoundPath;
231
232                 Notification noti = new Notification
233                 {
234                     Title = "Notification"
235                 };
236
237                 Notification.AccessorySet accessory = new Notification.AccessorySet();
238                 accessory.SoundOption = Notifications.AccessoryOption.Custom;
239                 accessory.SoundPath = "Test";
240
241                 noti.Accessory = accessory;
242
243                 NotificationManager.Post(noti);
244                 await Task.Delay(1000);
245
246                 Assert.AreEqual(_soundpath, "Test", "the set value and the get value should be equal");
247
248                 NotificationManager.Delete(noti);
249
250                 NotificationListenerManager.Added -= ChangedEventForSoundPath;
251             }
252             catch (Exception e)
253             {
254                 Assert.True(false, e.Message);
255             }
256         }
257
258         [Test]
259         [Category("P1")]
260         [Description("Check whether CanVibrate returns expected value or not")]
261         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.CanVibrate A")]
262         [Property("SPEC_URL", "-")]
263         [Property("CRITERIA", "PRO")]
264         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
265         public static async Task CanVibrate_PROPERTY_READ_ONLY()
266         {
267             try
268             {
269                 NotificationListenerManager.Added += ChangedEventForCanVibrate;
270
271                 Notification noti = new Notification
272                 {
273                     Title = "Notification"
274                 };
275
276                 Notification.AccessorySet accessory = new Notification.AccessorySet();
277                 accessory.CanVibrate = true;
278
279                 noti.Accessory = accessory;
280
281                 NotificationManager.Post(noti);
282                 await Task.Delay(1000);
283
284                 Assert.AreEqual(_isvibration, true, "the set value and the get value should be equal");
285
286                 NotificationManager.Delete(noti);
287
288                 NotificationListenerManager.Added -= ChangedEventForCanVibrate;
289             }
290             catch (Exception e)
291             {
292                 Assert.True(false, e.Message);
293             }
294         }
295
296         [Test]
297         [Category("P1")]
298         [Description("Check whether LedOption returns expected value or not")]
299         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedOption A")]
300         [Property("SPEC_URL", "-")]
301         [Property("CRITERIA", "PRO,PRE")]
302         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
303         public static async Task LedOption_GET_ENUM_OFF()
304         {
305             try
306             {
307                 NotificationListenerManager.Added += ChangedEventForLedOption;
308
309                 Notification noti = new Notification
310                 {
311                     Title = "Notification"
312                 };
313
314                 Notification.AccessorySet accessory = new Notification.AccessorySet();
315                 accessory.LedOption = Notifications.AccessoryOption.Off;
316                 accessory.LedOnMillisecond = 100;
317                 accessory.LedOffMillisecond = 100;
318
319                 noti.Accessory = accessory;
320
321                 NotificationManager.Post(noti);
322                 await Task.Delay(1000);
323
324                 Assert.AreEqual((int)_ledoption, (int)Notifications.AccessoryOption.Off, "the set value and the get value should be equal");
325
326                 NotificationManager.Delete(noti);
327
328                 NotificationListenerManager.Added -= ChangedEventForLedOption;
329             }
330             catch (Exception e)
331             {
332                 Assert.True(false, e.Message);
333             }
334         }
335
336         [Test]
337         [Category("P1")]
338         [Description("Check whether LedOption returns expected value or not")]
339         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedOption A")]
340         [Property("SPEC_URL", "-")]
341         [Property("CRITERIA", "PRO,PRE")]
342         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
343         public static async Task LedOption_GET_ENUM_ON()
344         {
345             try
346             {
347                 NotificationListenerManager.Added += ChangedEventForLedOption;
348
349                 Notification noti = new Notification
350                 {
351                     Title = "Notification"
352                 };
353
354                 Notification.AccessorySet accessory = new Notification.AccessorySet();
355                 accessory.LedOption = Notifications.AccessoryOption.On;
356                 accessory.LedOnMillisecond = 100;
357                 accessory.LedOffMillisecond = 100;
358
359                 noti.Accessory = accessory;
360
361                 NotificationManager.Post(noti);
362                 await Task.Delay(1000);
363
364                 Assert.AreEqual((int)_ledoption, (int)Notifications.AccessoryOption.On, "the set value and the get value should be equal");
365
366                 NotificationManager.Delete(noti);
367
368                 NotificationListenerManager.Added -= ChangedEventForLedOption;
369             }
370             catch (Exception e)
371             {
372                 Assert.True(false, e.Message);
373             }
374         }
375
376         [Test]
377         [Category("P1")]
378         [Description("Check whether LedOption returns expected value or not")]
379         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedOption A")]
380         [Property("SPEC_URL", "-")]
381         [Property("CRITERIA", "PRO,PRE")]
382         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
383         public static async Task LedOption_GET_ENUM_CUSTOM()
384         {
385             try
386             {
387                 NotificationListenerManager.Added += ChangedEventForLedOption;
388
389                 Notification noti = new Notification
390                 {
391                     Title = "Notification"
392                 };
393
394                 Notification.AccessorySet accessory = new Notification.AccessorySet();
395                 accessory.LedOption = Notifications.AccessoryOption.Custom;
396                 accessory.LedOnMillisecond = 100;
397                 accessory.LedOffMillisecond = 100;
398
399                 noti.Accessory = accessory;
400
401                 NotificationManager.Post(noti);
402                 await Task.Delay(1000);
403
404                 Assert.AreEqual((int)_ledoption, (int)Notifications.AccessoryOption.Custom, "the set value and the get value should be equal");
405
406                 NotificationManager.Delete(noti);
407
408                 NotificationListenerManager.Added -= ChangedEventForLedOption;
409             }
410             catch (Exception e)
411             {
412                 Assert.True(false, e.Message);
413             }
414         }
415
416         [Test]
417         [Category("P1")]
418         [Description("Check whether LedOnMillisecond returns expected value or not")]
419         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedOnMillisecond A")]
420         [Property("SPEC_URL", "-")]
421         [Property("CRITERIA", "PRO")]
422         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
423         public static async Task LedOnMillisecond_PROPERTY_READ_ONLY()
424         {
425             try
426             {
427                 NotificationListenerManager.Added += ChangedEventForLedOnMs;
428
429                 Notification noti = new Notification
430                 {
431                     Title = "Notification"
432                 };
433
434                 Notification.AccessorySet accessory = new Notification.AccessorySet();
435                 accessory.LedOption = Notifications.AccessoryOption.On;
436                 accessory.LedOnMillisecond = 100;
437                 accessory.LedOffMillisecond = 100;
438
439                 noti.Accessory = accessory;
440
441                 NotificationManager.Post(noti);
442                 await Task.Delay(1000);
443
444                 Assert.AreEqual(_ledonms, 100, "the set value and the get value should be equal");
445
446                 NotificationManager.Delete(noti);
447
448                 NotificationListenerManager.Added -= ChangedEventForLedOnMs;
449             }
450             catch (Exception e)
451             {
452                 Assert.True(false, e.Message);
453             }
454         }
455
456         [Test]
457         [Category("P1")]
458         [Description("Check whether LedOffMillisecond returns expected value or not")]
459         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedOffMillisecond A")]
460         [Property("SPEC_URL", "-")]
461         [Property("CRITERIA", "PRO")]
462         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
463         public static async Task LedOffMillisecond_PROPERTY_READ_ONLY()
464         {
465             try
466             {
467                 NotificationListenerManager.Added += ChangedEventForLedOffMs;
468
469                 Notification noti = new Notification
470                 {
471                     Title = "Notification"
472                 };
473
474                 Notification.AccessorySet accessory = new Notification.AccessorySet();
475                 accessory.LedOption = Notifications.AccessoryOption.On;
476                 accessory.LedOnMillisecond = 100;
477                 accessory.LedOffMillisecond = 100;
478
479                 noti.Accessory = accessory;
480
481                 NotificationManager.Post(noti);
482                 await Task.Delay(1000);
483
484                 Assert.AreEqual(_ledoffms, 100, "the set value and the get value should be equal");
485
486                 NotificationManager.Delete(noti);
487
488                 NotificationListenerManager.Added -= ChangedEventForLedOffMs;
489             }
490             catch (Exception e)
491             {
492                 Assert.True(false, e.Message);
493             }
494         }
495
496         [Test]
497         [Category("P1")]
498         [Description("Check whether LedColor returns expected value or not")]
499         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.AccessoryArgs.LedColor A")]
500         [Property("SPEC_URL", "-")]
501         [Property("CRITERIA", "PRO")]
502         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
503         public static async Task LedColor_PROPERTY_READ_ONLY()
504         {
505             try
506             {
507                 NotificationListenerManager.Added += ChangedEventForLedColor;
508
509                 Notification noti = new Notification
510                 {
511                     Title = "Notification"
512                 };
513
514                 Notification.AccessorySet accessory = new Notification.AccessorySet();
515                 accessory.LedOption = Notifications.AccessoryOption.Custom;
516                 accessory.LedOnMillisecond = 100;
517                 accessory.LedOffMillisecond = 100;
518                 accessory.LedColor = Color.Green;
519
520                 noti.Accessory = accessory;
521
522                 NotificationManager.Post(noti);
523                 await Task.Delay(1000);
524
525                 Assert.AreEqual(_ledcolor, Color.Green, "the set value and the get value should be equal");
526
527                 NotificationManager.Delete(noti);
528
529                 NotificationListenerManager.Added -= ChangedEventForLedColor;
530             }
531             catch (Exception e)
532             {
533                 Assert.True(false, e.Message);
534             }
535         }
536     }
537 }