Inheritance: IDisposable
示例#1
0
        public void PluginsMultipleLoad()
        {
            int pluginLoadIterations = 0;

            int constructorSimulator = 0;
            int constructorWidget    = 0;
            int constructorExtension = 0;

            TestConstants.Prepare();

            GlobalEvents.Hook <PluginsLoaded>((x) =>
            {
                pluginLoadIterations++;

                Assert.AreNotEqual(x.Simulators, null);
                Assert.AreNotEqual(x.Widgets, null);
                Assert.AreNotEqual(x.Extensions, null);

                Assert.AreEqual(x.Simulators.ToList().Count, cfgSimulatorPlugins - cfgSimulatorPluginsInvalid);
                Assert.AreEqual(x.Widgets.ToList().Count, cfgWidgetPlugins - cfgWidgetPluginsInvalid);
                Assert.AreEqual(x.Extensions.ToList().Count, cfgExtensionPlugins - cfgExtensionPluginsInvalid);
            }, true);

            // Count number of constructors.
            GlobalEvents.Hook <PluginTestExtensionConstructor>((x) => constructorExtension++, false);
            GlobalEvents.Hook <PluginTestWidgetConstructor>((x) => constructorWidget++, false);
            GlobalEvents.Hook <PluginTestSimulatorConstructor>((x) => constructorSimulator++, false);

            using (var pluginHost = new SimTelemetry.Domain.Plugins.Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                var rand = new Random().Next(1, 5);
                Debug.WriteLine("Initializing " + rand + " times");
                for (int i = 0; i < rand; i++)
                {
                    pluginHost.Load();
                    pluginHost.Unload();
                }
                pluginHost.Load();
                pluginHost.Unload();
            }

            using (var pluginHost = new SimTelemetry.Domain.Plugins.Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                pluginHost.Load();
            }

            // Verify everything!
            Assert.AreEqual(constructorSimulator, pluginLoadIterations * cfgSimulatorPlugins);
            Assert.AreEqual(constructorExtension, pluginLoadIterations * cfgExtensionPlugins);
            Assert.AreEqual(constructorWidget, pluginLoadIterations * cfgWidgetPlugins);

            Assert.AreEqual(TestConstants.Warnings,
                            pluginLoadIterations *
                            (cfgWidgetPluginsInvalid + cfgSimulatorPluginsInvalid + cfgExtensionPluginsInvalid));
        }
        public void TrackDataProviderTests()
        {
            TestConstants.Prepare();

            using (var pluginHost = new Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;
                pluginHost.Load();

                Assert.Greater(pluginHost.Simulators.Count, 0);
                var testSim = pluginHost.Simulators[0];

                var w = new Stopwatch();

                w.Start();

                var mem = GC.GetTotalMemory(true);
                var trackRepo = new TrackRepository(testSim.TrackProvider);
                var tracks = trackRepo.GetIds().Count();

                w.Stop();
                Debug.WriteLine("[TIME] Retrieving ID list (" + tracks + ") costs " + w.ElapsedMilliseconds + "ms");
                w.Reset();

                w.Start();
                var Spa = trackRepo.GetByFile("67_SPA.GDB");
                Assert.AreNotEqual(null, Spa);
                Debug.WriteLine(Spa.Name + " " + Spa.Length);

                w.Stop();
                Debug.WriteLine("[TIME] Retrieving Spa 1967 costs " + w.ElapsedMilliseconds + "ms");
                w.Reset();

                // Building all tracks can take seconds.
                /*w.Start();
                foreach(var track in trackRepo.GetAll())
                    Debug.WriteLine(track.Name + "=" + track.Length);
                w.Stop();
                Debug.WriteLine("[TIME] Retrieving all tracks costs " + w.ElapsedMilliseconds + "ms");*/

                w.Start();

                Spa = trackRepo.GetByFile("67_SPA.GDB");
                Assert.AreNotEqual(null, Spa);
                Debug.WriteLine(Spa.Name + " " + Spa.Length);

                w.Stop();
                Debug.WriteLine("[TIME] Retrieving Spa 1967 costs " + w.ElapsedMilliseconds + "ms");
                Assert.LessOrEqual(w.ElapsedMilliseconds, 1);
                w.Reset();

                var dmem = GC.GetTotalMemory(true) - mem;
                Debug.WriteLine(dmem);
                w.Reset();
            }
        }
示例#3
0
        public void PluginsFound()
        {
            bool pluginsLoadedEventFire = false;

            TestConstants.Prepare();

            // Listen to warnings:

            GlobalEvents.Hook<PluginsLoaded>((x) =>
            {
                Assert.AreNotEqual(x.Simulators, null);
                Assert.AreNotEqual(x.Widgets, null);
                Assert.AreNotEqual(x.Extensions, null);

                Assert.AreEqual(x.Simulators.ToList().Count, cfgSimulatorPlugins - cfgSimulatorPluginsInvalid);
                Assert.AreEqual(x.Widgets.ToList().Count, cfgWidgetPlugins - cfgWidgetPluginsInvalid);
                Assert.AreEqual(x.Extensions.ToList().Count, cfgExtensionPlugins - cfgExtensionPluginsInvalid);

                pluginsLoadedEventFire = true;
            }, true);

            // Manually count the no of plugins in the bin directory.
            var files = Directory.GetFiles(TestConstants.SimulatorsBinFolder);
            var plugins = files.Where(x => Path.GetFileName(x).Contains("SimTelemetry.Plugins.") && x.ToLower().EndsWith(".dll"));

            using (var pluginHost = new Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                pluginHost.Load();

                // Resolve the no. of plugins there are available:
                var iPluginsManualCount = plugins.ToList().Count;
                var iPluginsTelemetry = pluginHost.Simulators.ToList().Count;

                Assert.AreNotEqual(0, iPluginsManualCount);
                Assert.AreEqual(iPluginsTelemetry, iPluginsManualCount);
            }

            Assert.AreEqual(pluginsLoadedEventFire, true);
            Assert.AreEqual(TestConstants.Warnings, cfgWidgetPluginsInvalid + cfgSimulatorPluginsInvalid + cfgExtensionPluginsInvalid);
        }
示例#4
0
        public void SimulatorBasicTests()
        {
            TestConstants.Prepare();

            var trackScanCount = 0;
            var modScanCount = 0;

            // Events fired from test object:
            GlobalEvents.Hook<PluginTestSimulatorModScanner>((x) => { modScanCount++; }, true);
            GlobalEvents.Hook<PluginTestSimulatorTrackScanner>((x) => { trackScanCount++; }, true);

            using (var pluginHost = new Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                pluginHost.Load();

                Assert.Greater(pluginHost.Simulators.Count, 0);

                var testSim = pluginHost.Simulators[0];

                var testSimulator = testSim.GetSimulator();
                Assert.AreEqual(0, trackScanCount);
                Assert.AreEqual(0, modScanCount);

                Assert.AreEqual("rFactor", testSimulator.Name);
                Assert.AreEqual("rfactor", testSimulator.ProcessName);
                Assert.AreEqual("1.255", testSimulator.Version);

                var tracks = testSimulator.Tracks;
                var mods = testSimulator.Mods;

                Assert.AreEqual(1, modScanCount);
                Assert.AreEqual(1, trackScanCount);

                Assert.AreEqual(1, tracks.Count(x => x.ID != string.Empty));
                Assert.AreEqual(1, mods.Count(x => x.Name != ""));
            }
        }
示例#5
0
        public void Record()
        {
            if (Process.GetProcessesByName("rfactor").Length == 0) Assert.Ignore();
            var rFactorProcess = Process.GetProcessesByName("rfactor")[0];

            IntPtr alloc = Marshal.AllocHGlobal(512 * 1024 * 1024);

            using (var host = new Plugins())
            {
                host.PluginDirectory = TestConstants.SimulatorsBinFolder;

                host.Load();

                // Simulators are now loaded

                var testPlugin = host.Simulators.Where(x => x.Name == "Test simulator").FirstOrDefault();
                testPlugin.SimulatorStart(rFactorProcess);

                var telSource = new Domain.Aggregates.Telemetry(testPlugin.TelemetryProvider, rFactorProcess);
                var telLogger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, false, true, false));
                telLogger.SetAnnotater(new TelemetryArchive());
                telSource.SetLogger(telLogger);

                Thread.Sleep(15000);

                telLogger.Close();
                telSource = null;
            }

            Marshal.FreeHGlobal(alloc);
        }
示例#6
0
        public void PluginsMultipleLoad()
        {
            int pluginLoadIterations = 0;

            int constructorSimulator = 0;
            int constructorWidget = 0;
            int constructorExtension = 0;

            TestConstants.Prepare();

            GlobalEvents.Hook<PluginsLoaded>((x) =>
                                                 {
                                                     pluginLoadIterations++;

                                                     Assert.AreNotEqual(x.Simulators, null);
                                                     Assert.AreNotEqual(x.Widgets, null);
                                                     Assert.AreNotEqual(x.Extensions, null);

                                                     Assert.AreEqual(x.Simulators.ToList().Count, cfgSimulatorPlugins - cfgSimulatorPluginsInvalid);
                                                     Assert.AreEqual(x.Widgets.ToList().Count, cfgWidgetPlugins - cfgWidgetPluginsInvalid);
                                                     Assert.AreEqual(x.Extensions.ToList().Count, cfgExtensionPlugins - cfgExtensionPluginsInvalid);
                                                 }, true);

            // Count number of constructors.
            GlobalEvents.Hook<PluginTestExtensionConstructor>((x) => constructorExtension++, false);
            GlobalEvents.Hook<PluginTestWidgetConstructor>((x) => constructorWidget++, false);
            GlobalEvents.Hook<PluginTestSimulatorConstructor>((x) => constructorSimulator++, false);

            using (var pluginHost = new SimTelemetry.Domain.Plugins.Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                var rand = new Random().Next(1, 5);
                Debug.WriteLine("Initializing " + rand + " times");
                for (int i = 0; i < rand; i++)
                {
                    pluginHost.Load();
                    pluginHost.Unload();
                }
                pluginHost.Load();
                pluginHost.Unload();
            }

            using (var pluginHost = new SimTelemetry.Domain.Plugins.Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;

                pluginHost.Load();
            }

            // Verify everything!
            Assert.AreEqual(constructorSimulator, pluginLoadIterations * cfgSimulatorPlugins);
            Assert.AreEqual(constructorExtension, pluginLoadIterations * cfgExtensionPlugins);
            Assert.AreEqual(constructorWidget, pluginLoadIterations * cfgWidgetPlugins);

            Assert.AreEqual(TestConstants.Warnings,
                            pluginLoadIterations *
                            (cfgWidgetPluginsInvalid + cfgSimulatorPluginsInvalid + cfgExtensionPluginsInvalid));
        }
示例#7
0
        public void CarDataProviderTests()
        {
            TestConstants.Prepare();
            using (var pluginHost = new Plugins())
            {
                pluginHost.PluginDirectory = TestConstants.SimulatorsBinFolder;
                pluginHost.Load();

                Assert.Greater(pluginHost.Simulators.Count, 0);
                var testSim = pluginHost.Simulators[0];

                var w = new Stopwatch();

                w.Start();

                var carRepo = new CarRepository(testSim.CarProvider);
                var cars = carRepo.GetIds().Count();

                // I got over 1106 cars installed, so that's more than 1000.
                Assert.Greater(cars,100);
                w.Stop();
                Debug.WriteLine("[TIME] Retrieving ID list (" + cars + ") costs " + w.ElapsedMilliseconds + "ms");
                w.Reset();

                w.Start();
                var f1Car = carRepo.GetByFile("JButton05.veh");
                Assert.AreNotEqual(f1Car, null);
                if (f1Car != null)
                    Debug.WriteLine("#" + f1Car.StartNumber + ". " + f1Car.Driver);
                Debug.WriteLine("[TIME] Retrieving JButton05.veh car costs " + w.ElapsedMilliseconds + "ms");
                w.Stop();
                w.Reset();

                // This test is very very very slow:
                /*w.Start();
                cars = carRepo.GetAll().Count();
                w.Stop();
                Debug.WriteLine("[TIME] Retrieving all (other) cars costs " + w.ElapsedMilliseconds + "ms");
                w.Reset();*/

                w.Start();
                f1Car = carRepo.GetByFile("TSATO05.veh");
                Assert.AreNotEqual(f1Car, null);
                if (f1Car != null)
                    Debug.WriteLine("#" + f1Car.StartNumber + ". " + f1Car.Driver);
                Debug.WriteLine("[TIME] Retrieving TSATO05.veh car costs " + w.ElapsedMilliseconds + "ms");
                w.Stop();

                w.Reset();

                // Verify that when cached, this is very quick:
                w.Start();
                f1Car = carRepo.GetByFile("JButton05.veh");
                Assert.AreNotEqual(f1Car, null);
                if (f1Car != null)
                    Debug.WriteLine("#" + f1Car.StartNumber + ". " + f1Car.Driver);
                Debug.WriteLine("[TIME] Retrieving JButton05.veh car costs " + w.ElapsedMilliseconds + "ms");

                w.Stop();
                w.Reset();
            }
        }