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 private Window _firstPageWindow;
31 public static string ResourceDir { get; private set; }
37 protected override void OnCreate()
39 ResourceDir = DirectoryInfo.Resource;
41 var testCases = GetTestCases();
42 CreateFirstPage(testCases);
46 public void RunStandalone(string[] args)
48 ResourceDir = Path.Combine(Path.GetDirectoryName(typeof(TestRunner).GetTypeInfo().Assembly.Location), "res");
50 Elementary.Initialize();
51 Elementary.ThemeOverlay();
53 EcoreSynchronizationContext.Initialize();
55 var testCases = GetTestCases();
56 TestCaseBase theTest = null;
60 theTest = testCases.Where((testCase) => testCase.TestName == args[0] || testCase.GetType().ToString() == args[0]).FirstOrDefault();
66 EcoreMainloop.Begin();
70 CreateFirstPage(testCases);
71 EcoreMainloop.Begin();
74 Elementary.Shutdown();
77 private IEnumerable<TestCaseBase> GetTestCases()
79 Assembly asm = typeof(TestRunner).GetTypeInfo().Assembly;
80 Type testCaseType = typeof(TestCaseBase);
82 var tests = from test in asm.GetTypes()
83 where testCaseType.IsAssignableFrom(test) && !test.GetTypeInfo().IsInterface && !test.GetTypeInfo().IsAbstract
84 select Activator.CreateInstance(test) as TestCaseBase;
86 return from test in tests
91 internal static void UIExit()
96 private Window CreateWindow(bool isSecond = false)
98 Window window = new Window("ElmSharp UI Tests");
102 window.KeyGrab(EvasKeyEventArgs.PlatformBackButtonName, true);
103 window.KeyUp += (s, e) =>
105 if (e.KeyName == EvasKeyEventArgs.PlatformBackButtonName)
110 GC.WaitForPendingFinalizers();
116 window.KeyGrab(EvasKeyEventArgs.PlatformBackButtonName, false);
117 window.KeyUp += (s, e) =>
119 if (e.KeyName == EvasKeyEventArgs.PlatformBackButtonName)
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 conformant.SetContent(box);
144 GenList list = new GenList(_firstPageWindow)
153 GenItemClass defaultClass = new GenItemClass("default")
155 GetTextHandler = (data, part) =>
157 return string.Format("{0}",(string)data);
161 foreach (var tc in testCases)
163 list.Append(defaultClass, tc.TestName);
166 list.ItemSelected += (s, e) =>
168 foreach (var tc in testCases)
170 if (tc.TestName == (string)(e.Item.Data))
182 private void StartTC(TestCaseBase tc)
184 Window window = CreateWindow();
188 private void StartTCFromList(TestCaseBase tc)
190 Window window = CreateWindow(true);
194 static void Main(string[] args)
196 TestRunner testRunner = new TestRunner();
197 testRunner.Run(args);
199 // if running with appfw is failed, below line will be executed.
200 testRunner.RunStandalone(args);