Пример #1
0
        static void Main()
        {
            {
                TestLogger.Log("Testing Boolean.ToString...");
                TestLogger.Log(true.ToString());
                TestLogger.Log(false.ToString());
            }

            {
                var result = false;
                TestLogger.Log("Testing Boolean.TryParse...");

                TestLogger.Log(Boolean.TryParse("True", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("true", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("TRUE", out result).ToString());
                TestLogger.Log(result);

                TestLogger.Log(Boolean.TryParse("Frue", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("false", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("FALSE", out result).ToString());
                TestLogger.Log(result);

                TestLogger.Log(Boolean.TryParse("1", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("0", out result).ToString());
                TestLogger.Log(result);
                TestLogger.Log(Boolean.TryParse("Bad", out result).ToString());
                TestLogger.Log(result);
            }

            {
                TestLogger.Log("Testing DateTime.ToString...");
                var time = new DateTime(1979, 7, 31, 10, 25, 0);
                TestLogger.Log(time.ToString());
            }

            {
                TestLogger.Log("Testing String.Empty...");
                TestLogger.Log(String.Empty.Length);
            }

            {
                TestLogger.Log("Testing String.Equals...");
                TestLogger.Log(String.Equals("True", "True"));
                TestLogger.Log(String.Equals("True", "true"));
                TestLogger.Log(String.Equals("True", "False"));
                TestLogger.Log(String.Equals("True", "false"));

                TestLogger.Log(String.Equals("True", "True", StringComparison.Ordinal));
                TestLogger.Log(String.Equals("True", "true", StringComparison.Ordinal));
                TestLogger.Log(String.Equals("True", "False", StringComparison.Ordinal));
                TestLogger.Log(String.Equals("True", "false", StringComparison.Ordinal));

                TestLogger.Log(String.Equals("True", "True", StringComparison.OrdinalIgnoreCase));
                TestLogger.Log(String.Equals("True", "true", StringComparison.OrdinalIgnoreCase));
                TestLogger.Log(String.Equals("True", "False", StringComparison.OrdinalIgnoreCase));
                TestLogger.Log(String.Equals("True", "false", StringComparison.OrdinalIgnoreCase));
            }

            {
                TestLogger.Log("Testing String.ToUpper...");
                TestLogger.Log("True".ToUpper());
                TestLogger.Log("true".ToUpper());
                TestLogger.Log("TRUE".ToUpper());
            }

            {
                TestLogger.Log("Testing String.ToUpper...");
                TestLogger.Log("True".ToLower());
                TestLogger.Log("true".ToLower());
                TestLogger.Log("TRUE".ToLower());
            }

            {
                TestLogger.Log("Testing String.IsNullOrEmpty...");
                TestLogger.Log(String.IsNullOrEmpty(String.Empty));
                TestLogger.Log(String.IsNullOrEmpty(null));
                TestLogger.Log(String.IsNullOrEmpty(""));
                TestLogger.Log(String.IsNullOrEmpty("a"));
            }

            {
                TestLogger.Log("Testing String.Format...");
                TestLogger.Log(String.Format("0"));
                TestLogger.Log(String.Format("0", "arg0"));
                TestLogger.Log(String.Format("0", "arg0", "arg1"));
                TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2", "arg3"));
                TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2", "arg3", "arg4"));

                try { TestLogger.Log(String.Format("1 {0}")); }
                catch (Exception e) { TestLogger.LogException(e); }
                TestLogger.Log(String.Format("1 {0}", "arg0"));
                TestLogger.Log(String.Format("1 {0}", "arg0", "arg1"));
                TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2", "arg3"));
                TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2", "arg3", "arg4"));

                try { TestLogger.Log(String.Format("2 {0} {1}")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("2 {0} {1}", "arg0")); }
                catch (Exception e) { TestLogger.LogException(e); }
                TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1"));
                TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2", "arg3"));
                TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2", "arg3", "arg4"));

                try { TestLogger.Log(String.Format("3 {0} {1} {2}")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1")); }
                catch (Exception e) { TestLogger.LogException(e); }
                TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2", "arg3"));
                TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2", "arg3", "arg4"));

                try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2")); }
                catch (Exception e) { TestLogger.LogException(e); }
                TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2", "arg3"));
                TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2", "arg3", "arg4"));

                try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2")); }
                catch (Exception e) { TestLogger.LogException(e); }
                try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2", "arg3")); }
                catch (Exception e) { TestLogger.LogException(e); }
                TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2", "arg3", "arg4"));

                TestLogger.Log(String.Format("Skip {0} {1}", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("Skip {0} {2}", "arg0", "arg1", "arg2"));
                TestLogger.Log(String.Format("Skip {1} {2}", "arg0", "arg1", "arg2"));
            }

            {
                TestLogger.Log("Testing String.Split...");
                foreach (var item in "a,b,c,d,efghi,j".Split(','))
                {
                    TestLogger.Log(item);
                }
            }

            {
                TestLogger.Log("Testing String.Substring...");
                string a = "1234567890";
                TestLogger.Log(a.Substring(2, 5));
            }

            {
                TestLogger.Log("Testing String.Join...");
                TestLogger.Log(string.Join(",", new string[] { "a", "b", "c", "def", "ghi" }));
            }

            {
                TestLogger.Log("Testing IndexOf(str)...");
                TestLogger.Log("abcdefg".IndexOf("abcdefg"));
                TestLogger.Log("abcdefg".IndexOf("abc"));
                TestLogger.Log("abcdefg".IndexOf("bcd"));
                TestLogger.Log("abcdefg".IndexOf("efg"));
                TestLogger.Log("abcdefg".IndexOf(""));
                TestLogger.Log("abcdefg".IndexOf("___"));
                try { TestLogger.Log("abcdefg".IndexOf(null)); }
                catch (ArgumentNullException) { TestLogger.Log("ArgumentNullException"); }

                TestLogger.Log("Testing IndexOf(char)...");
                TestLogger.Log("abcdefg".IndexOf('A'));
                TestLogger.Log("abcdefg".IndexOf('z'));
                TestLogger.Log("abcdefg".IndexOf('d'));
                TestLogger.Log("abcdefg".IndexOf('g'));
                TestLogger.Log("abcdefg".IndexOf('a'));

                TestLogger.Log("Testing IndexOf scenario...");
                const char   Separator    = '|';
                const string TestStr      = "This|is|a|test";
                int          invalidIndex = TestStr.IndexOf(Separator);
                TestLogger.Log(invalidIndex);

                int validIndex = TestStr.IndexOf(Separator.ToString());
                TestLogger.Log(validIndex);
            }

            {
                TestLogger.Log("Testing LastIndexOf(string)...");
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("abcdefg"));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("abc"));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("bcd"));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("efg"));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("") + 100);
                TestLogger.Log("".LastIndexOf("") + 200);
                TestLogger.Log("a".LastIndexOf("") + 300);
                TestLogger.Log("abcdefgabcdefg".LastIndexOf("___"));
                try { TestLogger.Log("abcdefgabcdefg".LastIndexOf(null)); }
                catch (ArgumentNullException) { TestLogger.Log("ArgumentNullException"); }

                TestLogger.Log("Testing LastIndexOf(char)...");
                TestLogger.Log("abcdefgabcdefg".LastIndexOf('A'));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf('z'));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf('d'));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf('g'));
                TestLogger.Log("abcdefgabcdefg".LastIndexOf('a'));
            }

            {
                TestLogger.Log("Testing basic string append...");
                StringBuilder sb = new StringBuilder();
                sb.Append("a");
                sb.Append("b");
                TestLogger.Log(sb.ToString());
            }

            {
                var mixedArray = new Dummy[3];
                mixedArray[0] = new Dummy();
                mixedArray[1] = null;

                TestLogger.Log("Testing char to string...");
                TestLogger.Log(('c').ToString());

                TestLogger.Log("Testing special append...");
                StringBuilder sb = new StringBuilder();
                sb.Append("a");
                sb.Append("");
                sb.Append((string)null);
                sb.Append(1);
                sb.Append(2.0);
                sb.Append(mixedArray[0]); // object with tostring
                sb.Append(mixedArray[1]); // null
                sb.Append(mixedArray[2]); // undefined
                sb.Append('c');
                sb.Append("b");
                TestLogger.Log(sb.ToString());
            }

            {
                TestLogger.Log("Testing nested append...");
                StringBuilder sb = new StringBuilder();
                sb.Append("a");
                StringBuilder nested = new StringBuilder();
                nested.Append("{");
                nested.Append("b");
                nested.Append("}");
                sb.Append(nested.ToString());
                sb.Append("|");
                sb.Append(nested);
                sb.Append("c");
                TestLogger.Log(sb.ToString());
            }
        }
Пример #2
0
        static void Main()
        {
            {
                TestLogger.Log("Testing names...");
                TestLogger.Log(typeof(DerivedClass).Name);
                TestLogger.Log(typeof(DerivedClass).Namespace);
                TestLogger.Log(typeof(DerivedClass).FullName);
            }

            {
                TestLogger.Log("Testing Invoke...");
                typeof(BaseClass).GetMethod("Test").Invoke(new BaseClass(), null);
                typeof(BaseClass).GetMethod("Test").Invoke(new DerivedClass(), null);
                try
                {
                    typeof(DerivedClass).GetMethod("Test").Invoke(new BaseClass(), null);
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                typeof(DerivedClass).GetMethod("Test").Invoke(new DerivedClass(), null);
            }

            {
                TestLogger.Log("Testing SetValue on value type...");
                var b = new DerivedClass();
                typeof(DerivedClass).GetProperty("A").SetValue(b, 5, null);
                TestLogger.Log(b.A);
                TestLogger.Log(typeof(DerivedClass).GetProperty("A").GetValue(b, null).ToString());
            }

            {
                TestLogger.Log("Testing SetValue on reference type...");
                var b = new DerivedClass();
                typeof(DerivedClass).GetProperty("B").SetValue(b, "test", null);
                TestLogger.Log(b.B);
                TestLogger.Log(typeof(DerivedClass).GetProperty("B").GetValue(b, null).ToString());
            }

            {
                TestLogger.Log("Testing generic construction...");
                var i = GenericNew <TestClass>();
                i.Method();
            }

            {
                TestLogger.Log("Testing assembly loading...");
#if IL2JS
                // Assuming assembly name resolution is 'Name'
                var assembly = Assembly.Load("IL2JS_Tests_ReflectionBase_IL2JS");
#else
                var assembly = Assembly.Load("IL2JS_Tests_ReflectionBase_WSH, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
#endif
                TestLogger.Log(NA(assembly.FullName));
                var type     = assembly.GetType("Microsoft.LiveLabs.JavaScript.Tests.BaseClass");
                var instance = (BaseClass)Activator.CreateInstance(type);
                instance.Test();
            }

            // DISABLED: Only types with [Reflection(ReflectionLevel.Name)] or greater support names
#if false
            {
                TestLogger.Log("Testing names...");
                Type tp;

                tp = typeof(System.Object);
                TestLogger.Log("System.Object: tp.Name: " + tp.Name);
                TestLogger.Log("System.Object: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("System.Object: tp.FullName: " + NA(tp.FullName));

                tp = typeof(System.String);
                TestLogger.Log("System.String: tp.Name: " + tp.Name);
                TestLogger.Log("System.String: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("System.String: tp.FullName: " + NA(tp.FullName));

                tp = typeof(TestClass);
                TestLogger.Log("TestClass: tp.Name: " + tp.Name);
                TestLogger.Log("TestClass: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("TestClass: tp.FullName: " + NA(tp.FullName));

                tp = typeof(TestClass[]);
                TestLogger.Log("TestClass[]: tp.Name: " + tp.Name);
                TestLogger.Log("TestClass[]: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("TestClass[]: tp.FullName: " + NA(tp.FullName));

                tp = typeof(int?);
                TestLogger.Log("int?: tp.Name: " + tp.Name);
                TestLogger.Log("int?: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("int?: tp.FullName: " + NA(tp.FullName));

                tp = typeof(int?[]);
                TestLogger.Log("int?[]: tp.Name: " + tp.Name);
                TestLogger.Log("int?[]: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("int?[]: tp.FullName: " + NA(tp.FullName));

                tp = typeof(int[][]);
                TestLogger.Log("int[][]: tp.Name: " + tp.Name);
                TestLogger.Log("int[][]: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("int[][]: tp.FullName: " + NA(tp.FullName));

                tp = typeof(TestStruct?);
                TestLogger.Log("TestStruct?: tp.Name: " + tp.Name);
                TestLogger.Log("TestStruct?: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("TestStruct?: tp.FullName: " + NA(tp.FullName));

                tp = typeof(List <TestClass>[]);
                TestLogger.Log("List<TestClass>[]: tp.Name: " + tp.Name);
                TestLogger.Log("List<TestClass>[]: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("List<TestClass>[]: tp.FullName: " + NA(tp.FullName));

                tp = typeof(OuterClassNonGeneric.NestedClassNonGeneric);
                TestLogger.Log("OuterClassNonGeneric.NestedClassNonGeneric: tp.Name: " + tp.Name);
                TestLogger.Log("OuterClassNonGeneric.NestedClassNonGeneric: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("OuterClassNonGeneric.NestedClassNonGeneric: tp.FullName: " + NA(tp.FullName));

                tp = typeof(OuterClassNonGeneric.NestedClassGeneric <int>);
                TestLogger.Log("OuterClassNonGeneric.NestedClassGeneric<int>: tp.Name: " + tp.Name);
                TestLogger.Log("OuterClassNonGeneric.NestedClassGeneric<int>: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("OuterClassNonGeneric.NestedClassGeneric<int>: tp.FullName: " + NA(tp.FullName));

                tp = typeof(OuterClassGeneric <string> .NestedClassNonGeneric);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassNonGeneric: tp.Name: " + tp.Name);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassNonGeneric: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassNonGeneric: tp.FullName: " + NA(tp.FullName));

                tp = typeof(OuterClassGeneric <string> .NestedClassGeneric <List <string> >);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassGeneric<List<string>>: tp.Name: " + tp.Name);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassGeneric<List<string>>: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("OuterClassGeneric<string>.NestedClassGeneric<List<string>>: tp.FullName: " + NA(tp.FullName));

                tp = typeof(OuterClassGeneric <List <int>[]> .NestedClassGeneric <List <string>[]>[]);
                TestLogger.Log("OuterClassGeneric<List<int>[]>.NestedClassGeneric<List<string>[]>[]: tp.Name: " + tp.Name);
                TestLogger.Log("OuterClassGeneric<List<int>[]>.NestedClassGeneric<List<string>[]>[]: tp.Namespace: " + tp.Namespace);
                TestLogger.Log("OuterClassGeneric<List<int>[]>.NestedClassGeneric<List<string>[]>[]: tp.FullName: " + NA(tp.FullName));
            }
#endif

            {
                TestLogger.Log("Testing custom attributes...");
                foreach (var o in typeof(TestClass).GetCustomAttributes(false))
                {
                    TestLogger.Log(o.GetType().Name);
                    var ta = o as TestAttribute;
                    if (ta != null)
                    {
                        TestLogger.Log(ta.One);
                        TestLogger.Log(ta.Two);
                    }
                }
            }

            {
                TestLogger.Log("Testing GetFields...");
                foreach (var f in typeof(DerivedClass).GetFields())
                {
                    TestLogger.Log(f.Name);
                }
                TestLogger.Log("Testing GetMethods...");
                var nms = new List <string>();
                foreach (var m in typeof(DerivedClass).GetMethods())
                {
                    // Object is not marked as [Reflection(ReflectionLevel.Full)]
                    if (!m.DeclaringType.IsAssignableFrom(typeof(Object)))
                    {
                        nms.Add(m.Name);
                    }
                }
                nms.Sort((l, r) => string.Compare(l, r, StringComparison.Ordinal));
                foreach (var nm in nms)
                {
                    TestLogger.Log(nm);
                }
                TestLogger.Log("Testing GetProperties...");
                foreach (var p in typeof(DerivedClass).GetProperties())
                {
                    TestLogger.Log(p.Name);
                }
                TestLogger.Log("Testing GetEvents...");
                foreach (var e in typeof(DerivedClass).GetEvents())
                {
                    TestLogger.Log(e.Name);
                }
            }
        }
Пример #3
0
        private static void Run()
        {
            {
                TestLogger.Log("Testing basic interop...");
                var fso    = new FileSystemObject();
                var drive1 = fso.GetDrive("C:");
                var drive2 = fso.GetDrive("C:");
                TestLogger.Log(drive1.FreeSpace == drive2.FreeSpace);
            }

            {
                TestLogger.Log("Tesing getters...");
                var prop = new PropertyTest();
                prop.Setup();
                TestLogger.Log(prop.X);
            }

            {
                TestLogger.Log("Testing virtuals...");
                var b = new VirtualsBase();
                TestLogger.Log(b.V());
                TestLogger.Log(b.CallV());
                TestLogger.Log(b.U());
                var d = (VirtualsBase) new VirtualsDerived();
                TestLogger.Log(d.V());
                TestLogger.Log(d.CallV());
                TestLogger.Log(d.U());
            }

            {
                TestLogger.Log("Testing JSObject...");
                var obj = new JSObject
                {
                    { "int", 1 },
                    { "string", "two" },
                    { "object", new JSObject {
                          { "inner", 3 }, { "null", null }
                      } }
                };
                TestLogger.Log(obj.GetField <int>("int"));
                TestLogger.Log(obj.GetField <string>("string"));
                TestLogger.Log(obj.GetField <JSObject>("object").GetField <int>("inner"));
            }

            {
                TestLogger.Log("Testing exceptions...");
                var obj = new JSObject {
                    { "int", 1 }, { "string", "two" }
                };
                try
                {
                    // Invalid cast
                    var dummy = obj.GetField <int[]>("int");
                    TestLogger.Log(dummy.ToString());
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                try
                {
                    // User exception
                    TestException.ThrowFromUnmanaged();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                // Managed -> unmanaged exception
                TestException.CatchFromManagedInUnmanaged();
                try
                {
                    // Managed -> unmanaged -> managed exception
                    TestException.ThrowViaUnmanaged();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                // Unmanaged -> managed -> unmanaged -> catch
                TestException.CatchViaManagedInUnmanaged();
                try
                {
                    // Unmanaged exception
                    TestException.InvalidJavaScript();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
            }

            {
                TestLogger.Log("Testing JSArray...");
                var arr = JSArray.FromArray(0, 1, "two", new JSObject {
                    { "value", 3 }
                }, new JSObject {
                    { "value", "four" }
                });
                TestLogger.Log(arr.Length);
                TestLogger.Log(arr[0].ToString());
                TestLogger.Log(arr[1].ToString());
                TestLogger.Log(arr[2].ToString());
                TestLogger.Log(arr[3].GetField <int>("value"));
                TestLogger.Log(arr[4].GetField <string>("value"));
            }

            {
                TestLogger.Log("Testing polymorphic method of higher-kinded type...");
                var t1 = new TestGeneric <int>(1);
                TestLogger.Log(t1.M <string>("two"));
                var obj = new JSObject();
                obj.SetField("f", "field");
                var t2 = new TestGeneric <JSObject>(obj);
                TestLogger.Log(t2.M <int>(3));
                TestLogger.Log(t2.M <JSObject>(obj));
            }

            {
                TestLogger.Log("Testing exported instance methods in base types...");
                var d = new TestGenericDerived <int>();
                d.Value      = new int[] { 1, 2, 3 };
                d.OtherValue = 4;
                TestLogger.Log(d.N());
            }

            {
                TestLogger.Log("Testing delegates...");
                TestLogger.Log(TestDelegate.TestWithDelegate());
                TestLogger.Log
                    (TestDelegate.WithManagedDelegate
                        ((i, obj) =>
                        new JSObject {
                    { "test", i.ToString() + " " + obj.GetField <int>("test").ToString() }
                },
                        new JSObject {
                    { "test", 7 }
                }));
            }

            {
                TestLogger.Log("Testing param arrays...");
                TestLogger.Log(TestParams.JoinA(3, 7, "a", "b", "c"));
                TestLogger.Log(TestParams.TestB());
                ParamsDelegate f = TestParams.JoinA;
                TestLogger.Log(TestParams.Call(f));
                var g = TestParams.GetTestB();
                TestLogger.Log(g(3, 7, "a", "b", "c"));
            }

            {
                TestLogger.Log("Testing proxied object...");
                var p = new ProxiedTest();
                TestLogger.Log(ProxiedBase.TestGlobal);
                TestLogger.Log(p.One);
                TestLogger.Log(p.Two);
                TestLogger.Log(p.Three.GetField <int>("value"));
                TestLogger.Log(p.GetValue());
                p.One   = 11;
                p.Two   = "twenty-two";
                p.Three = new JSObject {
                    { "value", 55 }
                };
#if true
                // BROKEN: Polymorphic delegates
                p.Delegate = i => TestLogger.Log(i);
#endif
                TestLogger.Log(p.One);
                TestLogger.Log(p.Two);
                TestLogger.Log(p.Three.GetField <int>("value"));
#if true
                // BROKEN: Polymorphic delegates
                p.Delegate(7);
#endif
                TestLogger.Log(p.GetValue());
                p.Morph();
                // TODO: Managed Interop will not notice '2' is an int rather than a string
#if false
                try
                {
                    TestLogger.Log(p.Two);
                }
                catch (InvalidCastException e)
                {
                    TestLogger.LogException(e);
                }
#endif
                var obj = JSObject.From(p);
                TestLogger.Log(obj.GetField <int>("two"));
                obj.SetField <int>("one", 111);
                TestLogger.Log(p.One);
                p.One = 1111;
                TestLogger.Log(obj.GetField <int>("one"));
            }

            {
                TestLogger.Log("Testing keyed object...");
                var k = new KeyedTest(1, "two", 3, "four");
                TestLogger.Log(k.I);
                TestLogger.Log(k.S);
                TestLogger.Log(k.X);
                TestLogger.Log(k.Y);
                k.I = 11;
                k.X = 33;
                TestLogger.Log(k.I);
                TestLogger.Log(k.X);
                var k2 = k.Clone();
                TestLogger.Log(k2.I);
                TestLogger.Log(k2.X);
                k.I = 111;
                k.X = 333;
                TestLogger.Log(k2.I);
                TestLogger.Log(k2.X);
                var k3 = k.PassThrough();
                TestLogger.Log(k3.I);
                TestLogger.Log(k3.X);
                k3.I = 1111;
                k3.X = 3333;
                TestLogger.Log(k.I);
                TestLogger.Log(k.X);
                k.Morph();
                try
                {
                    TestLogger.Log(k.X);
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                var obj = JSObject.From(k);
                TestLogger.Log(obj.GetField <string>("x"));
                obj.SetField <int>("x", 1);
                TestLogger.Log(k.X);
            }

            {
                TestLogger.Log("Testing nullable...");
                var ni = new int?(3);
                TestLogger.Log(ni.Value);
                ni = NullableTest.Incr(ni);
                TestLogger.Log(ni.Value);
                var ni2 = default(int?);
                TestLogger.Log(ni2.HasValue);
                ni2 = NullableTest.Incr(ni2);
                TestLogger.Log(ni2.HasValue);
            }

            {
                TestLogger.Log("Testing primitive arrays...");
                var arr  = new int[] { 0, 1, 2, 3, 4, 5 };
                var arr2 = TestArray.WithArray(arr);
                TestLogger.Log(arr[3]);
                TestLogger.Log(arr2.Length);
                TestLogger.Log(arr2[3]);
            }

            {
                TestLogger.Log("Testing normal object...");
                {
                    var l = "left";
                    var r = new Normal {
                        I = 7, S = "nine"
                    };
                    var o  = TestNormal.Right(l, r);
                    var r2 = (Normal)o;
                    TestLogger.Log(r2.I);
                    TestLogger.Log(r2.S);
                }
                {
                    var l = new Normal {
                        I = 7, S = "nine"
                    };
                    var r  = "right";
                    var o  = TestNormal.Right(l, r);
                    var r2 = (string)o;
                    TestLogger.Log(r2);
                }
                {
                    var l  = "left";
                    var r  = 2;
                    var o  = TestNormal.Right(l, r);
                    var r2 = (int)o;
                    TestLogger.Log(r2);
                }
                {
                    var l = new KeyedTest(1, "two", 3, "four");
                    var r = new ProxiedTest();
                    try
                    {
                        var o  = TestNormal.Right(l, r);
                        var r2 = (ProxiedTest)o;
                        TestLogger.Log(r2.One);
                    }
                    catch (Exception e)
                    {
                        TestLogger.LogException(e);
                    }
                }
            }

            {
                TestLogger.Log("Testing default instances bug...");
                var t = new TestDefaultInstance();
                TestLogger.Log(t.X.ToString());
                t.X = 3;
                TestLogger.Log(t.X.ToString());
            }

            TestLogger.Log("Done.");
        }