[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / 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.Applications;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22 using System.Threading;
23 using System.Diagnostics;
24 using System.Threading.Tasks;
25
26 namespace Tizen.NUI.Devel.Tests
27 {
28     using tlog = Tizen.Log;
29     public class App : Tizen.NUI.NUIApplication
30     {
31         static string tag = "NUITEST";
32
33         public App() : base()
34         {
35             tlog.Debug(tag, "Call App()");
36         }
37
38         View root;
39         public static TextLabel mainTitle;
40         static string title = "NUI Auto TCT \n\n";
41         float textSize = 30.0f;
42         Window window;
43         Layer layer;
44         public static int mainPid;
45         public static int mainTid;
46         Timer timer;
47
48         protected override void OnCreate()
49         {
50             base.OnCreate();
51
52             tlog.Debug(tag, "OnCreate() START!");
53
54             mainPid = Process.GetCurrentProcess().Id;
55             mainTid = Thread.CurrentThread.ManagedThreadId;
56
57             window = NUIApplication.GetDefaultWindow();
58             window.BackgroundColor = Color.Green;
59
60             root = new View()
61             {
62                 Size = new Size(100, 100),
63                 BackgroundColor = Color.White,
64                 PositionUsesPivotPoint = true,
65                 ParentOrigin = ParentOrigin.Center,
66                 PivotPoint = PivotPoint.Center,
67             };
68
69             layer = window.GetDefaultLayer();
70             layer.Add(root);
71
72             mainTitle = new TextLabel()
73             {
74                 MultiLine = true,
75                 Text = title + $"Process ID: {Process.GetCurrentProcess().Id} \nThread ID: {Thread.CurrentThread.ManagedThreadId}\n",
76                 PixelSize = textSize,
77                 BackgroundColor = Color.Cyan,
78                 Size = new Size(window.WindowSize.Width * 0.9f, window.WindowSize.Height * 0.9f, 0),
79                 PositionUsesPivotPoint = true,
80                 ParentOrigin = ParentOrigin.Center,
81                 PivotPoint = PivotPoint.Center,
82             };
83             root.Add(mainTitle);
84
85             tlog.Debug(tag, "OnCreate() END!");
86
87             timer = new Timer(1000);
88             timer.Tick += OnTick;
89             timer.Start();
90
91         }
92
93         private bool OnTick(object obj, EventArgs e)
94         {
95             TRunner t = new TRunner();
96             t.LoadTestsuite();
97             t.Execute();
98
99             App.MainTitleChangeText("Finished!");
100             return false;
101         }
102
103
104
105         static public async Task MainTitleChangeBackgroundColor(Color color)
106         {
107             if (color != null)
108             {
109                 mainTitle.BackgroundColor = color;
110                 await Task.Delay(900);
111             }
112         }
113
114         static public async Task MainTitleChangeText(string tcTitle)
115         {
116             if (tcTitle != null)
117             {
118                 var processId = Process.GetCurrentProcess().Id;
119                 var threadId = Thread.CurrentThread.ManagedThreadId;
120
121                 mainTitle.Text = $"{title}\nProcess ID: {processId}\nThread ID: {threadId}\n TC: {tcTitle}";
122                 await Task.Delay(20);
123
124                 tlog.Debug(tag, $"{title}\nProcess ID: {processId}\nThread ID: {threadId}\n TC: {tcTitle}");
125             }
126         }
127
128         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
129         {
130             base.OnAppControlReceived(e);
131             tlog.Debug(tag, $"### OnAppControlReceived() START!");
132         }
133
134         protected override void OnResume()
135         {
136             base.OnResume();
137
138             tlog.Debug(tag, $"### OnResume() START!");
139
140             // TRunner t = new TRunner();
141             // t.LoadTestsuite();
142             // t.Execute();
143
144             tlog.Debug(tag, $"OnResume() END!");
145         }
146
147         protected override void OnPause()
148         {
149             base.OnPause();
150         }
151
152         protected override void OnTerminate()
153         {
154             timer.Tick -= OnTick;
155             mainTitle.GetParent().Remove(mainTitle);
156             mainTitle = null;
157             root.GetParent().Remove(root);
158             root = null;
159
160             base.OnTerminate();
161             Exit();
162         }
163
164         static void Main(string[] args)
165         {
166             tlog.Debug(tag, "NUI RUN!");
167             App example = new App();
168             example.Run(args);
169         }
170     };
171 }