protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); sourceName = Intent.GetStringExtra("TestSuite"); suiteElement = AndroidRunner.Runner.Suites[sourceName]; var menu = new RootElement(String.Empty); main = new Section(sourceName); foreach (var test in suiteElement.TestCases) { main.Add(test); } menu.Add(main); var options = new Section() { new ActionElement("Run all", Run), }; menu.Add(options); var da = new DialogAdapter(this, menu); var lv = new ListView(this) { Adapter = da }; SetContentView(lv); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); test_suite = Intent.GetStringExtra ("TestSuite"); suite = AndroidRunner.Suites [test_suite]; var menu = new RootElement (String.Empty); main = new Section (test_suite); foreach (ITest test in suite.Tests) { TestSuite ts = test as TestSuite; if (ts != null) main.Add (new TestSuiteElement (ts)); else main.Add (new TestCaseElement (test as TestCase)); } menu.Add (main); Section options = new Section () { new ActionElement ("Run all", Run), }; menu.Add (options); var da = new DialogAdapter (this, menu); var lv = new ListView (this) { Adapter = da }; SetContentView (lv); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); var menu = new RootElement ("Test Runner"); var runMode = new Section("Run Mode"); var interactiveCheckBox = new CheckboxElement("Enable Interactive Mode"); interactiveCheckBox.ValueChanged += (sender , args) => GraphicsTestBase.ForceInteractiveMode = interactiveCheckBox.Value; runMode.Add(interactiveCheckBox); menu.Add(runMode); main = new Section ("Test Suites"); IList<ITest> suites = new List<ITest>(AndroidRunner.AssemblyLevel); while (suites.Count == 1 && (suites[0] is TestSuite)) suites = suites[0].Tests; foreach (var test in suites) { var ts = test as TestSuite; if (ts != null) main.Add(new TestSuiteElement(ts)); else main.Add(new TestCaseElement(test)); } menu.Add (main); Section options = new Section () { new ActionElement ("Run Everything", Run), new ActivityElement ("Credits", typeof (CreditsActivity)) }; menu.Add (options); var lv = new ListView (this) { Adapter = new DialogAdapter (this, menu) }; SetContentView (lv); // AutoStart running the tests (with either the supplied 'writer' or the options) if (Runner.AutoStart) { string msg = String.Format ("Automatically running tests{0}...", Runner.TerminateAfterExecution ? " and closing application" : String.Empty); Toast.MakeText (this, msg, ToastLength.Long).Show (); ThreadPool.QueueUserWorkItem (delegate { RunOnUiThread (delegate { Run (); // optionally end the process, e.g. click "Andr.Unit" -> log tests results, return to springboard... if (Runner.TerminateAfterExecution) Finish (); }); }); } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); if (Runner.Options == null) Runner.Options = new Options (this); var menu = new RootElement ("Test Runner"); main = new Section ("Test Suites"); foreach (TestSuite suite in AndroidRunner.AssemblyLevel) { main.Add (new TestSuiteElement (suite)); } menu.Add (main); Section options = new Section () { new ActionElement ("Run Everything", Run), new ActivityElement ("Options", typeof (OptionsActivity)), new ActivityElement ("Credits", typeof (CreditsActivity)) }; menu.Add (options); var lv = new ListView (this) { Adapter = new DialogAdapter (this, menu) }; SetContentView (lv); // AutoStart running the tests (with either the supplied 'writer' or the options) if (Runner.AutoStart) { string msg = String.Format ("Automatically running tests{0}...", Runner.TerminateAfterExecution ? " and closing application" : String.Empty); Toast.MakeText (this, msg, ToastLength.Long).Show (); ThreadPool.QueueUserWorkItem (delegate { RunOnUiThread (delegate { Run (); // optionally end the process, e.g. click "Andr.Unit" -> log tests results, return to springboard... if (Runner.TerminateAfterExecution) Finish (); }); }); } }
void Populate(object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; var members = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members) { Type mType = GetTypeForMember(mi); if (mType == null) continue; string caption = null; object[] attrs = mi.GetCustomAttributes(false); bool skip = false; foreach (var attr in attrs) { if (attr is SkipAttribute) skip = true; if (attr is CaptionAttribute) caption = ((CaptionAttribute)attr).Caption; else if (attr is SectionAttribute) { if (section != null) root.Add(section); var sa = attr as SectionAttribute; section = new Section(sa.Caption, sa.Footer); } } if (skip) continue; if (caption == null) caption = MakeCaption(mi.Name); if (section == null) section = new Section(); Element element = null; if (mType == typeof(string)) { PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; EventHandler invoke = null; bool multi = false; foreach (object attr in attrs) { if (attr is PasswordAttribute) pa = attr as PasswordAttribute; else if (attr is EntryAttribute) ea = attr as EntryAttribute; else if (attr is MultilineAttribute) multi = true; else if (attr is HtmlAttribute) html = attr; else if (attr is AlignmentAttribute) align = attr as AlignmentAttribute; if (attr is OnTapAttribute) { string mname = ((OnTapAttribute)attr).Method; if (callbacks == null) { throw new Exception("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType().GetMethod(mname); if (method == null) throw new Exception("Did not find method " + mname); invoke = delegate { method.Invoke(method.IsStatic ? null : callbacks, new object[0]); }; } } string value = (string)GetValue(mi, o); if (pa != null) element = new EntryElement(caption, value) { Hint = pa.Placeholder, Password = true }; else if (ea != null) element = new EntryElement(caption, value) { Hint = ea.Placeholder }; else if (multi) element = new MultilineElement(caption, value); else if (html != null) element = new HtmlElement(caption, value); else { var selement = new StringElement(caption, value); element = selement; if (align != null) selement.Alignment = align.Alignment; } if (invoke != null) { // ((StringElement)element).Click += invoke; } } else if (mType == typeof(float)) { var floatElement = new FloatElement(null, null, (int)GetValue(mi, o)); floatElement.Caption = caption; element = floatElement; foreach (object attr in attrs) { if (attr is RangeAttribute) { var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof(bool)) { bool checkbox = false; foreach (object attr in attrs) { if (attr is CheckboxAttribute) checkbox = true; } if (checkbox) element = new CheckboxElement(caption, (bool)GetValue(mi, o)); else element = new BooleanElement(caption, (bool)GetValue(mi, o)); } else if (mType == typeof(DateTime)) { var dateTime = (DateTime)GetValue(mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs) { if (attr is DateAttribute) asDate = true; else if (attr is TimeAttribute) asTime = true; } if (asDate) element = new DateElement(caption, dateTime); else if (asTime) element = new TimeElement(caption, dateTime); else element = new DateTimeElement(caption, dateTime); } else if (mType.IsEnum) { var csection = new Section(); ulong evalue = Convert.ToUInt64(GetValue(mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static)) { ulong v = Convert.ToUInt64(GetValue(fi, null)); if (v == evalue) selected = idx; csection.Add(new RadioElement(MakeCaption(fi.Name))); idx++; } element = new RootElement(caption, new RadioGroup(null, selected)) { csection }; } else if (mType == typeof(ImageView)) { element = new ImageElement(null); // (ImageView)GetValue(mi, o)); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType)) { var csection = new Section(); int count = 0; if (last_radio_index == null) throw new Exception("IEnumerable found, but no previous int found"); foreach (var e in (IEnumerable)GetValue(mi, o)) { csection.Add(new RadioElement(e.ToString())); count++; } int selected = (int)GetValue(last_radio_index, o); if (selected >= count || selected < 0) selected = 0; element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof(int) == mType) { foreach (object attr in attrs) { if (attr is RadioSelectionAttribute) { last_radio_index = mi; break; } } } else { var nested = GetValue(mi, o); if (nested != null) { var newRoot = new RootElement(caption); Populate(callbacks, nested, newRoot); element = newRoot; } } if (element == null) continue; section.Add(element); mappings[element] = new MemberAndInstance(mi, o); } root.Add(section); }