Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RunnerActivity.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under Apache 2.0 License. See LICENSE.md for details.
3 //
4 // Copyright 2011-2012 Xamarin Inc.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Reflection;
22 using System.Threading;
23 
24 using Android.App;
25 using Android.OS;
26 using Android.Widget;
27 using MonoDroid.Dialog;
28 using NUnit.Framework.Api;
29 using NUnit.Framework.Internal;
30 using SiliconStudio.Paradox.Graphics.Regression;
31 
32 namespace Android.NUnitLite.UI {
33 
34  public class RunnerActivity : Activity {
35 
36  Section main;
37 
38  public RunnerActivity ()
39  {
40  Initialized = (AndroidRunner.AssemblyLevel.Count > 0);
41  }
42 
43  public bool Initialized {
44  get; private set;
45  }
46 
47  public AndroidRunner Runner {
48  get { return AndroidRunner.Runner; }
49  }
50 
51  protected override void OnCreate (Bundle bundle)
52  {
53  base.OnCreate (bundle);
54 
55  var menu = new RootElement ("Test Runner");
56 
57  var runMode = new Section("Run Mode");
58  var interactiveCheckBox = new CheckboxElement("Enable Interactive Mode");
59  interactiveCheckBox.ValueChanged += (sender , args) => GraphicsTestBase.ForceInteractiveMode = interactiveCheckBox.Value;
60  runMode.Add(interactiveCheckBox);
61  menu.Add(runMode);
62 
63  main = new Section ("Test Suites");
64 
65  IList<ITest> suites = new List<ITest>(AndroidRunner.AssemblyLevel);
66  while (suites.Count == 1 && (suites[0] is TestSuite))
67  suites = suites[0].Tests;
68 
69  foreach (var test in suites)
70  {
71  var ts = test as TestSuite;
72  if (ts != null)
73  main.Add(new TestSuiteElement(ts));
74  else
75  main.Add(new TestCaseElement(test));
76  }
77  menu.Add (main);
78 
79  Section options = new Section () {
80  new ActionElement ("Run Everything", Run),
81  new ActivityElement ("Credits", typeof (CreditsActivity))
82  };
83  menu.Add (options);
84 
85  var lv = new ListView (this) {
86  Adapter = new DialogAdapter (this, menu)
87  };
88  SetContentView (lv);
89 
90  // AutoStart running the tests (with either the supplied 'writer' or the options)
91  if (Runner.AutoStart) {
92  string msg = String.Format ("Automatically running tests{0}...",
93  Runner.TerminateAfterExecution ? " and closing application" : String.Empty);
94  Toast.MakeText (this, msg, ToastLength.Long).Show ();
95  ThreadPool.QueueUserWorkItem (delegate {
96  RunOnUiThread (delegate {
97  Run ();
98  // optionally end the process, e.g. click "Andr.Unit" -> log tests results, return to springboard...
99  if (Runner.TerminateAfterExecution)
100  Finish ();
101  });
102  });
103  }
104  }
105 
106  NamespaceAssemblyBuilder builder = new NamespaceAssemblyBuilder(new NUnitLiteTestAssemblyBuilder());
107 
108  public void Add (Assembly assembly)
109  {
110  if (assembly == null)
111  throw new ArgumentNullException ("assembly");
112 
113  // this can be called many times but we only want to load them
114  // once since we need to share them across most activities
115  if (!Initialized)
116  {
117  var ts = builder.Build(assembly, new Dictionary<string, object>());
118 
119  if (ts == null) return;
120 
121  // TestLoader.Load always return a TestSuite so we can avoid casting many times
122  AndroidRunner.AssemblyLevel.Add (ts);
123  Add (ts);
124  }
125  }
126 
127  void Add (TestSuite suite)
128  {
129  var suiteName = suite.FullName ?? suite.Name;
130 
131  // add a suffix to the name if a test with the same name already exists
132  var count = 2;
133  while (AndroidRunner.Suites.ContainsKey(suiteName))
134  {
135  suiteName = (suite.FullName ?? suite.Name) + count;
136  ++count;
137  }
138  suite.FullName = suite.Name = suiteName;
139 
140  AndroidRunner.Suites.Add(suiteName, suite);
141  foreach (ITest test in suite.Tests)
142  {
143  TestSuite ts = (test as TestSuite);
144  if (ts != null)
145  Add (ts);
146  }
147  }
148 
149  async void Run ()
150  {
151  if (!Runner.OpenWriter ("Run Everything", this))
152  return;
153 
154  try {
155  foreach (TestSuite suite in AndroidRunner.AssemblyLevel)
156  {
157  await Runner.Run(suite);
158  }
159  }
160  finally {
161  Runner.CloseWriter ();
162  }
163 
164  foreach (TestElement te in main) {
165  te.Update ();
166  }
167  }
168  }
169 }
_In_ size_t count
Definition: DirectXTexP.h:174
static IDictionary< string, TestSuite > Suites
Sections contain individual Element instances that are rendered by MonoDroid.Dialog ...
Definition: Section.cs:28
override void OnCreate(Bundle bundle)