c876c2a1628ae2cc051d31c556ff7a7cd4ef35da
[test/tct/csharp/api.git] /
1 using System;
2 using System.Runtime.InteropServices;
3 using Tizen.Applications;
4 using Tizen.NUI;
5 using Tizen.NUI.UIComponents;
6 using Tizen.NUI.BaseComponents;
7 using Tizen.NUI.Constants;
8 using Tizen;
9
10 namespace NUIApplicationsManualWearableTests
11 {
12     /// <summary>
13     /// A sample of NUIApplication
14     /// </summary>
15     class NUIApplicationsManualWearableTests : NUIApplication
16     {
17         public delegate void AddIdleTest();
18         public void OnButtonPressed()
19         {
20             Log.Fatal("TCT", "Call Exit()");
21             Exit();
22         }
23         protected override void OnPreCreate()
24         {
25             Log.Fatal("TCT", "[TestCase][OnPreCreate][NUIApplication] Pass");
26             base.OnPreCreate();
27         }
28         protected override void OnCreate()
29         {
30             base.OnCreate();\r
31 \r
32             PushButton pauseButton = new PushButton();
33             pauseButton.Size2D = new Size2D(120, 60);
34             pauseButton.Position2D = new Position2D(-150, -300);
35             pauseButton.Label = CreateTextVisual("Pause", Color.White);
36             pauseButton.Clicked += (obj, ee) =>
37             {
38                 OnPause();
39                 return false;
40             };
41             Window.Instance.GetDefaultLayer().Add(pauseButton);\r
42             
43             
44             PushButton resumeButton = new PushButton();
45             resumeButton.Size2D = new Size2D(120, 60);
46             resumeButton.Position2D = new Position2D(-30, -300);
47             resumeButton.Label = CreateTextVisual("Resume", Color.White);
48             resumeButton.Clicked += (obj, e) =>
49             {
50                 OnResume();
51                 return true;
52             };
53             Window.Instance.GetDefaultLayer().Add(resumeButton);
54
55             PushButton exitButton = new PushButton();
56             exitButton.Size2D = new Size2D(120, 60);
57             exitButton.Position2D = new Position2D(-150, -150);
58             exitButton.Label = CreateTextVisual("Exit", Color.White);
59
60             exitButton.Clicked += (obj, e) =>
61             {
62                 Exit();
63                 return true;
64             };
65             Window.Instance.GetDefaultLayer().Add(exitButton);
66
67             PushButton addIdleButton = new PushButton();
68             addIdleButton.Size2D = new Size2D(120, 60);
69             addIdleButton.Position2D = new Position2D(-30, -150);
70             addIdleButton.Label = CreateTextVisual("AddIdle", Color.White);
71             addIdleButton.Clicked += (obj, e) =>
72             {
73                 AddIdleTest addIdleTest = new AddIdleTest(MyDelegate);
74                 AddIdle(addIdleTest);
75                 return true;
76             };\r
77 \r
78             Window.Instance.GetDefaultLayer().Add(addIdleButton);
79
80             pauseButton.DownFocusableView = resumeButton;
81             resumeButton.UpFocusableView = pauseButton;
82             resumeButton.DownFocusableView = exitButton;
83             exitButton.UpFocusableView = resumeButton;
84             exitButton.DownFocusableView = addIdleButton;
85             addIdleButton.UpFocusableView = exitButton;
86
87
88             FocusManager.Instance.SetCurrentFocusView(pauseButton);
89             
90             
91             Log.Fatal("TCT", "[TestCase][OnCreate][NUIApplication] Pass");
92         }\r
93 \r
94         private PropertyMap CreateTextVisual(string text, Color color)
95         {
96             PropertyMap map = new PropertyMap();
97             map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text));
98             map.Add(TextVisualProperty.Text, new PropertyValue(text));
99             map.Add(TextVisualProperty.TextColor, new PropertyValue(color));
100             map.Add(TextVisualProperty.PointSize, new PropertyValue(6.0f));
101             map.Add(TextVisualProperty.HorizontalAlignment, new PropertyValue("CENTER"));
102             map.Add(TextVisualProperty.VerticalAlignment, new PropertyValue("BOTTOM"));
103             return map;
104         }
105         public static void MyDelegate()
106         {
107             Log.Fatal("TCT", "[TestCase][AddIdle][NUIApplication] Pass");
108         }
109
110         protected override void OnResume()
111         {
112             Log.Fatal("TCT", "[TestCase][OnResume][NUIApplication] Pass");
113             base.OnResume();
114         }
115
116         protected override void OnPause()
117         {
118             Log.Fatal("TCT", "[TestCase][OnPause][NUIApplication] Pass");
119             base.OnPause();
120         }
121
122         protected override void OnTerminate()
123         {
124             Log.Fatal("TCT", "NUIApplication::OnTerminate()");
125             Log.Fatal("TCT", "[TestCase][OnTerminate][NUIApplication] Pass");
126             base.OnTerminate();
127         }
128
129         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
130         {
131             Log.Fatal("TCT", "NUIApplication::OnAppControlReceived()");
132             if (e.ReceivedAppControl != null)
133             {
134                 Log.Fatal("TCT", "[TestCase][Test_Properties] ReceivedAppControl properties is not null");
135                 Log.Fatal("TCT", "[TestCase][Test_Properties] ReceivedAppControl Type: " + e.ReceivedAppControl.GetType());
136             }
137             Log.Fatal("TCT", "[TestCase][OnAppControlReceived][NUIApplication] Pass");
138
139             base.OnAppControlReceived(e);
140             ShowPropertiesInfo();
141         }
142
143         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
144         {
145             Log.Fatal("TCT", "NUIApplication::OnLocaleChanged()");
146             if (e.Locale != null)
147             {
148                 Log.Fatal("TCT", "[Test_Properties] Locale properties is not null");
149                 Log.Fatal("TCT", "[Test_Properties] Current value of Locale : " + e.Locale);
150                 Log.Fatal("TCT", "[Test_Properties] Locale type: " + e.Locale.GetType());
151             }
152
153             Log.Fatal("TCT", "[TestCase][OnLocaleChanged][NUIApplication] Pass");
154             base.OnLocaleChanged(e);
155         }
156
157         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
158         {
159             Log.Fatal("TCT", "NUIApplication::OnRegionFormatChanged()");
160             if (e != null)
161             {
162                 Log.Fatal("TCT", "[Test_Properties] Region properties is not null");
163                 Log.Fatal("TCT", "[Test_Properties] Current value of Region : " + e.Region);
164                 Log.Fatal("TCT", "[Test_Properties] Region type: " + e.Region.GetType());
165             }
166
167             Log.Fatal("TCT", "[TestCase][OnRegionFormatChanged][NUIApplication] Pass");
168             base.OnRegionFormatChanged(e);
169         }
170
171         protected override void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
172         {
173             Log.Fatal("TCT", "NUIApplication::OnDeviceOrientationChanged()");
174             if (e != null)
175             {
176                 Log.Fatal("TCT", "[Test_Properties] DeviceOrientation properties is not null");
177                 Log.Fatal("TCT", "[Test_Properties] Current value of DeviceOrientation : " + e.DeviceOrientation);
178                 Log.Fatal("TCT", "[Test_Properties] DeviceOrientation type: " + e.DeviceOrientation.GetType());
179             }
180
181             Log.Fatal("TCT", "[TestCase][OnDeviceOrientationChanged][NUIApplication] Pass");
182             base.OnDeviceOrientationChanged(e);
183         }
184
185         protected override void OnLowMemory(LowMemoryEventArgs e)
186         {
187             Log.Fatal("TCT", "NUIApplication::OnLowMemory()");
188             if (e.LowMemoryStatus != LowMemoryStatus.None)
189             {
190                 Log.Fatal("TCT", "[Test_Properties] LowMemoryStatus properties is not null");
191                 Log.Fatal("TCT", "[Test_Properties] Current value of LowMemoryStatus : " + e.LowMemoryStatus.ToString());
192                 Log.Fatal("TCT", "[Test_Properties] LowMemoryStatus type: " + e.LowMemoryStatus.GetType());
193             }
194             Log.Fatal("TCT", "[TestCase][OnLowMemory][NUIApplication] Pass");
195
196             base.OnLowMemory(e);
197         }
198
199         protected override void OnLowBattery(LowBatteryEventArgs e)
200         {
201             Log.Fatal("TCT", "NUIApplication::OnLowBattery()");
202             if (e.LowBatteryStatus != LowBatteryStatus.None)
203             {
204                 Log.Fatal("TCT", "[Test_Properties] LowBatteryStatus properties is not null");
205                 Log.Fatal("TCT", "[Test_Properties] Current value of LowBatteryStatus : " + e.LowBatteryStatus.ToString());
206                 Log.Fatal("TCT", "[Test_Properties] LowBatteryStatus type: " + e.LowBatteryStatus.GetType());
207             }
208
209             Log.Fatal("TCT", "[TestCase][OnLowBattery][NUIApplication] Pass");
210
211             base.OnLowBattery(e);
212         }
213
214         public override void Run(string[] args)
215         {
216             Created += Created_Event_Test;
217             AppControlReceived += AppControlReceived_Event_Test;
218             LocaleChanged += LocaleChanged_Event_Test;
219             LowMemory += LowMemory_Event_Test;
220             LowBattery += LowBattery_Event_Test;
221             Terminated += Terminated_Event_Test;
222             Paused += Paused_Event_Test;
223             Resumed += Resumed_Event_Test;
224             DeviceOrientationChanged += DeviceOrientationCHanged_Event_Test;
225             RegionFormatChanged += RegionFormatChanged_Event_Test;
226
227             Log.Fatal("TCT", "[TestCase][Run][NUIApplication] Pass");
228
229             base.Run(args);
230         }
231
232         private void Terminated_Event_Test(object sender, EventArgs e)
233         {
234             /*
235              * SCENARIO:
236              * Launch app
237              * -> If log show "NUIApplication::Terminated_Event_Test()" -> PASS
238              */
239             Log.Fatal("TCT", "NUIApplication::Terminated_Event_Test");
240             Log.Fatal("TCT", "[TestCase][Terminated_Event_Test][NUIApplication] Pass");
241         }
242
243         private void LocaleChanged_Event_Test(object sender, LocaleChangedEventArgs e)
244         {
245             /*
246              * SCENARIO:
247              * Launch app
248              * -> If log show "NUIApplication::LocaleChanged_Event_Test()" -> PASS
249              */
250             Log.Fatal("TCT", "NUIApplication::LocaleChanged_Event_Test");
251             Log.Fatal("TCT", "NUIApplication::LocaleChanged_Event_Test: new located - " + e.Locale);
252             Log.Fatal("TCT", "[TestCase][LocaleChanged_Event_Test][NUIApplication] Pass");
253         }
254
255         private void RegionFormatChanged_Event_Test(object sender, RegionFormatChangedEventArgs e)
256         {
257             Log.Fatal("TCT", "NUIApplication::RegionFormatChanged_Event_Test");
258             Log.Fatal("TCT", "NUIApplication::RegionFormatChanged_Event_Test: new region - " + e.Region);
259             Log.Fatal("TCT", "[TestCase][RegionFormatChanged_Event_Test][NUIApplication] Pass");
260         }
261
262         private void DeviceOrientationCHanged_Event_Test(object sender, DeviceOrientationEventArgs e)
263         {
264             Log.Fatal("TCT", "NUIApplication::DeviceOrientationCHanged_Event_Test");
265             Log.Fatal("TCT", "NUIApplication::DeviceOrientationCHanged_Event_Test: new located - " + e.DeviceOrientation);
266             Log.Fatal("TCT", "[TestCase][DeviceOrientationCHanged_Event_Test][NUIApplication] Pass");
267         }
268
269         private void LowMemory_Event_Test(object sender, LowMemoryEventArgs e)
270         {
271             /*
272              * SCENARIO:
273              * Launch app
274              * -> If log show "NUIApplication::LowMemory_Event_Test()" -> PASS
275              */
276             Log.Fatal("TCT", "NUIApplication::LowMemory_Event_Test");
277             if (e.LowMemoryStatus == LowMemoryStatus.None)
278             {
279                 Log.Fatal("TCT", "NUIApplication::LowMemory_Event_Test: LowMemoryStatus.None");
280             }
281             else if (e.LowMemoryStatus == LowMemoryStatus.Normal)
282             {
283                 Log.Fatal("TCT", "NUIApplication::LowMemory_Event_Test: LowMemoryStatus.Normal");
284             }
285             else if (e.LowMemoryStatus == LowMemoryStatus.SoftWarning)
286             {
287                 Log.Fatal("TCT", "NUIApplication::LowMemory_Event_Test: LowMemoryStatus.SoftWarning");
288             }
289             else if (e.LowMemoryStatus == LowMemoryStatus.HardWarning)
290             {
291                 Log.Fatal("TCT", "NUIApplication::LowMemory_Event_Test: LowMemoryStatus.HardWarning");
292             }
293             Log.Fatal("TCT", "[TestCase][LowMemory_Event_Test][NUIApplication] Pass");
294         }
295
296         private void LowBattery_Event_Test(object sender, LowBatteryEventArgs e)
297         {
298             Log.Fatal("TCT", "NUIApplication::LowBattery_Event_Test");
299
300             if (e.LowBatteryStatus == LowBatteryStatus.CriticalLow)
301             {
302                 Log.Fatal("TCT", "NUIApplication::LowBattery_Event_Test: LowMemoryStatus.CriticalLow");
303             }
304             Log.Fatal("TCT", "[TestCase][LowBattery_Event_Test][NUIApplication] Pass");
305         }
306
307         private void AppControlReceived_Event_Test(object sender, AppControlReceivedEventArgs e)
308         {
309             /*
310              * SCENARIO:
311              * Launch app
312              * -> If log show "NUIApplication::AppControlReceived_Event_Test()" -> PASS
313              */
314             Log.Fatal("TCT", "NUIApplication::AppControlReceived_Event_Test");
315             Log.Fatal("TCT", "[TestCase][AppControlReceived_Event_Test][NUIApplication] Pass");
316         }
317
318         private void Created_Event_Test(object sender, EventArgs e)
319         {
320             /*
321              * SCENARIO:
322              * Launch app
323              * -> If log show "NUIApplication::Created_Event_Test()" -> PASS
324              */
325             Log.Fatal("TCT", "NUIApplication::Created_Event_Test");
326             Log.Fatal("TCT", "[TestCase][Created_Event_Test][NUIApplication] Pass");
327         }
328         public void Paused_Event_Test(object sender, EventArgs e)
329         {
330             /*
331              * PRECONDITION
332              * 1. Open NUIApplication app.
333              * 2. Open other app.
334              */
335             Log.Fatal("TCT", "[TestCase][Paused_Event_Test][NUIApplication] Pass");
336         }
337         public void Resumed_Event_Test(object sender, EventArgs e)
338         {
339             /*
340              * PRECONDITION
341              * 1. Open NUIApplication app.
342              * 2. Open other app.
343              * 3. Long press HOME button and tap to NUIApplicaton shortcut.
344              */
345             Log.Fatal("TCT", "NUIApplication Resumed event occur!");
346             Log.Fatal("TCT", "[TestCase][Resumed_Event_Test][NUIApplication] Pass");
347         }
348
349         public override void Exit()
350         {
351             Log.Fatal("TCT", "[TestCase][Exit][NUIApplication] Pass");
352             base.Exit();
353         }
354         void ShowPropertiesInfo()
355         {
356             if (base.ApplicationInfo != null)
357             {
358                 Log.Fatal("TCT", "[Info] ApplicationInfo is not null");
359                 Log.Fatal("TCT", "[Info] ApplicationInfo.ApplicationId = " + base.ApplicationInfo.ApplicationId);
360                 Log.Fatal("TCT", "[Info] ApplicationInfo.ApplicationType = " + base.ApplicationInfo.ApplicationType);
361                 Log.Fatal("TCT", "[Info] ApplicationInfo.ExecutablePath = " + base.ApplicationInfo.ExecutablePath);
362                 Log.Fatal("TCT", "[Info] ApplicationInfo.ExternalSharedDataPath = " + base.ApplicationInfo.ExternalSharedDataPath);
363                 Log.Fatal("TCT", "[Info] ApplicationInfo.IconPath = " + base.ApplicationInfo.IconPath);
364                 Log.Fatal("TCT", "[Info] ApplicationInfo.IsNoDisplay = " + base.ApplicationInfo.IsNoDisplay);
365                 Log.Fatal("TCT", "[Info] ApplicationInfo.IsOnBoot = " + base.ApplicationInfo.IsOnBoot);
366                 Log.Fatal("TCT", "[Info] ApplicationInfo.IsPreload = " + base.ApplicationInfo.IsPreload);
367                 Log.Fatal("TCT", "[Info] ApplicationInfo.Label = " + base.ApplicationInfo.Label);
368                 Log.Fatal("TCT", "[Info] ApplicationInfo.Metadata Count = " + base.ApplicationInfo.Metadata.Count);
369                 foreach (var item in base.ApplicationInfo.Metadata)
370                 {
371                     Log.Fatal("TCT", "[Info] ApplicationInfo.Metadata, Key: " + item.Key + " Value: " + item.Value);
372                 }
373                 Log.Fatal("TCT", "[Info] ApplicationInfo.PackageId = " + base.ApplicationInfo.PackageId);
374                 Log.Fatal("TCT", "[Info] ApplicationInfo.SharedDataPath = " + base.ApplicationInfo.SharedDataPath);
375                 Log.Fatal("TCT", "[Info] ApplicationInfo.SharedResourcePath = " + base.ApplicationInfo.SharedResourcePath);
376                 Log.Fatal("TCT", "[Info] ApplicationInfo.SharedTrustedPath = " + base.ApplicationInfo.SharedTrustedPath);
377             }
378             if (base.DirectoryInfo != null)
379             {
380                 Log.Fatal("TCT", "[Info] DirectoryInfo is not null");
381                 Log.Fatal("TCT", "[Info] DirectoryInfo.Cache = " + base.DirectoryInfo.Cache);
382                 Log.Fatal("TCT", "[Info] DirectoryInfo.Data = " + base.DirectoryInfo.Data);
383                 Log.Fatal("TCT", "[Info] DirectoryInfo.ExpansionPackageResource = " + base.DirectoryInfo.ExpansionPackageResource);
384                 Log.Fatal("TCT", "[Info] DirectoryInfo.ExternalCache = " + base.DirectoryInfo.ExternalCache);
385                 Log.Fatal("TCT", "[Info] DirectoryInfo.ExternalData = " + base.DirectoryInfo.ExternalData);
386                 Log.Fatal("TCT", "[Info] DirectoryInfo.ExternalSharedData = " + base.DirectoryInfo.ExternalSharedData);
387                 Log.Fatal("TCT", "[Info] DirectoryInfo.Resource = " + base.DirectoryInfo.Resource);
388                 Log.Fatal("TCT", "[Info] DirectoryInfo.SharedData = " + base.DirectoryInfo.SharedData);
389                 Log.Fatal("TCT", "[Info] DirectoryInfo.SharedResource = " + base.DirectoryInfo.SharedResource);
390                 Log.Fatal("TCT", "[Info] DirectoryInfo.SharedTrusted = " + base.DirectoryInfo.SharedTrusted);
391             }
392
393             Log.Fatal("TCT", "[Info] Current == this : " + (Current == this));
394             Log.Fatal("TCT", "[Info] Current.ApplicationInfo.ApplicationId = " + Current.ApplicationInfo.ApplicationId);
395         }
396
397     }
398     class Program
399     {
400         static void Main(string[] args)
401         {
402             Log.Warn("WATCH", "[TestCase][TCT] Main ");
403
404             NUIApplicationsManualWearableTests app = new NUIApplicationsManualWearableTests();
405             app.Run(args);
406         }
407     }
408 }