Beispiel #1
0
        public static void Tests_IllegalCalls()
        {
            var module_ = ScriptEngine.GetModule("test", asEGMFlags.asGM_ALWAYS_CREATE);

            module_.AddScriptSection("test", @"
int foo()
{
    return 1;
}
class TestClass
{
    int field;
    int method()
    {
        return field;
    }
}
TestClass Obj();
");
            module_.Build();
            var module = module_ as dynamic;

            try
            {
                module.Foobar();
                Tests.Assert(false, "Calling nonexisting function");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Calling nonexisting function");
            }
            try
            {
                var x = module.Ohmy;
                Tests.Assert(false, "Getting nonexisting global variable");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Getting nonexisting global variable");
            }
            try
            {
                module.Woosh = 5;
                Tests.Assert(false, "Setting nonexisting global variable");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Setting nonexisting global variable");
            }
            try
            {
                module.Obj.Boo();
                Tests.Assert(false, "Calling nonexisting method");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Calling nonexisting method");
            }
            try
            {
                var f = module.Obj.Field;
                Tests.Assert(false, "Getting nonexisting field");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Getting nonexisting field");
            }
            try
            {
                module.Obj.BrtmBrtm = 55;
                Tests.Assert(false, "Setting nonexisting field");
            }
            catch (RuntimeBinderException)
            {
                Tests.Assert(true, "Setting nonexisting field");
            }
        }
Beispiel #2
0
 static void assert(bool cond, string msg)
 {
     Tests.Assert(cond, msg);
 }