A game framework written with osu! in mind.
at master 2.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Linq; 6using osu.Framework.Allocation; 7using osu.Framework.Bindables; 8using osu.Framework.Configuration; 9using osu.Framework.Graphics.Containers; 10using osu.Framework.Platform; 11 12namespace osu.Framework.Testing 13{ 14 public class TestBrowserTestRunner : CompositeDrawable 15 { 16 private const double time_between_tests = 200; 17 18 private Bindable<double> volume; 19 private double volumeAtStartup; 20 21 public TestBrowserTestRunner(TestBrowser browser) 22 { 23 this.browser = browser; 24 } 25 26 [BackgroundDependencyLoader] 27 private void load(FrameworkConfigManager config) 28 { 29 volume = config.GetBindable<double>(FrameworkSetting.VolumeUniversal); 30 volumeAtStartup = volume.Value; 31 volume.Value = 0; 32 } 33 34 protected override void Dispose(bool isDisposing) 35 { 36 volume.Value = volumeAtStartup; 37 base.Dispose(isDisposing); 38 } 39 40 protected override void LoadComplete() 41 { 42 base.LoadComplete(); 43 44 AddInternal(browser); 45 46 Console.WriteLine($@"{(int)Time.Current}: Running {browser.TestTypes.Count} visual test cases..."); 47 48 runNext(); 49 } 50 51 private int testIndex; 52 53 private Type loadableTestType => testIndex >= 0 ? browser.TestTypes.ElementAtOrDefault(testIndex) : null; 54 55 private readonly TestBrowser browser; 56 57 [Resolved] 58 private GameHost host { get; set; } 59 60 private void runNext() 61 { 62 if (loadableTestType == null) 63 { 64 //we're done 65 Scheduler.AddDelayed(host.Exit, time_between_tests); 66 return; 67 } 68 69 if (browser.CurrentTest?.GetType() != loadableTestType) 70 { 71 browser.LoadTest(loadableTestType, () => 72 { 73 testIndex++; 74 Scheduler.AddDelayed(runNext, time_between_tests); 75 }); 76 } 77 } 78 } 79}