Пример #1
0
        public void DepthVideo_Is_Drawn_When_RenderDepth_Is_True_And_The_DepthVideoOutputTarget_Is_Defined_And_Valid()
        {
            VastPark.Legacy.Environment.Initialise(System.IO.Path.GetTempPath());

            var context = new ImmlDocument();
            var parkEngine = new Mock<IParkEngine>();
            parkEngine.Setup(c => c.Context).Returns(context);

            var renderEngine = new Mock<IRenderEngine>();
            parkEngine.Setup(r => r.RenderEngine).Returns(renderEngine.Object);

            var scriptEngine = new Mock<IScriptEngine>();
            scriptEngine.Setup(s => s.WriteLine(It.IsAny<string>())).Callback<string>(a => System.Diagnostics.Debug.WriteLine(a));
            parkEngine.Setup(s => s.ScriptEngine).Returns(scriptEngine.Object);

            var primitive = ImmlElementFactory.CreatePrimitive();
            primitive.Name = "DepthTarget";

            context.Add(primitive);

            var timePeriod = TimeSpan.FromSeconds(30); //allow up to 30 seconds for the context to become ready
            var slimResetEvent = new SlimResetEvent(100);
            var start = DateTime.Now;
            var textureWritten = false;

            Texture.TextureBytesLoaded += delegate
            {
                textureWritten = true;
            };

            ThreadPool.QueueUserWorkItem(w =>
            {
                using (var plugin = new OpenNiPlugin())
                {
                    plugin.SetParkEngine(parkEngine.Object);
                    plugin.RenderDepth = true;
                    plugin.DepthVideoOutputTarget = primitive.Name;
                    plugin.Load();
                    plugin.Enabled = true;

                    while (DateTime.Now.Subtract(start) < timePeriod)
                    {
                        plugin.Update();

                        if (textureWritten)
                        {
                            break;
                        }

                        Thread.Sleep(16);
                    }

                    slimResetEvent.Set();
                }
            });

            slimResetEvent.Wait();

            Assert.True(textureWritten);
        }
Пример #2
0
        public void When_The_Kinect_Is_Connected_The_Plugin_Successfully_Loads()
        {
            VastPark.Legacy.Environment.Initialise(System.IO.Path.GetTempPath());

            var timePeriod = TimeSpan.FromSeconds(30); //allow up to 30 seconds for the context to become ready
            var slimResetEvent = new SlimResetEvent(100);
            var start = DateTime.Now;
            var contextReady = false;

            ThreadPool.QueueUserWorkItem(w =>
            {
                using(var plugin = new OpenNiPlugin())
                {
                    plugin.Load();
                    plugin.Enabled = true;

                    while (DateTime.Now.Subtract(start) < timePeriod)
                    {
                        plugin.Update();

                        if (plugin.IsContextReady)
                        {
                            break;
                        }

                        Thread.Sleep(16);
                    }

                    contextReady = plugin.IsContextReady;
                    slimResetEvent.Set();
                }
            });

            slimResetEvent.Wait();

            Assert.True(contextReady);
        }