2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using System.Reflection;
21 using System.Collections.Generic;
23 using Tizen.Applications;
25 namespace ElmSharp.Test
27 public class TestRunner : CoreUIApplication
29 internal Window _firstPageWindow;
30 private static bool s_terminated;
32 public static string ResourceDir { get; private set; }
39 protected override void OnCreate()
41 ResourceDir = DirectoryInfo.Resource;
43 var testCases = GetTestCases();
44 CreateFirstPage(testCases);
48 protected override void OnTerminate()
54 public void RunStandalone(string[] args)
56 ResourceDir = Path.Combine(Path.GetDirectoryName(typeof(TestRunner).GetTypeInfo().Assembly.Location), "res");
58 EcoreSynchronizationContext.Initialize();
60 var testCases = GetTestCases();
61 TestCaseBase theTest = null;
65 theTest = testCases.Where((testCase) => testCase.TestName == args[0] || testCase.GetType().ToString() == args[0]).FirstOrDefault();
71 EcoreMainloop.Begin();
75 CreateFirstPage(testCases);
76 EcoreMainloop.Begin();
79 Elementary.Shutdown();
82 private IEnumerable<TestCaseBase> GetTestCases()
84 Assembly asm = typeof(TestRunner).GetTypeInfo().Assembly;
85 Type testCaseType = typeof(TestCaseBase);
87 var tests = from test in asm.GetTypes()
88 where testCaseType.IsAssignableFrom(test) && !test.GetTypeInfo().IsInterface && !test.GetTypeInfo().IsAbstract
89 select Activator.CreateInstance(test) as TestCaseBase;
91 return from test in tests
96 internal static void UIExit()
101 private Window CreateWindow(bool isSecond = false)
103 Window window = new Window("ElmSharp UI Tests")
105 AvailableRotations = DisplayRotation.Degree_0 | DisplayRotation.Degree_180 | DisplayRotation.Degree_270 | DisplayRotation.Degree_90
110 window.BackButtonPressed += (s, e) =>
115 GC.WaitForPendingFinalizers();
120 window.BackButtonPressed += (s, e) =>
128 private void CreateFirstPage(IEnumerable<TestCaseBase> testCases)
130 _firstPageWindow = CreateWindow();
131 Console.WriteLine("Screen DPI : {0}", _firstPageWindow.ScreenDpi.X);
132 Conformant conformant = new Conformant(_firstPageWindow);
134 Box box = new Box(_firstPageWindow)
142 var bg = new Background(_firstPageWindow);
143 bg.Color = Color.White;
145 conformant.SetContent(bg);
147 GenList list = new GenList(_firstPageWindow)
156 GenItemClass defaultClass = new GenItemClass("default")
158 GetTextHandler = (data, part) =>
160 return string.Format("{0}",(string)data);
164 list.Append(defaultClass, "");
165 foreach (var tc in testCases)
167 list.Append(defaultClass, tc.TestName);
169 list.Append(defaultClass, "");
171 list.ItemSelected += (s, e) =>
173 foreach (var tc in testCases)
175 if (tc.TestName == (string)(e.Item.Data))
187 private void StartTC(TestCaseBase tc)
189 Window window = CreateWindow();
193 private void StartTCFromList(TestCaseBase tc)
195 Window window = CreateWindow(true);
199 static void Main(string[] args)
201 Elementary.Initialize();
202 Elementary.ThemeOverlay();
204 Console.WriteLine("ELM_PROFILE : {0}", Elementary.GetProfile());
205 Console.WriteLine("ELM_SCALE : {0}", Elementary.GetScale());
207 TestRunner testRunner = new TestRunner();
208 testRunner.Run(args);
210 // if running with appfw is failed, below line will be executed.
213 testRunner.RunStandalone(args);