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>()); } }
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)); } }
public void aliasPrefixTest4() { using (dynamic l = new ConariX(gCfgUnlib)) { l.Prefix = "apiprefix_"; 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"; } l.Aliases["HelloWorld"] = new ProcAlias( xfun, new AliasCfg() { NoPrefixR = true } ); string exp = "Hello World !"; Assert.Equal(exp, l.HelloWorld <CharPtr>()); l.Prefix = ""; Assert.Equal(exp, l.HelloWorld <CharPtr>()); } }
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>())); } }
public void aliasPrefixTest6() { using (dynamic l = new ConariX(gCfgUnlib)) { l.Aliases["GMN1"] = new ProcAlias( "GetMagicNum", new AliasCfg() { NoPrefixR = true } ); l.Aliases["GMN2"] = new ProcAlias( "GetMagicNum", new AliasCfg() { NoPrefixR = false } ); l.Prefix = "apiprefix_"; Assert.Equal(-1, l.GMN1 <int>()); Assert.Equal(4, l.GMN2 <int>()); l.Prefix = ""; Assert.Equal(-1, l.GMN1 <int>()); Assert.Equal(-1, l.GMN2 <int>()); } }
public void aliasTest4() { using (dynamic l = new ConariX(gCfgUnlib)) { UInt32 expected = 0x00001CE8; l.Aliases["addr"] = l.Aliases["_"] = "ADDR_SPEC"; Assert.Equal(expected, (UInt32)l.V.addr); Assert.Equal(expected, l.V._ <UInt32>()); Assert.Equal(expected, (UInt32)l.ExVar.DLR.addr); Assert.Equal(expected, l.ExVar.DLR._ <UInt32>()); Assert.Equal(expected, (UInt32)l.ExVar.get("addr")); Assert.Equal(expected, l.ExVar.get <UInt32>("addr")); Assert.Equal(expected, (UInt32)l.ExVar.getVar("_")); Assert.Equal(expected, l.ExVar.getVar <UInt32>("_")); Assert.Equal(expected, l.ExVar.getField <UInt32>("addr").value); Assert.Equal(expected, l.ExVar.getField(typeof(UInt32), "_").value); } }
public void exvarTest3() { using (dynamic l = new ConariX(gCfgUnlib)) { string expected = "Hello World!"; string fld; if (IntPtr.Size == sizeof(Int64)) { fld = "?eVariableTest@API@UnLib@Conari@r_eg@net@@3PEBDEB"; } else { fld = "?eVariableTest@API@UnLib@Conari@r_eg@net@@3PBDB"; } if (IntPtr.Size == sizeof(Int32)) { Assert.Equal(expected, (CharPtr)l.ExVar.get(fld)); Assert.Equal(expected, (CharPtr)l.ExVar.getVar(fld)); } Assert.Equal(expected, (CharPtr)l.ExVar.get <IntPtr>(fld)); Assert.Equal(expected, (CharPtr)l.ExVar.getVar <IntPtr>(fld)); Assert.Equal(expected, (CharPtr)l.ExVar.getField <IntPtr>(fld).value); Assert.Equal(expected, (CharPtr)l.ExVar.getField(typeof(IntPtr), fld).value); byte[] raw = l.ExVar.getField(typeof(IntPtr).NativeSize(), fld).value; var rawptr = (IntPtr.Size == sizeof(Int64)) ? BitConverter.ToInt64(raw, 0) : BitConverter.ToInt32(raw, 0); Assert.Equal(expected, (CharPtr)rawptr); } }
public void chkTypeTVerTest1() { using (dynamic l = new ConariX(gCfgUnlib)) { TVer v = new TVer(7, 0, 256); Assert.Equal(true, l.chkTypeTVer <bool>(v, 7, 0, 256)); Assert.Equal(false, l.chkTypeTVer <bool>(v, 7, 1, 256)); } }
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))()); } }
public void cacheTest1() { using (dynamic l = new ConariX(gCfgUnlib)) { Assert.Equal(7, l.get_VarSeven <int>()); Assert.Equal(null, l.set_VarSeven(1235)); Assert.Equal(1235, l.get_VarSeven <int>()); Assert.Equal(null, l.set_VarSeven(-44)); Assert.Equal(-44, l.get_VarSeven <int>()); } }
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>())); } }
public void basicTest14() { using (dynamic l = new ConariX(gCfgUnlib)) { Assert.Equal(7, l.get_VarSeven <int>()); Assert.Equal(null, l.set_VarSeven(5)); Assert.Equal(5, l.get_VarSeven <int>()); Assert.Equal(null, l.reset_VarSeven()); Assert.Equal(-1, l.get_VarSeven <int>()); } }
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))()); } }
public void basicTest9() { Assert.Throws <EntryPointNotFoundException>(() => { using (dynamic l = new ConariX(gCfgUnlib)) { l.Mangling = true; l.bind <Func <bool> >("not_real_func_name")(); } }); }
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>())); } }
public void basicTest5() { Assert.Throws <WinFuncFailException>(() => { using (dynamic l = new ConariX(gCfgUnlib)) { l.Mangling = false; l.bind <Func <bool> >("not_real_func_name")(); } }); }
public void callingConvTest2() { using (IConari l = new ConariX( new Config("") { LazyLoading = true }, CallingConvention.Cdecl)) { Assert.Equal(CallingConvention.Cdecl, l.Convention); } }
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>())); } }
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>())); } }
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>())); } }
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>()); } }); }
public void multiAliasTest2() { using (dynamic l = new ConariX(gCfgUnlib)) { l.Aliases["d"] = "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ"; l.Aliases["a"] = l.Aliases["b"] = l.Aliases["c"] = l.Aliases["d"]; Assert.Equal(true, l.a <bool>()); Assert.Equal(true, l.b <bool>()); Assert.Equal(true, l.c <bool>()); Assert.Equal(true, l.d <bool>()); } }
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")()); } }
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")()); } }
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>())); } }
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>()); } }); }
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 })); } }
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>())); } }
public void callingConvTest1() { using (dynamic l = new ConariX( new Config("") { LazyLoading = true })) { Assert.Equal(CallingConvention.Cdecl, l.Convention); l.Convention = CallingConvention.StdCall; Assert.Equal(CallingConvention.StdCall, l.Convention); } }
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>())); } }