[NUI] Fix runtime error of xaml testcases
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / Program.cs
1 /*
2  *  Copyright (c) 2017 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 System;
18 using NUnitLite.TUnit;
19 using Tizen.NUI;
20 using Tizen.NUI.BaseComponents;
21 using System.Threading;
22 using System.Diagnostics;
23 using System.Threading.Tasks;
24
25 namespace Tizen.NUI.Devel.Tests
26 {
27     using tlog = Tizen.Log;
28     public class App : Tizen.NUI.NUIApplication
29     {
30         static string tag = "NUITEST";
31
32         public App() : base()
33         {
34             tlog.Debug(tag, "Call App()");
35         }
36
37         View root;
38         public static TextLabel mainTitle;
39         static string title = "NUI Auto TCT \n\n";
40         float textSize = 30.0f;
41         Window window;
42         Layer layer;
43         public static int mainPid;
44         public static int mainTid;
45
46         protected override void OnCreate()
47         {
48             base.OnCreate();
49
50             tlog.Debug(tag, "OnCreate() START!");
51
52             mainPid = Process.GetCurrentProcess().Id;
53             mainTid = Thread.CurrentThread.ManagedThreadId;
54
55             window = NUIApplication.GetDefaultWindow();
56             window.BackgroundColor = Color.Green;
57
58             root = new View()
59             {
60                 Size = new Size(100, 100),
61                 BackgroundColor = Color.White,
62                 PositionUsesPivotPoint = true,
63                 ParentOrigin = ParentOrigin.Center,
64                 PivotPoint = PivotPoint.Center,
65             };
66
67             layer = window.GetDefaultLayer();
68             layer.Add(root);
69
70             mainTitle = new TextLabel()
71             {
72                 MultiLine = true,
73                 Text = title + $"Process ID: {Process.GetCurrentProcess().Id} \nThread ID: {Thread.CurrentThread.ManagedThreadId}\n",
74                 PixelSize = textSize,
75                 BackgroundColor = Color.Cyan,
76                 Size = new Size(window.WindowSize.Width * 0.9f, window.WindowSize.Height * 0.9f, 0),
77                 PositionUsesPivotPoint = true,
78                 ParentOrigin = ParentOrigin.Center,
79                 PivotPoint = PivotPoint.Center,
80             };
81             root.Add(mainTitle);
82
83             tlog.Debug(tag, "OnCreate() END!");
84         }
85
86         static public async Task MainTitleChangeBackgroundColor(Color color)
87         {
88             if (color != null)
89             {
90                 mainTitle.BackgroundColor = color;
91                 await Task.Delay(900);
92             }
93         }
94
95         static public async Task MainTitleChangeText(string tcTitle)
96         {
97             if (tcTitle != null)
98             {
99                 var processId = Process.GetCurrentProcess().Id;
100                 var threadId = Thread.CurrentThread.ManagedThreadId;
101
102                 mainTitle.Text = $"{title}\nProcess ID: {processId}\nThread ID: {threadId}\n TC: {tcTitle}";
103                 await Task.Delay(20);
104
105                 tlog.Debug(tag, $"{title}\nProcess ID: {processId}\nThread ID: {threadId}\n TC: {tcTitle}");
106             }
107         }
108
109         protected override void OnResume()
110         {
111             base.OnResume();
112
113             tlog.Debug(tag, $"### OnResume() START!");
114
115             TRunner t = new TRunner();
116             t.LoadTestsuite();
117             t.Execute();
118
119             tlog.Debug(tag, $"OnResume() END!");
120         }
121
122         protected override void OnPause()
123         {
124             base.OnPause();
125         }
126
127         protected override void OnTerminate()
128         {
129             base.OnTerminate();
130             Exit();
131         }
132
133         static void Main(string[] args)
134         {
135             tlog.Debug(tag, "NUI RUN!");
136             App example = new App();
137             example.Run(args);
138         }
139     };
140 }