Example #1
0
        public void ImportType()
        {
            SRM.ImportType(typeof(Contact));

            string script = @"

var t = debug.assert;

var contact = new Contact();

contact.name = 'reo';

t( contact.phoneNumbers != null );

contact.phoneNumbers.add('01-234-567');

t( contact.name, 'reo' );
t( contact.phoneNumbers.length, 1 );
t( contact.phoneNumbers[0], '01-234-567' );

// access invisible property
contact.remark = 'comment';
t( contact.remark, null );

";

            SRM.Run(script);
        }
Example #2
0
        public void AccessProperty()
        {
            // import using alias
            SRM.ImportType(typeof(Friut), "MyClass");

            SRM.Run(@"

var t = debug.assert;

var apple = new MyClass();

apple.name = 'apple';
t(apple.name, 'apple');

apple.Color = 'red';
apple.Price = 1.95;

t(apple.color, 'red');
t(apple.price, 1.95);

t(apple.color + ' ' + apple.price, 'red 1.95');


t( apple['name'], 'apple' );
t( apple['Color'], 'red' );
t( apple['color'], 'red' );
t( apple['price'], '1.95' );

");
        }
Example #3
0
        public void CLRArrayIndexNumber()
        {
            int[] arr = new int[10];

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = i;
            }

            SRM["arr"] = arr;
            SRM.Run(@" 
debug.assert(arr.length, 10);

for(var i=0;i<arr.length;i++) {
  debug.assert( arr[i], i );
}");

            SRM["myarr"] = new MyArrayStub();
            SRM.Run(@"
debug.assert(myarr.length, 10);

for(var i=0;i<myarr.length;i++) {
  myarr[i] = i;
	debug.assert( myarr[i], i );
}");
        }
Example #4
0
        public void EventBindTest()
        {
            var c = new EventStub();

            SRM["c"] = c;

            SRM.Run(@"
var t = debug.assert;
t( c.DummyEvent, null );
var a = 10;
c.DummyEvent = function() {
  a = 20;
};
debug.assertTrue( c.DummyEvent != null, 'event not be attached' );
");

            c.RaiseEvent();

            SRM.Run(@"
t( a, 20 );
t( c.DummyEvent != null );
c.DummyEvent = null;
debug.assertTrue( c.DummyEvent == null, 'event not be detached.' );
");
        }
Example #5
0
        [TestCase(Disabled = true)]       // Not Supported Yet
        public void InnerClasssAccess()
        {
            SRM.ImportType(typeof(StaticA.StaticB));

            SRM.Run(@"
debug.assert( Test.StaticA.StaticB != null );
debug.assert( new StaticB() != null );
");
        }
Example #6
0
        public void FuncCall()
        {
            SRM["myfunc"] = (System.Func <int, int, int>)((a, b) =>
            {
                return(a + b);
            });

            SRM.Run(@"debug.assert( myfunc(1, 2), 3 );");
        }
Example #7
0
        public void IDictionaryEnumeration()
        {
            // import using alias
            SRM["obj"] = new Stuff();

            SRM.Run(@"

");
        }
Example #8
0
        void DictionaryAccess()
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic["name"] = "hello";

            SRM["myobj"] = dic;

            SRM.Run(@" debug.assert( myobj.name, 'hello' ); ");
        }
Example #9
0
        public void StaticMemberModify()
        {
            SRM.ImportType(typeof(StaticClassTest));

            SRM.Run(@"
debug.assert( StaticClassTest != null );
debug.assert( StaticClassTest.a, 10 );
StaticClassTest.a = 20;
debug.assert( StaticClassTest.a, 20 );
");
        }
Example #10
0
        public void ImportNamespace()
        {
            SRM.ImportNamespace("System.Windows.Forms");
            SRM.ImportNamespace("System.Drawing");

            SRM.Run(@"
var t = debug.assert;

t( Color != null );
t( Color.Red != null );

");
        }
Example #11
0
        public void StaticMemberAccess()
        {
            SRM.ImportType(typeof(System.Drawing.Color));

            SRM.Run(@"
debug.assert(Color.Yellow, 'Color [Yellow]');

debug.assert(System.Drawing.SystemColors.Control != null);

debug.assert(Color.Yellow, System.Drawing.Color.Yellow);

");
        }
Example #12
0
        public void CLRArrayPrototype()
        {
            int[] arr = { 1, 2, 3, 4, 5 };

            SRM["arr"] = arr;
            SRM.Run(@"
var t = debug.assert;

t( arr[0], 1 );
t( arr.length, 5 );
t( arr.join('.'), '1.2.3.4.5' );

");
        }
Example #13
0
        public void ImportAndCreate()
        {
            SRM.ImportType(typeof(Friut));

            SRM.Run(@"

var t = debug.assert;

var apple = new Friut();

t(typeof apple, 'native object');
t(apple instanceof Friut);

");
        }
Example #14
0
        public void AccessLowercaseMethod()
        {
            // import using alias
            SRM.ImportType(typeof(Friut), "MyClass");

            SRM.Run(@"

var t = debug.assert;

var apple = new MyClass();
var c = apple.methodInLowercase(5, 6);

t(c, 11);

");
        }
Example #15
0
        public void ImportAndCreate2()
        {
            // import using alias
            SRM.ImportType(typeof(Friut), "MyClass");

            SRM.Run(@"

var t = debug.assert;

var apple = new MyClass();

t(typeof apple, 'native object');
t(apple instanceof MyClass);

");
        }
Example #16
0
        public void AccessMethod()
        {
            // import using alias
            SRM.ImportType(typeof(Friut), "MyClass");

            SRM.Run(@"

var t = debug.assert;

var apple = new MyClass();
apple.shipOut();

t(apple.isShippedOut, true);

");
        }
Example #17
0
        public void CLRArrayIndexString()
        {
            SRM["myarr"] = new MyArrayStub();
            SRM.Run(@"
for(var i=0;i<myarr.length;i++) {
  myarr['item'+i] = i;
	debug.assert( myarr['item'+i], i );
}");

            SRM["mylist"] = new MyListStub();
            SRM.Run(@"
for(var i=0;i<mylist.length;i++) {
  mylist['item' + i] = i;
	debug.assert( mylist['item'+ i], i );
}");
        }
Example #18
0
        public void NewKeyword()
        {
            SRM.ImportType(typeof(ArrayList));

            SRM.Run(@"
var arr1 = new ArrayList();
debug.assert( arr1 != null );

var arr2 = new ArrayList;
debug.assert( arr2 != null );

var alias = ArrayList;
debug.assert( new alias() != null );
debug.assert( new alias != null );

");
        }
Example #19
0
        public void IDictionarySupport()
        {
            // import using alias
            SRM["obj"] = new Stuff();

            SRM.Run(@"

var t = debug.assert;

var date = new Date();

obj.name = 'red alert';
obj.startTime = date;

t(obj.name, 'red alert');
t(obj.startTime, date);

");
        }
Example #20
0
        public void ExtendedObjectValue()
        {
            var extObj = new MyObjectValue();

            SRM["extObj"] = extObj;

            SRM.Run("extObj.testProp = 'a';");
            TestCaseAssertion.AssertTrue(extObj.ValueSetted);              // true
            TestCaseAssertion.AssertTrue(!extObj.ValueGetted);             // false

            SRM.Run("var a = extObj.testProp;");
            TestCaseAssertion.AssertTrue(extObj.ValueSetted);              // true
            TestCaseAssertion.AssertTrue(extObj.ValueGetted);              // true

            extObj = new MyObjectValue();

            //SRM.Run("extObj.testProp = 'a';");
            TestCaseAssertion.AssertTrue(!extObj.ValueSetted);             // true
            TestCaseAssertion.AssertTrue(!extObj.ValueGetted);             // false
        }
Example #21
0
        public void FieldAndEventMember()
        {
            SRM["c"] = new Contact();

            SRM.Run(@"

var t = debug.assert;

c.fieldMember = 10;

t( c.fieldMember, 10 );

c.eventMember = function(){
  this.fieldMember = 20;
};

");

            ((Contact)SRM["c"]).RaiseEventMember();

            SRM.Run(@"

var t = debug.assert;

t( c.fieldMember, 20 );

c.eventMember = null; // remove event
c.fieldMember = 10;

");
            ((Contact)SRM["c"]).RaiseEventMember();

            SRM.Run(@"

var t = debug.assert;

t( c.fieldMember, 10 );

");
        }
Example #22
0
        public void IDictionaryEnumeration()
        {
            // import using alias
            SRM["obj"] = new Stuff();

            SRM.Run(@"

var t = debug.assert;

var date = new Date();

obj.name = 'red alert';
obj.startTime = date;

var o = '';
for(name in obj) {
  o+=name + ' ';
}

t(o, 'name startTime ');

");
        }
Example #23
0
        public void EventTest()
        {
            SRM["c"] = new Contact();

            SRM.Run(@"
var t = debug.assert;
t( c.EventMember, null );
var a = 10;
c.EventMember = function() {
  a = 20;
};
t( c.EventMember != null );
");

            ((Contact)SRM["c"]).RaiseEventMember();

            SRM.Run(@"
t( a, 20 );
t( c.EventMember != null );
c.EventMember = null;
t( c.EventMember, null );
");
        }
Example #24
0
        public void ComparingOperators()
        {
            // import using alias
            SRM.ImportType(typeof(Friut), "MyClass");

            SRM.Run(@"

var t = debug.assert;

var apple = new MyClass();
apple.price = 1.95;

t(apple.price <= 1.95);
t(apple.price >= 1.95);
t(apple.price == 1.95);

t(apple.price == '1.95');         // compare to string

t(apple.price === 1.95);
apple.price = 2.1;
t(apple.price === 2.1);    

");
        }