Esempio n. 1
0
        public void cacheTest4()
        {
            /*
             *  MethodInfo m = typeof(T).GetMethod("Invoke"); - local
             *  TDyn type = ...from cache
             *  type.dynamic.CreateDelegate(...)
             *     - type.declaringType - failed from another cached TDyn
             *     - m.DeclaringType - should be ok
             *
             *  see `T getDelegate<T>(IntPtr ptr, CallingConvention conv) where T : class`
             */

            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(7, l.get_Seven <ushort>());
                Assert.Equal(7, l.bind <Func <ushort> >("get_Seven")());

                Assert.Equal(7, l.get_Seven <ushort>());
                Assert.Equal(7, l.bind <Func <ushort> >("get_Seven")());
            }

            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(7, l.bind <Func <ushort> >("get_Seven")());
                Assert.Equal(7, l.get_Seven <ushort>());

                Assert.Equal(7, l.bind <Func <ushort> >("get_Seven")());
                Assert.Equal(7, l.get_Seven <ushort>());
            }
        }
Esempio n. 2
0
        public void aliasTest3()
        {
            // char const * net::r_eg::Conari::UnLib::API::getD_HelloWorld(void)
            // x86: ?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPBDXZ
            // x64: ?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPEBDXZ
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string xfun;
                if (IntPtr.Size == sizeof(Int64))
                {
                    xfun = "?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPEBDXZ";
                }
                else
                {
                    xfun = "?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPBDXZ";
                }

                string exp = "Hello World !";
                l.Aliases["getD_HelloWorld"] = new ProcAlias(xfun);

                Assert.Equal(exp, l.getD_HelloWorld <CharPtr>());
                Assert.Equal(exp, l.bind <Func <CharPtr> >("getD_HelloWorld")());

                var dyn = l.bind(Dynamic.GetMethodInfo(typeof(CharPtr)), "getD_HelloWorld");
                Assert.Equal(exp, (CharPtr)dyn.dynamic.Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 3
0
        public void basicTest15()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(7, l.bind(Dynamic.GetMethodInfo(typeof(int)), "get_VarSeven")
                             .dynamic
                             .Invoke(null, null));

                Assert.Null(l.bind(Dynamic.GetMethodInfo(typeof(void), typeof(int)), "set_VarSeven")
                            .dynamic
                            .Invoke(null, new object[] { 5 }));

                Assert.Equal(5, l.bind(Dynamic.GetMethodInfo(typeof(int)), "get_VarSeven")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));

                Assert.Null(l.bind(Dynamic.GetMethodInfo(null), "reset_VarSeven")
                            .dynamic
                            .Invoke(null, null));

                Assert.Equal(-1, l.bind(Dynamic.GetMethodInfo(typeof(int)), "get_VarSeven")
                             .dynamic
                             .Invoke(null, null));
            }
        }
Esempio n. 4
0
 public void cacheTest2()
 {
     using (dynamic l = new ConariX(gCfgUnlib))
     {
         Assert.Equal(7, l.bindFunc <int>("get_VarSeven", typeof(int))());
         Assert.Null(l.bind("set_VarSeven", typeof(void), typeof(int))(1024));
         Assert.Equal(1024, l.bind <int>("get_VarSeven", typeof(int))());
         Assert.Null(l.bind("set_VarSeven", typeof(void), typeof(int))(-4096));
         Assert.Equal(-4096, l.bind <int>("get_VarSeven", typeof(int))());
     }
 }
Esempio n. 5
0
 public void basicTest1()
 {
     using (dynamic l = new ConariX(gCfgUnlib))
     {
         Assert.Equal(true, l.get_True <bool>());
         Assert.True(l.bind <Func <bool> >("get_True")());
         Assert.Equal(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "get_True")
                      .dynamic
                      .Invoke(null, Array.Empty <object>()));
     }
 }
Esempio n. 6
0
 public void basicTest12()
 {
     using (dynamic l = new ConariX(UNLIB_DLL, true))
     {
         Assert.Equal(7, l.bindFunc <int>("get_VarSeven", typeof(int))());
         Assert.Null(l.bind("set_VarSeven", typeof(void), typeof(int))(5));
         Assert.Equal(5, l.bind <int>("get_VarSeven", typeof(int))());
         Assert.Null(l.bind("reset_VarSeven", null)());
         Assert.Equal(-1, (int)l.bind("get_VarSeven", typeof(int))());
     }
 }
Esempio n. 7
0
 public void basicTest2()
 {
     using (dynamic l = new ConariX(gCfgUnlib))
     {
         Assert.Equal(7, l.get_Seven <ushort>());
         Assert.Equal(7, l.bind <Func <ushort> >("get_Seven")());
         Assert.Equal((ushort)7, l.bind(Dynamic.GetMethodInfo(typeof(ushort)), "get_Seven")
                      .dynamic
                      .Invoke(null, Array.Empty <object>()));
     }
 }
Esempio n. 8
0
 public void manglingTest2()
 {
     // unsigned short net::r_eg::Conari::UnLib::API::getD_Seven(void)
     // ?getD_Seven@API@UnLib@Conari@r_eg@net@@YAGXZ
     using (dynamic l = new ConariX(gCfgUnlib))
     {
         Assert.Equal(7, l.bind <Func <ushort> >("?getD_Seven@API@UnLib@Conari@r_eg@net@@YAGXZ")());
         Assert.Equal((ushort)7, l.bind(Dynamic.GetMethodInfo(typeof(ushort)), "?getD_Seven@API@UnLib@Conari@r_eg@net@@YAGXZ")
                      .dynamic
                      .Invoke(null, Array.Empty <object>()));
     }
 }
Esempio n. 9
0
        public void basicTest3()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string exp = "Hello World !";
                Assert.Equal(exp, l.get_HelloWorld <CharPtr>());
                Assert.Equal(exp, l.bind <Func <CharPtr> >("get_HelloWorld")());

                var dyn = l.bind(Dynamic.GetMethodInfo(typeof(CharPtr)), "get_HelloWorld");
                Assert.Equal(exp, (CharPtr)dyn.dynamic.Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 10
0
        public void manglingTest1()
        {
            // bool net::r_eg::Conari::UnLib::API::getD_True(void)
            // ?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ

            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.True(l.bind <Func <bool> >("?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ")());
                Assert.Equal(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 11
0
        public void cacheTest3()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(7, l.bindFunc <Func <int> >("get_VarSeven")());

                l.bind <Action <int> >("set_VarSeven")(1024);
                Assert.Equal(1024, l.bind <Func <int> >("get_VarSeven")());

                l.bind <Action <int> >("set_VarSeven")(-4096);
                Assert.Equal(-4096, l.bind <Func <int> >("get_VarSeven")());
            }
        }
Esempio n. 12
0
        public void basicTest13()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(7, l.bind <Func <int> >("get_VarSeven")());

                l.bind <Action <int> >("set_VarSeven")(5);
                Assert.Equal(5, l.bind <int>("get_VarSeven", typeof(int))());

                l.bind("reset_VarSeven")();
                Assert.Equal(-1, l.bind <Func <int> >("get_VarSeven")());
            }
        }
Esempio n. 13
0
        public void basicTest7()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal((UserSpecUintType)7, l.get_Seven <UserSpecUintType>());
                Assert.Equal((UserSpecUintType)7, l.bind <Func <UserSpecUintType> >("get_Seven")());

                Assert.Equal((UserSpecUintType)7,
                             l.bind(Dynamic.GetMethodInfo(typeof(UserSpecUintType)), "get_Seven")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 14
0
 public void echoTest7()
 {
     using (dynamic l = new ConariX(gCfgUnlib))
     {
         Assert.Equal(0, l.get_IntVal <int>(0));
         Assert.Equal(-456, l.bind <Func <int, int> >("get_IntVal")(-456));
         Assert.Equal(1024, l.bind(Dynamic.GetMethodInfo(typeof(int), typeof(int)), "get_IntVal")
                      .dynamic
                      .Invoke(null, new object[1] {
             1024
         }));
     }
 }
Esempio n. 15
0
        public void manglingTest6()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                l.Mangling = true;

                Assert.Equal(7, l.get_SevenVectorCall <ushort>());
                Assert.Equal(7, l.bind <Func <ushort> >("get_SevenVectorCall")());
                Assert.Equal((ushort)7, l.bind(Dynamic.GetMethodInfo(typeof(ushort)), "get_SevenVectorCall")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 16
0
        public void multiAliasTest1()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                l.Aliases["getD_True"] = "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ";
                l.Aliases["getFlag"]   = l.Aliases["getD_True"];

                Assert.Equal(true, l.getD_True <bool>());
                Assert.Equal(true, l.getFlag <bool>());
                Assert.True(l.bind <Func <bool> >("getFlag")());
                Assert.Equal(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "getFlag")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 17
0
        public void namingTest1()
        {
            using (dynamic l = new ConariX(UNLIB_DLL, true, "apiprefix_"))
            {
                Assert.Equal(4, l.GetMagicNum <int>());

                Assert.Equal(4, l.bind <Func <int> >("GetMagicNum")());
                Assert.Equal(-1, l.bindFunc <Func <int> >("GetMagicNum")());

                Assert.Equal(-1, l.bind(Dynamic.GetMethodInfo(typeof(int)), "GetMagicNum").dynamic.Invoke(null, null));

                Assert.Equal(-1, l.bindFunc <int>("GetMagicNum", typeof(int))());
                Assert.Equal(4, l.bind <int>("GetMagicNum", typeof(int))());
            }
        }
Esempio n. 18
0
        public void aliasTest1()
        {
            // bool net::r_eg::Conari::UnLib::API::getD_True(void)
            // ?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ

            using (dynamic l = new ConariX(UNLIB_DLL, true))
            {
                l.Aliases["getD_True"] = new ProcAlias("?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ");

                Assert.Equal(true, l.getD_True <bool>());
                Assert.True(l.bind <Func <bool> >("getD_True")());
                Assert.Equal(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "getD_True")
                             .dynamic
                             .Invoke(null, Array.Empty <object>()));
            }
        }
Esempio n. 19
0
        public void echoTest5()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string exp = "my string-123 !";

                using (var uns = new UnmanagedString(exp, UnmanagedString.SType.Unicode))
                {
                    WCharPtr wchrptr = uns;

                    Assert.Equal(exp, l.get_WStringPtrVal <WCharPtr>(wchrptr));
                    Assert.Equal(exp, l.bind <Func <WCharPtr, WCharPtr> >("get_WStringPtrVal")(wchrptr));

                    var dyn = l.bind(Dynamic.GetMethodInfo(typeof(WCharPtr), typeof(WCharPtr)), "get_WStringPtrVal");
                    Assert.Equal(exp, (WCharPtr)dyn.dynamic.Invoke(null, new object[] { wchrptr }));
                }
            }
        }
Esempio n. 20
0
        public void echoTest3()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string exp = "my string-123 !";

                using (var uns = new UnmanagedString(exp, UnmanagedString.SType.BSTR))
                {
                    BSTR bstr = uns;

                    Assert.Equal(exp, l.get_BSTRVal <BSTR>(bstr));
                    Assert.Equal(exp, l.bind <Func <BSTR, BSTR> >("get_BSTRVal")(bstr));

                    var dyn = l.bind(Dynamic.GetMethodInfo(typeof(BSTR), typeof(BSTR)), "get_BSTRVal");
                    Assert.Equal(exp, (BSTR)dyn.dynamic.Invoke(null, new object[] { bstr }));
                }
            }
        }
Esempio n. 21
0
        public void echoTest1()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string exp = "my string-123 !";

                using (var uns = new UnmanagedString(exp, UnmanagedString.SType.Ansi))
                {
                    CharPtr chrptr = uns;

                    Assert.Equal(exp, l.get_CharPtrVal <CharPtr>(chrptr));
                    Assert.Equal(exp, l.bind <Func <CharPtr, CharPtr> >("get_CharPtrVal")(chrptr));

                    var dyn = l.bind(Dynamic.GetMethodInfo(typeof(CharPtr), typeof(CharPtr)), "get_CharPtrVal");
                    Assert.Equal(exp, (CharPtr)dyn.dynamic.Invoke(null, new object[] { chrptr }));
                }
            }
        }
Esempio n. 22
0
 public void basicTest9()
 {
     Assert.Throws <EntryPointNotFoundException>(() =>
     {
         using (dynamic l = new ConariX(gCfgUnlib))
         {
             l.Mangling = true;
             l.bind <Func <bool> >("not_real_func_name")();
         }
     });
 }
Esempio n. 23
0
 public void basicTest5()
 {
     Assert.Throws <WinFuncFailException>(() =>
     {
         using (dynamic l = new ConariX(gCfgUnlib))
         {
             l.Mangling = false;
             l.bind <Func <bool> >("not_real_func_name")();
         }
     });
 }
Esempio n. 24
0
        public void echoTest6()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                Assert.Equal(false, l.get_BoolVal <bool>(false));
                Assert.False(l.bind <Func <bool, bool> >("get_BoolVal")(false));
                Assert.Equal(false, l.bind(Dynamic.GetMethodInfo(typeof(bool), typeof(bool)), "get_BoolVal")
                             .dynamic
                             .Invoke(null, new object[1] {
                    false
                }));

                Assert.Equal(true, l.get_BoolVal <bool>(true));
                Assert.True(l.bind <Func <bool, bool> >("get_BoolVal")(true));
                Assert.Equal(true, l.bind(Dynamic.GetMethodInfo(typeof(bool), typeof(bool)), "get_BoolVal")
                             .dynamic
                             .Invoke(null, new object[1] {
                    true
                }));
            }
        }
Esempio n. 25
0
 public void basicTest10()
 {
     Assert.Throws <EntryPointNotFoundException>(() =>
     {
         using (dynamic l = new ConariX(gCfgUnlib))
         {
             l.Mangling = true;
             l.bind(Dynamic.GetMethodInfo(typeof(bool)), "not_real_func_name")
             .dynamic
             .Invoke(null, Array.Empty <object>());
         }
     });
 }
Esempio n. 26
0
 public void basicTest6()
 {
     Assert.Throws <WinFuncFailException>(() =>
     {
         using (dynamic l = new ConariX(gCfgUnlib))
         {
             l.Mangling = false;
             l.bind(Dynamic.GetMethodInfo(typeof(bool)), "not_real_func_name")
             .dynamic
             .Invoke(null, Array.Empty <object>());
         }
     });
 }
Esempio n. 27
0
        public void manglingTest8()
        {
            using dynamic l = new ConariX(gCfgUnlib)
                  {
                      Mangling = false
                  };

            var xfun = l.bind <Func <ushort> >("get_SevenStdCall");

            if (IntPtr.Size == sizeof(Int64))
            {
                Assert.Equal((ushort)7, xfun());
                return;
            }

            Assert.Throws <WinFuncFailException>(() =>
            {
                xfun();
            });
        }
Esempio n. 28
0
        public void stringTest4()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                string exp = "mystring-123 !";

                using (var uns1 = new UnmanagedString(exp, UnmanagedString.SType.Unicode))
                    using (var uns2 = new UnmanagedString(exp, UnmanagedString.SType.Unicode))
                        using (var uns3 = new UnmanagedString(" " + exp, UnmanagedString.SType.Unicode))
                        {
                            WCharPtr chrptr  = uns1;
                            WCharPtr chrptr2 = uns2;

                            Assert.Equal(true, l.get_WStringPtrCmpRef <bool>(chrptr, chrptr2));
                            Assert.True(l.bind <Func <WCharPtr, WCharPtr, bool> >("get_WStringPtrCmpRef")(chrptr, chrptr2));

                            Assert.Equal(false, l.get_WStringPtrCmpRef <bool>(chrptr, (WCharPtr)uns3));
                        }
            }
        }
Esempio n. 29
0
        public void manglingTest9()
        {
            using dynamic l = new ConariX(gCfgUnlib)
                  {
                      Mangling = false
                  };

            var xfun = l.bind(Dynamic.GetMethodInfo(typeof(ushort)), "get_SevenStdCall")
                       .dynamic;

            if (IntPtr.Size == sizeof(Int64))
            {
                Assert.Equal((ushort)7, xfun.Invoke(null, Array.Empty <object>()));
                return;
            }

            Assert.Throws <WinFuncFailException>(() =>
            {
                xfun.Invoke(null, Array.Empty <object>());
            });
        }
Esempio n. 30
0
        public void complexTest1()
        {
            using (dynamic l = new ConariX(gCfgUnlib))
            {
                IntPtr ptr1 = l.get_TSpec <IntPtr>();
                IntPtr ptr2 = l.bind <Func <IntPtr> >("get_TSpec")();

                var    dyn  = l.bind(Dynamic.GetMethodInfo(typeof(IntPtr)), "get_TSpec");
                IntPtr ptr3 = (IntPtr)dyn.dynamic.Invoke(null, Array.Empty <object>());

                Assert.NotEqual(IntPtr.Zero, ptr1);
                Assert.True(ptr1 == ptr2 && ptr2 == ptr3);

                /*
                 *  struct TSpec
                 *  {
                 *      BYTE a;
                 *      int b;
                 *      char* name;
                 *  };
                 *
                 *  s->a    = 2;
                 *  s->b    = 4;
                 *  s->name = "Conari";
                 *
                 */
                var TSpecPtr = NativeData
                               ._(ptr1)
                               .t <int, int>("a", "b")
                               .t <CharPtr>("name");
                //.AlignSizeByMax; // byte = 4 / int = 4 / ptrx64 = 8

                byte[]  bytes  = TSpecPtr.Raw.Values;
                dynamic dlr    = TSpecPtr.Raw.Type;
                var     fields = TSpecPtr.Raw.Type.Fields;

                Assert.Equal(3, fields.Count);

                int    expA    = 2;
                int    expB    = 4;
                string expName = "Conari";

                // a
                Assert.Equal("a", fields[0].name);
                Assert.Equal(NativeData.SizeOf <int>(), fields[0].tsize);
                Assert.Equal(typeof(int), fields[0].type);
                Assert.Equal(expA, fields[0].value);

                // b
                Assert.Equal("b", fields[1].name);
                Assert.Equal(NativeData.SizeOf <int>(), fields[1].tsize);
                Assert.Equal(typeof(int), fields[1].type);
                Assert.Equal(expB, fields[1].value);

                // name
                Assert.Equal("name", fields[2].name);
                Assert.Equal(CharPtr.PtrSize, fields[2].tsize);
                Assert.Equal(typeof(CharPtr), fields[2].type);
                Assert.Equal(expName, (CharPtr)fields[2].value);

                // DLR
                Assert.Equal(expA, dlr.a);
                Assert.Equal(expB, dlr.b);
                Assert.Equal(expName, (CharPtr)dlr.name);

                // byte-seq
                var br = new BReader(bytes);
                Assert.Equal(expA, br.next <int>(NativeData.SizeOf <int>()));
                Assert.Equal(expB, br.next <int>(NativeData.SizeOf <int>()));
                Assert.Equal(expName, (CharPtr)br.next <CharPtr>(NativeData.SizeOf <CharPtr>()));
            }
        }