// Complex struct type test
    static void callBack_RPInvoke_Vector3InComplexStruct(ref ComplexDT arg)
    {
        ComplexDT ret;

        Console.WriteLine("callBack_RPInvoke_Vector3InComplexStruct");
        Console.WriteLine("    Arg ival: {0}", arg.iv);
        Console.WriteLine("    Arg Vector3 v1: ({0} {1} {2})", arg.vecs.a.X, arg.vecs.a.Y, arg.vecs.a.Z);
        Console.WriteLine("    Arg Vector3 v2: ({0} {1} {2})", arg.vecs.b.X, arg.vecs.b.Y, arg.vecs.b.Z);
        Console.WriteLine("    Arg Vector3 v3: ({0} {1} {2})", arg.v3.X, arg.v3.Y, arg.v3.Z);
        Console.WriteLine("    Arg string arg: {0}", arg.str);

        arg.vecs.a.X = arg.vecs.a.X + 1;
        arg.vecs.a.Y = arg.vecs.a.Y + 1;
        arg.vecs.a.Z = arg.vecs.a.Z + 1;
        arg.vecs.b.X = arg.vecs.b.X + 1;
        arg.vecs.b.Y = arg.vecs.b.Y + 1;
        arg.vecs.b.Z = arg.vecs.b.Z + 1;
        arg.v3.X     = arg.v3.X + 1;
        arg.v3.Y     = arg.v3.Y + 1;
        arg.v3.Z     = arg.v3.Z + 1;
        arg.iv       = arg.iv + 1;
        arg.str      = "ret_string";

        Console.WriteLine("    Return ival: {0}", arg.iv);
        Console.WriteLine("    Return Vector3 v1: ({0} {1} {2})", arg.vecs.a.X, arg.vecs.a.Y, arg.vecs.a.Z);
        Console.WriteLine("    Return Vector3 v2: ({0} {1} {2})", arg.vecs.b.X, arg.vecs.b.Y, arg.vecs.b.Z);
        Console.WriteLine("    Return Vector3 v3: ({0} {1} {2})", arg.v3.X, arg.v3.Y, arg.v3.Z);
        Console.WriteLine("    Return string arg: {0}", arg.str);
        float sum = arg.vecs.a.X + arg.vecs.a.Y + arg.vecs.a.Z
                    + arg.vecs.b.X + arg.vecs.b.Y + arg.vecs.b.Z
                    + arg.v3.X + arg.v3.Y + arg.v3.Z;

        Console.WriteLine("    Sum of all return float scalar values = {0}", sum);
    }
Exemple #2
0
    public static bool test() 
    {

        // Expected return value is 12 bytes.
        if (nativeCall_PInvoke_CheckVector3Size() != 12) 
        {
            Console.WriteLine("The size of native Vector3 type is not 12 bytes");
            return false;            
        }

        // Argument passing test.
        // The native code accesses only 12 bytes for each Vector object.
        {
            int iv = 123;
            Vector3 v1 = new Vector3(1,2,3);
            string str = "abcdefg";
            Vector3 v2 = new Vector3(10,11,12);
            // Expected return value = 1 + 2 + 3 + 10 + 11 + 12 = 39
            if (nativeCall_PInvoke_Vector3Arg(iv, v1, str, v2) != 39) 
            {
                Console.Write("PInvoke Vector3Arg test failed\n");
                return false;            
            }
        }
        
        // Argument passing test for Unix.
        // Few arguments are passed onto stack.
        {
            Vector3 v1 = new Vector3(1, 2, 3);
            Vector3 v2 = new Vector3(10, 20, 30);
            float f0 = 100, f1 = 101, f2 = 102, f3 = 103, f4 = 104, f5 = 105, f6 = 106, f7 = 107, f8 = 108;
            
            float sum = nativeCall_PInvoke_Vector3Arg_Unix(
                v1, // register
                f0, f1, f2, f3, f4, f5, // register
                f6, v2,  // stack
                f7, f8); // stack
            if (sum != 1002) {
                Console.Write("PInvoke Vector3Arg_Unix test failed\n");
                return false;            
            }
        }
        
        // Argument passing test for Unix.
        // Few arguments are passed onto stack.
        {
            Vector3 v1 = new Vector3(1, 2, 3);
            Vector3 v2 = new Vector3(4, 5, 6);
            Vector3 v3 = new Vector3(7, 8, 9);
            float f0 = 100, f1 = 101, f2 = 102, f3 = 103, f4 = 104, f5 = 105, f6 = 106, f7 = 107, f8 = 108, f9 = 109;
            
            float sum = nativeCall_PInvoke_Vector3Arg_Unix2(
                v1, // register
                f0, f1, f2, f3, f4, f5, // register
                f6, v2,  // stack
                f7, f8,  // stack
                v3,      // stack
                f9);     // stack
            if (sum != 1090) {
                Console.Write("PInvoke Vector3Arg_Unix2 test failed\n");
                return false;            
            }
        }        
        
        // JIT crashes with this testcase.
        // Disabled temporarily.
        {
            Vector3 ret = nativeCall_PInvoke_Vector3Ret();
            // Expected return value = (1, 2, 3) dot (1, 2, 3) = 14
            float sum = Vector3.Dot(ret, ret);
            if (sum != 14) {
                Console.WriteLine("PInvoke Vector3Ret test failed");
                return false;            
            }
        }
        
        // Array argument test.
        // Both the managed and native code assumes 12 bytes for each element.
        {
            Vector3[] v3_array = new Vector3[2];
            v3_array[0].X = 1; v3_array[0].Y = 2; v3_array[0].Z = 3;
            v3_array[1].X = 5; v3_array[1].Y = 6; v3_array[1].Z = 7;
            // Expected resutn value = 1 + 2 + 3 + 5 + 6 + 7 = 24
            if (nativeCall_PInvoke_Vector3Array(v3_array) != 24) 
            {
                Console.WriteLine("PInvoke Vector3Array test failed");
                return false;            
            }
        }
        
        // Structure pass and return test.
        // Both the managed and native side use 12 bytes for each Vector3 object.
        // Dot product makes sure that the backend assumption 1 and 2 are met.
        {
            DT data = new DT();
            data.a = new Vector3(1,2,3);
            data.b = new Vector3(5,6,7);
            DT ret = nativeCall_PInvoke_Vector3InStruct(data);
            // Expected return value = (2, 3, 4) dot (6, 7, 8) = 12 + 21 + 32 = 65
            float sum = Vector3.Dot(ret.a, ret.b);
            if (sum != 65) 
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed");
                return false;            
            }
        }

        // Complex struct test
        // Dot product makes sure that the backend assumption 1 and 2 are met.
        {
            ComplexDT cdt = new ComplexDT();
            cdt.iv = 99;
            cdt.str = "arg_string";
            cdt.vecs.a = new Vector3(1,2,3);
            cdt.vecs.b = new Vector3(5,6,7);
            cdt.v3 = new Vector3(10, 20, 30);

            nativeCall_PInvoke_Vector3InComplexStruct(ref cdt);
            
            Console.WriteLine("    Managed ival: {0}", cdt.iv);
            Console.WriteLine("    Managed Vector3 v1: ({0} {1} {2})", cdt.vecs.a.X, cdt.vecs.a.Y, cdt.vecs.a.Z);
            Console.WriteLine("    Managed Vector3 v2: ({0} {1} {2})", cdt.vecs.b.X, cdt.vecs.b.Y, cdt.vecs.b.Z);
            Console.WriteLine("    Managed Vector3 v3: ({0} {1} {2})", cdt.v3.X, cdt.v3.Y, cdt.v3.Z);
            Console.WriteLine("    Managed string arg: {0}", cdt.str); 
               
            // (2, 3, 4) dot (6, 7 , 8) = 12 + 21 + 32 = 65
            float t0 = Vector3.Dot(cdt.vecs.a, cdt.vecs.b);
            // (6, 7, 8) dot (11, 21, 31) = 66 + 147 + 248 = 461
            float t1 = Vector3.Dot(cdt.vecs.b, cdt.v3);
            // (11, 21, 31) dot (2, 3, 4) = 209
            float t2 = Vector3.Dot(cdt.v3, cdt.vecs.a);
            float sum = t0 + t1 + t2;
            
            Console.WriteLine("    Managed Sum = {0}", sum);
            if ((sum != 735) || (cdt.iv != 100) || (cdt.str.ToString() != "ret_string"))
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed"); 
                return false;            
            }
        }        

        Console.WriteLine("All PInvoke testcases passed");
        return true;
    }    
Exemple #3
0
 public static extern void nativeCall_PInvoke_Vector3InComplexStruct(ref ComplexDT cdt);
Exemple #4
0
    // Complex struct type test
    static void callBack_RPInvoke_Vector3InComplexStruct(ref ComplexDT arg)
    {   
        ComplexDT ret;
        Console.WriteLine("callBack_RPInvoke_Vector3InComplexStruct");
        Console.WriteLine("    Arg ival: {0}", arg.iv);
        Console.WriteLine("    Arg Vector3 v1: ({0} {1} {2})", arg.vecs.a.X, arg.vecs.a.Y, arg.vecs.a.Z);
        Console.WriteLine("    Arg Vector3 v2: ({0} {1} {2})", arg.vecs.b.X, arg.vecs.b.Y, arg.vecs.b.Z);
        Console.WriteLine("    Arg Vector3 v3: ({0} {1} {2})", arg.v3.X, arg.v3.Y, arg.v3.Z);
        Console.WriteLine("    Arg string arg: {0}", arg.str);        

        arg.vecs.a.X = arg.vecs.a.X + 1;
        arg.vecs.a.Y = arg.vecs.a.Y + 1;
        arg.vecs.a.Z = arg.vecs.a.Z + 1;
        arg.vecs.b.X = arg.vecs.b.X + 1;
        arg.vecs.b.Y = arg.vecs.b.Y + 1;
        arg.vecs.b.Z = arg.vecs.b.Z + 1;
        arg.v3.X = arg.v3.X + 1;
        arg.v3.Y = arg.v3.Y + 1;
        arg.v3.Z = arg.v3.Z + 1;    
        arg.iv = arg.iv + 1;
        arg.str = "ret_string";
        
        Console.WriteLine("    Return ival: {0}", arg.iv);
        Console.WriteLine("    Return Vector3 v1: ({0} {1} {2})", arg.vecs.a.X, arg.vecs.a.Y, arg.vecs.a.Z);
        Console.WriteLine("    Return Vector3 v2: ({0} {1} {2})", arg.vecs.b.X, arg.vecs.b.Y, arg.vecs.b.Z);
        Console.WriteLine("    Return Vector3 v3: ({0} {1} {2})", arg.v3.X, arg.v3.Y, arg.v3.Z);
        Console.WriteLine("    Return string arg: {0}", arg.str);        
        float sum = arg.vecs.a.X + arg.vecs.a.Y + arg.vecs.a.Z
            + arg.vecs.b.X + arg.vecs.b.Y + arg.vecs.b.Z
            + arg.v3.X + arg.v3.Y + arg.v3.Z;
        Console.WriteLine("    Sum of all return float scalar values = {0}", sum);            
    }    
    public static bool test()
    {
        // Expected return value is 12 bytes.
        if (nativeCall_PInvoke_CheckVector3Size() != 12)
        {
            Console.WriteLine("The size of native Vector3 type is not 12 bytes");
            return(false);
        }

        // Argument passing test.
        // The native code accesses only 12 bytes for each Vector object.
        {
            int     iv  = 123;
            Vector3 v1  = new Vector3(1, 2, 3);
            string  str = "abcdefg";
            Vector3 v2  = new Vector3(10, 11, 12);
            // Expected return value = 1 + 2 + 3 + 10 + 11 + 12 = 39
            if (nativeCall_PInvoke_Vector3Arg(iv, v1, str, v2) != 39)
            {
                Console.WriteLine("PInvoke Vector3Arg test failed");
                return(false);
            }
        }

        // Argument passing test for Unix.
        // Few arguments are passed onto stack.
        {
            Vector3 v1 = new Vector3(1, 2, 3);
            Vector3 v2 = new Vector3(10, 20, 30);
            float   f0 = 100, f1 = 101, f2 = 102, f3 = 103, f4 = 104, f5 = 105, f6 = 106, f7 = 107, f8 = 108;

            float sum = nativeCall_PInvoke_Vector3Arg_Unix(
                v1,                     // register
                f0, f1, f2, f3, f4, f5, // register
                f6, v2,                 // stack
                f7, f8);                // stack
            if (sum != 1002)
            {
                Console.WriteLine("PInvoke Vector3Arg_Unix test failed");
                return(false);
            }
        }

        // Argument passing test for Unix.
        // Few arguments are passed onto stack.
        {
            Vector3 v1 = new Vector3(1, 2, 3);
            Vector3 v2 = new Vector3(4, 5, 6);
            Vector3 v3 = new Vector3(7, 8, 9);
            float   f0 = 100, f1 = 101, f2 = 102, f3 = 103, f4 = 104, f5 = 105, f6 = 106, f7 = 107, f8 = 108, f9 = 109;

            float sum = nativeCall_PInvoke_Vector3Arg_Unix2(
                v1,                     // register
                f0, f1, f2, f3, f4, f5, // register
                f6, v2,                 // stack
                f7, f8,                 // stack
                v3,                     // stack
                f9);                    // stack
            if (sum != 1090)
            {
                Console.WriteLine("PInvoke Vector3Arg_Unix2 test failed");
                return(false);
            }
        }

        // Return test
        {
            Vector3 ret = nativeCall_PInvoke_Vector3Ret();
            // Expected return value = (1, 2, 3) dot (1, 2, 3) = 14
            float sum = Vector3.Dot(ret, ret);
            if (sum != 14)
            {
                Console.WriteLine("PInvoke Vector3Ret test failed");
                return(false);
            }
        }

        // Array argument test.
        // Both the managed and native code assumes 12 bytes for each element.
        {
            Vector3[] v3_array = new Vector3[2];
            v3_array[0].X = 1; v3_array[0].Y = 2; v3_array[0].Z = 3;
            v3_array[1].X = 5; v3_array[1].Y = 6; v3_array[1].Z = 7;
            // Expected resutn value = 1 + 2 + 3 + 5 + 6 + 7 = 24
            if (nativeCall_PInvoke_Vector3Array(v3_array) != 24)
            {
                Console.WriteLine("PInvoke Vector3Array test failed");
                return(false);
            }
        }

        // Structure pass and return test.
        // Both the managed and native side use 12 bytes for each Vector3 object.
        // Dot product makes sure that the backend assumption 1 and 2 are met.
        {
            DT data = new DT();
            data.a = new Vector3(1, 2, 3);
            data.b = new Vector3(5, 6, 7);
            DT ret = nativeCall_PInvoke_Vector3InStruct(data);
            // Expected return value = (2, 3, 4) dot (6, 7, 8) = 12 + 21 + 32 = 65
            float sum = Vector3.Dot(ret.a, ret.b);
            if (sum != 65)
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed");
                return(false);
            }
        }

        // Complex struct test
        // Dot product makes sure that the backend assumption 1 and 2 are met.
        {
            ComplexDT cdt = new ComplexDT();
            cdt.iv     = 99;
            cdt.str    = "arg_string";
            cdt.vecs.a = new Vector3(1, 2, 3);
            cdt.vecs.b = new Vector3(5, 6, 7);
            cdt.v3     = new Vector3(10, 20, 30);

            nativeCall_PInvoke_Vector3InComplexStruct(ref cdt);

            Console.WriteLine("    Managed ival: {0}", cdt.iv);
            Console.WriteLine("    Managed Vector3 v1: ({0} {1} {2})", cdt.vecs.a.X, cdt.vecs.a.Y, cdt.vecs.a.Z);
            Console.WriteLine("    Managed Vector3 v2: ({0} {1} {2})", cdt.vecs.b.X, cdt.vecs.b.Y, cdt.vecs.b.Z);
            Console.WriteLine("    Managed Vector3 v3: ({0} {1} {2})", cdt.v3.X, cdt.v3.Y, cdt.v3.Z);
            Console.WriteLine("    Managed string arg: {0}", cdt.str);

            // (2, 3, 4) dot (6, 7 , 8) = 12 + 21 + 32 = 65
            float t0 = Vector3.Dot(cdt.vecs.a, cdt.vecs.b);
            // (6, 7, 8) dot (11, 21, 31) = 66 + 147 + 248 = 461
            float t1 = Vector3.Dot(cdt.vecs.b, cdt.v3);
            // (11, 21, 31) dot (2, 3, 4) = 209
            float t2  = Vector3.Dot(cdt.v3, cdt.vecs.a);
            float sum = t0 + t1 + t2;

            Console.WriteLine("    Managed Sum = {0}", sum);
            if ((sum != 735) || (cdt.iv != 100) || (cdt.str.ToString() != "ret_string"))
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed");
                return(false);
            }
        }

        Console.WriteLine("All PInvoke testcases passed");
        return(true);
    }
 public static extern void nativeCall_PInvoke_Vector3InComplexStruct(ref ComplexDT cdt);
Exemple #7
0
    public static bool test()
    {
        // Expected return value is 12 bytes.
        if (nativeCall_PInvoke_CheckVector3Size() != 12)
        {
            Console.WriteLine("The size of native Vector3 type is not 12 bytes");
            return(false);
        }

        {
            int     iv  = 123;
            Vector3 v1  = new Vector3(1, 2, 3);
            string  str = "abcdefg";
            Vector3 v2  = new Vector3(10, 11, 12);
            // Expected return value = 1 + 2 + 3 + 10 + 11 + 12 = 39
            if (nativeCall_PInvoke_Vector3Arg(iv, v1, str, v2) != 39)
            {
                Console.Write("PInvoke Vector3Arg test failed\n");
                return(false);
            }
        }

        // JIT crashes with this testcase.
        // Disabled temporarily.
        // {
        //     // Expected return value = 1 + 2 + 3 = 6
        //     Vector3 ret = nativeCall_PInvoke_Vector3Ret();
        //     float sum = ret.X + ret.Y + ret.Z;
        //     if (sum != 6) {
        //         Console.WriteLine("PInvoke Vector3Ret test failed");
        //         return false;
        //     }
        // }


        {
            Vector3[] v3_array = new Vector3[2];
            v3_array[0].X = 1; v3_array[0].Y = 2; v3_array[0].Z = 3;
            v3_array[1].X = 5; v3_array[1].Y = 6; v3_array[1].Z = 7;
            // Expected resutn value = 1 + 2 + 3 + 5 + 6 + 7 = 24
            if (nativeCall_PInvoke_Vector3Array(v3_array) != 24)
            {
                Console.WriteLine("PInvoke Vector3Array test failed");
                return(false);
            }
        }

        {
            DT data = new DT();
            data.a = new Vector3(1, 2, 3);
            data.b = new Vector3(5, 6, 7);
            DT ret = nativeCall_PInvoke_Vector3InStruct(data);
            // Expected return value = 2 + 3 + 4 + 6 + 7 + 8 = 30
            float sum = ret.a.X + ret.a.Y + ret.a.Z + ret.b.X + ret.b.Y + ret.b.Z;
            if (sum != 30)
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed");
                return(false);
            }
        }

        {
            ComplexDT cdt = new ComplexDT();
            cdt.iv     = 99;
            cdt.str    = "arg_string";
            cdt.vecs.a = new Vector3(1, 2, 3);
            cdt.vecs.b = new Vector3(5, 6, 7);
            cdt.v3     = new Vector3(10, 20, 30);

            nativeCall_PInvoke_Vector3InComplexStruct(ref cdt);

            Console.WriteLine("    Managed ival: {0}", cdt.iv);
            Console.WriteLine("    Managed Vector3 v1: ({0} {1} {2})", cdt.vecs.a.X, cdt.vecs.a.Y, cdt.vecs.a.Z);
            Console.WriteLine("    Managed Vector3 v2: ({0} {1} {2})", cdt.vecs.b.X, cdt.vecs.b.Y, cdt.vecs.b.Z);
            Console.WriteLine("    Managed Vector3 v3: ({0} {1} {2})", cdt.v3.X, cdt.v3.Y, cdt.v3.Z);
            Console.WriteLine("    Managed string arg: {0}", cdt.str);

            // Expected return value = 2 + 3 + 4 + 6 + 7 + 8 + 11 + 12 + 13 = 93
            float sum = cdt.vecs.a.X + cdt.vecs.a.Y + cdt.vecs.a.Z
                        + cdt.vecs.b.X + cdt.vecs.b.Y + cdt.vecs.b.Z
                        + cdt.v3.X + cdt.v3.Y + cdt.v3.Z;
            if ((sum != 93) || (cdt.iv != 100) || (cdt.str.ToString() != "ret_string"))
            {
                Console.WriteLine("PInvoke Vector3InStruct test failed");
                return(false);
            }
        }

        Console.WriteLine("All PInvoke testcases passed");
        return(true);
    }