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; }
34 public string Profile { get; set; }
41 protected override void OnCreate()
43 ResourceDir = DirectoryInfo.Resource;
45 var testCases = GetTestCases();
46 CreateFirstPage(testCases);
50 protected override void OnTerminate()
56 public void RunStandalone(string[] args)
58 ResourceDir = Path.Combine(Path.GetDirectoryName(typeof(TestRunner).GetTypeInfo().Assembly.Location), "res");
60 EcoreSynchronizationContext.Initialize();
62 var testCases = GetTestCases();
63 TestCaseBase theTest = null;
67 theTest = testCases.Where((testCase) => testCase.TestName == args[0] || testCase.GetType().ToString() == args[0]).FirstOrDefault();
73 EcoreMainloop.Begin();
77 CreateFirstPage(testCases);
78 EcoreMainloop.Begin();
81 Elementary.Shutdown();
84 private IEnumerable<TestCaseBase> GetTestCases()
86 Assembly asm = typeof(TestRunner).GetTypeInfo().Assembly;
87 Type testCaseType = typeof(TestCaseBase);
89 var tests = from test in asm.GetTypes()
90 where testCaseType.IsAssignableFrom(test) && !test.GetTypeInfo().IsInterface && !test.GetTypeInfo().IsAbstract
91 select Activator.CreateInstance(test) as TestCaseBase;
93 return from test in tests
98 internal static void UIExit()
100 EcoreMainloop.Quit();
103 private Window CreateWindow(bool isSecond = false)
105 Window window = new Window("ElmSharp UI Tests")
107 AvailableRotations = DisplayRotation.Degree_0 | DisplayRotation.Degree_180 | DisplayRotation.Degree_270 | DisplayRotation.Degree_90
112 window.BackButtonPressed += (s, e) =>
117 GC.WaitForPendingFinalizers();
122 window.BackButtonPressed += (s, e) =>
130 private void CreateFirstPage(IEnumerable<TestCaseBase> testCases)
132 _firstPageWindow = CreateWindow();
133 Console.WriteLine("Screen DPI : {0}", _firstPageWindow.ScreenDpi.X);
134 Conformant conformant = new Conformant(_firstPageWindow);
136 Box box = new Box(_firstPageWindow)
144 var bg = new Background(_firstPageWindow);
145 bg.Color = Color.White;
147 conformant.SetContent(bg);
149 GenList list = new GenList(_firstPageWindow)
158 GenItemClass defaultClass = new GenItemClass("default")
160 GetTextHandler = (data, part) =>
162 TestCaseBase tc = data as TestCaseBase;
163 return tc == null ? "" : tc.TestName;
167 foreach (var tc in testCases.Where<TestCaseBase>((tc) => tc.TargetProfile.HasFlag(GetTargetProfile())))
169 list.Append(defaultClass, tc);
172 if (Profile == "wearable")
174 list.Prepend(defaultClass, null);
175 list.Append(defaultClass, null);
178 list.ItemSelected += (s, e) =>
180 TestCaseBase tc = e.Item.Data as TestCaseBase;
188 private void StartTC(TestCaseBase tc)
190 Window window = CreateWindow();
194 private void StartTCFromList(TestCaseBase tc)
196 Window window = CreateWindow(true);
200 private TargetProfile GetTargetProfile()
205 return TargetProfile.Wearable;
207 return TargetProfile.Mobile;
209 return TargetProfile.Tv;
211 return TargetProfile.Mobile;
214 static void Main(string[] args)
216 Elementary.Initialize();
217 Elementary.ThemeOverlay();
219 var profile = Elementary.GetProfile();
220 Console.WriteLine("ELM_PROFILE : {0}", profile);
221 Console.WriteLine("ELM_SCALE : {0}", Elementary.GetScale());
223 TestRunner testRunner = new TestRunner();
224 testRunner.Profile = profile;
225 testRunner.Run(args);
227 // if running with appfw is failed, below line will be executed.
230 testRunner.RunStandalone(args);