public void UndefinedMethodCall()
 {
     Assert.Throws(typeof(Microsoft.Azure.Kinect.Sensor.Test.StubGenerator.NativeFailureException), () =>
     {
         TestNativeMethods.k4a_device_get_installed_count();
     });
 }
        public void STUB_FAIL()
        {
            this.k4a.SetImplementation(@"

uint32_t k4a_device_get_installed_count()
{
    STUB_FAIL(""method failed"");
    return 12;
}");

            Assert.Throws(typeof(Microsoft.Azure.Kinect.Sensor.Test.StubGenerator.NativeFailureException), () =>
            {
                TestNativeMethods.k4a_device_get_installed_count();
            });
        }
        public void BasicMarshalling()
        {
            foreach (UInt32 index in new uint[] { 0, 100, 0xffffffff })
            {
                k4a.SetImplementation($@"

k4a_result_t k4a_device_open(uint32_t index, k4a_device_t *device_handle)
{{
    STUB_ASSERT(index == { index });
    STUB_ASSERT(device_handle != NULL);

    // Assign back a fake value
    *device_handle = (k4a_device_t)0x1234ABCD; 

    return K4A_RESULT_SUCCEEDED;
}}

void k4a_device_close(k4a_device_t device_handle)
{{
    STUB_ASSERT(device_handle == (k4a_device_t)0x1234ABCD);
}}

");


                try
                {
                    TestNativeMethods.k4a_result_t result = TestNativeMethods.k4a_device_open(index, out TestNativeMethods.k4a_device_t handle);
                    Debug.Assert(result == TestNativeMethods.k4a_result_t.K4A_RESULT_SUCCEEDED);

                    Debug.Assert(handle.DangerousGetHandle().ToInt32() == 0x1234abcd);

                    handle.Close();
                    handle.Close();
                }
                catch
                {
                    //NativeMethods.ErrorInfo error = new NativeMethods.ErrorInfo();
                    //error.expression = "Test expression";
                    //NativeMethods.Stub_GetError(ref error);
                    //Console.WriteLine($"{error.szFile}({error.line}) : Assert failed {error.expression}");
                }
            }
        }
        public void RedefineMethod()
        {
            k4a.SetImplementation(@"

uint32_t k4a_device_get_installed_count()
{
    return 12;
}");
            Assert.AreEqual(12, TestNativeMethods.k4a_device_get_installed_count());


            k4a.SetImplementation(@"

uint32_t k4a_device_get_installed_count()
{
    return 55;
}");
            Assert.AreEqual(55, TestNativeMethods.k4a_device_get_installed_count());
        }
 protected override bool ReleaseHandle()
 {
     TestNativeMethods.k4a_device_close(handle);
     return(true);
 }