cf6f41e29381745977fcd11f9f955a36bf0350e5
[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.ReplyActionArgs Api Tests")]
32     public class NotificationEventArgsReplyActionArgsTests
33     {
34         private static int _replymax;
35         private static string _placeholdertext;
36         private static NotificationEventListener.ButtonIndex _parentIndex;
37         private static string _buttontext;
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 ChangedEventForParentIndex(object sender, NotificationEventArgs args)
52         {
53             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
54             NotificationEventArgs.ReplyActionArgs action = style.Reply;
55             _parentIndex = action.ParentIndex;
56         }
57
58         private static void ChangedEventForPlaceHolderText(object sender, NotificationEventArgs args)
59         {
60             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
61             NotificationEventArgs.ReplyActionArgs action = style.Reply;
62             _placeholdertext = action.PlaceHolderText;
63         }
64
65         private static void ChangedEventForReplyMax(object sender, NotificationEventArgs args)
66         {
67             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
68             NotificationEventArgs.ReplyActionArgs action = style.Reply;
69             _replymax = action.ReplyMax;
70         }
71
72         private static void ChangedEventForButton(object sender, NotificationEventArgs args)
73         {
74             NotificationEventArgs.ActiveStyleArgs style = args.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
75             NotificationEventArgs.ReplyActionArgs action = style.Reply;
76             NotificationEventArgs.ButtonActionArgs btn = action.Button;
77             _buttontext = btn.Text;
78
79         }
80
81         [Test]
82         [Category("P1")]
83         [Description("ReplyActionArgs constructor")]
84         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.ReplyActionArgs C")]
85         [Property("SPEC_URL", "-")]
86         [Property("CRITERIA", "CONSTR")]
87         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
88         public static void ReplyActionArgs_INIT()
89         {
90             NotificationEventArgs.ReplyActionArgs reply = new NotificationEventArgs.ReplyActionArgs();
91             Assert.IsInstanceOf<NotificationEventArgs.ReplyActionArgs>(reply, "ReplyActionArgs object is not of correct instance");
92         }
93
94         [Test]
95         [Category("P1")]
96         [Description("Check whether property ParentIndex returns expected value or not")]
97         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.ParentIndex A")]
98         [Property("SPEC_URL", "-")]
99         [Property("CRITERIA", "PRO,PRE")]
100         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
101         public static async Task ParentIndex_GET_ENUM_FIRST()
102         {
103             try
104             {
105                 NotificationListenerManager.Added += ChangedEventForParentIndex;
106
107                 AppControl appcontrol = new AppControl();
108                 appcontrol.ApplicationId = "ButtonTest";
109
110                 Notification.ButtonAction button = new Notification.ButtonAction();
111                 button.Index = Notifications.ButtonIndex.First;
112                 button.Text = "Reply";
113                 button.ImagePath = "test";
114                 button.Action = appcontrol;
115
116                 Notification.ReplyAction action = new Notification.ReplyAction();
117                 action.ParentIndex = Notifications.ButtonIndex.First;
118                 action.ReplyMax = 160;
119                 action.PlaceHolderText = "Input";
120                 action.Button = button;
121
122                 Notification.ActiveStyle style = new Notification.ActiveStyle();
123                 style.IsAutoRemove = false;
124                 style.BackgroundImage = "test";
125                 style.ReplyAction = action;
126
127                 Notification noti = new Notification();
128                 noti.Title = "Notification";
129                 noti.AddStyle(style);
130
131                 NotificationManager.Post(noti);
132                 await Task.Delay(1000);
133
134                 Assert.AreEqual((int)_parentIndex, (int)Notifications.ButtonIndex.First, "the set value and the get value should be equal");
135
136                 NotificationManager.Delete(noti);
137
138                 NotificationListenerManager.Added -= ChangedEventForParentIndex;
139             }
140             catch (Exception e)
141             {
142                 Assert.True(false, e.Message);
143             }
144         }
145
146         [Test]
147         [Category("P1")]
148         [Description("Check whether property ParentIndex returns expected value or not")]
149         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.ParentIndex A")]
150         [Property("SPEC_URL", "-")]
151         [Property("CRITERIA", "PRO,PRE")]
152         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
153         public static async Task ParentIndex_GET_ENUM_SECOND()
154         {
155             try
156             {
157                 NotificationListenerManager.Added += ChangedEventForParentIndex;
158
159                 AppControl appcontrol = new AppControl();
160                 appcontrol.ApplicationId = "ButtonTest";
161
162                 Notification.ButtonAction button = new Notification.ButtonAction();
163                 button.Index = Notifications.ButtonIndex.Second;
164                 button.Text = "Reply";
165                 button.ImagePath = "test";
166                 button.Action = appcontrol;
167
168                 Notification.ReplyAction action = new Notification.ReplyAction();
169                 action.ParentIndex = Notifications.ButtonIndex.Second;
170                 action.ReplyMax = 160;
171                 action.PlaceHolderText = "Input";
172                 action.Button = button;
173
174                 Notification.ActiveStyle style = new Notification.ActiveStyle();
175                 style.IsAutoRemove = false;
176                 style.BackgroundImage = "test";
177                 style.ReplyAction = action;
178
179                 Notification noti = new Notification();
180                 noti.Title = "Notification";
181                 noti.AddStyle(style);
182
183                 NotificationManager.Post(noti);
184                 await Task.Delay(1000);
185
186                 Assert.AreEqual((int)_parentIndex, (int)Notifications.ButtonIndex.Second, "the set value and the get value should be equal");
187
188                 NotificationManager.Delete(noti);
189
190                 NotificationListenerManager.Added -= ChangedEventForParentIndex;
191             }
192             catch (Exception e)
193             {
194                 Assert.True(false, e.Message);
195             }
196         }
197
198         [Test]
199         [Category("P1")]
200         [Description("Check whether property ParentIndex returns expected value or not")]
201         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.ParentIndex A")]
202         [Property("SPEC_URL", "-")]
203         [Property("CRITERIA", "PRO,PRE")]
204         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
205         public static async Task ParentIndex_GET_ENUM_THIRD()
206         {
207             try
208             {
209                 NotificationListenerManager.Added += ChangedEventForParentIndex;
210
211                 AppControl appcontrol = new AppControl();
212                 appcontrol.ApplicationId = "ButtonTest";
213
214                 Notification.ButtonAction button = new Notification.ButtonAction();
215                 button.Index = Notifications.ButtonIndex.Third;
216                 button.Text = "Reply";
217                 button.ImagePath = "test";
218                 button.Action = appcontrol;
219
220                 Notification.ReplyAction action = new Notification.ReplyAction();
221                 action.ParentIndex = Notifications.ButtonIndex.Third;
222                 action.ReplyMax = 160;
223                 action.PlaceHolderText = "Input";
224                 action.Button = button;
225
226                 Notification.ActiveStyle style = new Notification.ActiveStyle();
227                 style.IsAutoRemove = false;
228                 style.BackgroundImage = "test";
229                 style.ReplyAction = action;
230
231                 Notification noti = new Notification();
232                 noti.Title = "Notification";
233                 noti.AddStyle(style);
234
235                 NotificationManager.Post(noti);
236                 await Task.Delay(1000);
237
238                 Assert.AreEqual((int)_parentIndex, (int)Notifications.ButtonIndex.Third, "the set value and the get value should be equal");
239
240                 NotificationManager.Delete(noti);
241
242                 NotificationListenerManager.Added -= ChangedEventForParentIndex;
243             }
244             catch (Exception e)
245             {
246                 Assert.True(false, e.Message);
247             }
248         }
249
250         [Test]
251         [Category("P1")]
252         [Description("Check whether property PlaceHolderText returns expected value or not")]
253         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.PlaceHolderText A")]
254         [Property("SPEC_URL", "-")]
255         [Property("CRITERIA", "PRO")]
256         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
257         public static async Task PlaceHolderText_PROPERTY_READ_ONLY()
258         {
259             try
260             {
261                 NotificationListenerManager.Added += ChangedEventForPlaceHolderText;
262
263                 AppControl appcontrol = new AppControl();
264                 appcontrol.ApplicationId = "Replytest";
265
266                 Notification.ButtonAction button = new Notification.ButtonAction();
267                 button.Index = Notifications.ButtonIndex.First;
268                 button.Text = "Reply";
269                 button.ImagePath = "test";
270                 button.Action = appcontrol;
271
272                 Notification.ReplyAction action = new Notification.ReplyAction();
273                 action.ParentIndex = Notifications.ButtonIndex.First;
274                 action.ReplyMax = 160;
275                 action.PlaceHolderText = "Input";
276                 action.Button = button;
277
278                 Notification.ActiveStyle style = new Notification.ActiveStyle();
279                 style.IsAutoRemove = false;
280                 style.BackgroundImage = "test";
281                 style.ReplyAction = action;
282
283                 Notification noti = new Notification();
284                 noti.Title = "Notification";
285                 noti.AddStyle(style);
286
287                 NotificationManager.Post(noti);
288                 await Task.Delay(1000);
289
290                 Assert.AreEqual(_placeholdertext, "Input", "the set value and the get value should be equal");
291
292                 NotificationManager.Delete(noti);
293
294                 NotificationListenerManager.Added -= ChangedEventForPlaceHolderText;
295             }
296             catch (Exception e)
297             {
298                 Assert.True(false, e.Message);
299             }
300         }
301
302         [Test]
303         [Category("P1")]
304         [Description("Check whether property ReplyMax returns expected value or not")]
305         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.ReplyMax A")]
306         [Property("SPEC_URL", "-")]
307         [Property("CRITERIA", "PRO")]
308         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
309         public static async Task ReplyMax_PROPERTY_READ_ONLY()
310         {
311             try
312             {
313                 NotificationListenerManager.Added += ChangedEventForReplyMax;
314
315                 AppControl appcontrol = new AppControl();
316                 appcontrol.ApplicationId = "ButtonTest";
317
318                 Notification.ButtonAction button = new Notification.ButtonAction();
319                 button.Index = Notifications.ButtonIndex.First;
320                 button.Text = "Reply";
321                 button.ImagePath = "test";
322                 button.Action = appcontrol;
323
324                 Notification.ReplyAction action = new Notification.ReplyAction();
325                 action.ParentIndex = Notifications.ButtonIndex.First;
326                 action.ReplyMax = 160;
327                 action.PlaceHolderText = "Input";
328                 action.Button = button;
329
330                 Notification.ActiveStyle style = new Notification.ActiveStyle();
331                 style.IsAutoRemove = false;
332                 style.BackgroundImage = "test";
333                 style.ReplyAction = action;
334
335                 Notification noti = new Notification();
336                 noti.Title = "Notification";
337                 noti.AddStyle(style);
338
339                 NotificationManager.Post(noti);
340                 await Task.Delay(1000);
341
342                 Assert.AreEqual(_replymax, 160, "the set value and the get value should be equal");
343
344                 NotificationManager.Delete(noti);
345
346                 NotificationListenerManager.Added -= ChangedEventForReplyMax;
347             }
348             catch (Exception e)
349             {
350                 Assert.True(false, e.Message);
351             }
352         }
353
354         [Test]
355         [Category("P1")]
356         [Description("Check whether Button returns expected value or not")]
357         [Property("SPEC", "Tizen.Applications.NotificationEventListener.NotificationEventArgs.ReplyActionArgs.Button A")]
358         [Property("SPEC_URL", "-")]
359         [Property("CRITERIA", "PRO")]
360         [Property("AUTHOR", "MyungKi Lee, mk5004.lee@samsung.com")]
361         public static async Task Button_PROPERTY_READ_ONLY()
362         {
363             try
364             {
365                 NotificationListenerManager.Added += ChangedEventForButton;
366
367                 AppControl appcontrol = new AppControl();
368                 appcontrol.ApplicationId = "ButtonTest";
369
370                 Notification.ButtonAction button = new Notification.ButtonAction();
371                 button.Index = Notifications.ButtonIndex.First;
372                 button.Text = "Reply";
373                 button.ImagePath = "test";
374                 button.Action = appcontrol;
375
376                 Notification.ReplyAction action = new Notification.ReplyAction();
377                 action.ParentIndex = Notifications.ButtonIndex.First;
378                 action.ReplyMax = 160;
379                 action.PlaceHolderText = "Input";
380                 action.Button = button;
381
382                 Notification.ActiveStyle style = new Notification.ActiveStyle();
383                 style.IsAutoRemove = false;
384                 style.BackgroundImage = "test";
385                 style.ReplyAction = action;
386
387                 Notification noti = new Notification();
388                 noti.Title = "Notification";
389                 noti.AddStyle(style);
390
391                 NotificationManager.Post(noti);
392                 await Task.Delay(1000);
393
394                 Assert.AreEqual(_buttontext, "Reply", "the set value and the get value should be equal");
395
396                 NotificationManager.Delete(noti);
397
398                 NotificationListenerManager.Added -= ChangedEventForButton;
399             }
400             catch (Exception e)
401             {
402                 Assert.True(false, e.Message);
403             }
404         }
405     }
406 }