public void TypeReferenceEquals()
        {
            var int_ref = JavaTypeReference.Int;

            Assert.AreEqual(JavaTypeReference.Int, int_ref, "primitive types 2");

            var pkg       = new JavaPackage("com.example", "com/example", null);
            var dummyType = JavaApiTestHelper.CreateClass(pkg, "Dummy");
            var tps       = new JavaTypeParameters(dummyType);
            var gt        = new JavaTypeParameter("T", tps);

            Assert.AreEqual(new JavaTypeReference(gt, null), new JavaTypeReference(new JavaTypeParameter("T", tps), null), "type parameters");
            Assert.AreNotEqual(new JavaTypeReference(gt, null), new JavaTypeReference(new JavaTypeParameter("U", tps), null), "type parameters 2");
            Assert.AreNotEqual(new JavaTypeReference(gt, null), new JavaTypeReference(gt, "[]"), "type parameters: array vs. non-array");
            Assert.AreEqual(new JavaTypeReference(gt, "[]"), new JavaTypeReference(gt, "[]"), "type parameters: array vs. array");

            var type = JavaApiTestHelper.CreateClass(pkg, "T");

            Assert.AreEqual(new JavaTypeReference(type, null, null), new JavaTypeReference(type, null, null), "type vs. type");
            Assert.AreNotEqual(new JavaTypeReference(type, null, "[]"), new JavaTypeReference(type, null, null), "type: array vs. non array");
            Assert.AreNotEqual(new JavaTypeReference(type, null, "[]"), new JavaTypeReference(type, null, "[][]"), "type: array vs. array of array");
            Assert.AreNotEqual(new JavaTypeReference(type, null, null), new JavaTypeReference(new JavaTypeParameter("T", tps), null), "type vs. type parameters");

            Assert.AreNotEqual(new JavaTypeReference(gt, "[]"), new JavaTypeReference(type, null, null), "type: array vs. non array");
            Assert.AreNotEqual(new JavaTypeReference(type, null, "[]"), new JavaTypeReference(type, null, "[][]"), "type: array vs. array of array");
        }
Example #2
0
        public void GenericInheritanceMappings()
        {
            var obj = api.FindType("java.lang.Object") as JavaClassModel;

            Assert.IsNotNull(obj.GenericInheritanceMapping, "java.lang.Object mapping not found");
            Assert.AreEqual(0, obj.GenericInheritanceMapping.Count, "ContentObservable mapping not found");

            var kls = api.FindType("android.database.ContentObservable") as JavaClassModel;
            var map = kls.GenericInheritanceMapping;

            Assert.IsNotNull(map, "ContentObservable mapping not found");
            Assert.AreEqual(1, map.Count, "ContentObservable mapping count unexpected");

            Assert.IsNotNull(map.Keys.First().ReferencedTypeParameter, "key is not GenericTypeParameter");
            Assert.IsNotNull("T", map.Keys.First().ReferencedTypeParameter.Name, "key GenericTypeParameter has unexpected name");
            Assert.IsNotNull(map.Values.First().ReferencedType, "value is not to JavaType");
            Assert.IsNotNull("android.database.ContentObserver", map.Values.First().ReferencedType.FullName, "value JavaType has unexpected name");

            var pkg       = new JavaPackage("com.example", "com/example", null);
            var dummyType = JavaApiTestHelper.CreateClass(pkg, "Dummy");
            var tps       = new JavaTypeParameters(dummyType);
            var gt        = new JavaTypeParameter("T", tps);

            Assert.IsTrue(map.TryGetValue(new JavaTypeReference(gt, null), out var mapped),
                          "Mapped type for generic parameter 'T' not found, or dictionary lookup failed.");

            Assert.AreEqual("android.database.ContentObserver", mapped.ReferencedType.FullName, "unexpected resolved type");
        }
Example #3
0
        public void GenericDerivation()
        {
            var dic = api.FindType("java.util.Dictionary") as JavaClassModel;

            Assert.IsNotNull(dic, "Dictionary not found");
            Assert.AreEqual(0, dic.GenericInheritanceMapping.Count, "Dictionary should have no mapping.");

            var hashtable = api.FindType("java.util.Hashtable") as JavaClassModel;

            Assert.IsNotNull(hashtable, "Hashtable not found");
            Assert.AreEqual(0, hashtable.GenericInheritanceMapping.Count, "Hashtable should have no mapping.");

            var pkg       = new JavaPackage("com.example", "com/example", null);
            var dummyType = JavaApiTestHelper.CreateClass(pkg, "Dummy");
            var tps       = new JavaTypeParameters(dummyType);

            var props = api.FindType("java.util.Properties") as JavaClassModel;

            Assert.IsNotNull(props, "Properties not found");
            Assert.AreEqual(2, props.GenericInheritanceMapping.Count, "Properties should have no mapping.");

            var k = new JavaTypeReference(new JavaTypeParameter("K", tps), null);
            var v = new JavaTypeReference(new JavaTypeParameter("V", tps), null);

            Assert.IsNotNull(props.GenericInheritanceMapping [k], "Properties: mapping for K not found.");
            Assert.AreEqual("java.lang.Object", props.GenericInheritanceMapping [k].ReferencedType.FullName, "Properties: mapping for K is not to java.lang.Object.");
            Assert.AreEqual("java.lang.Object", props.GenericInheritanceMapping [v].ReferencedType.FullName, "Properties: mapping for K is not to java.lang.Object.");
        }
Example #4
0
        public void IntentServiceHack()
        {
            // https://github.com/xamarin/java.interop/issues/717
            var api = JavaApiTestHelper.GetLoadedApi();

            // Create "mono.android.app" package
            var mono_android_app = api.AddPackage("mono.android.app", "mono/android/app");

            // Remove "android.app.IntentService" type
            var android_app    = api.Packages["android.app"];
            var intent_service = android_app.Types.Single(t => t.Name == "IntentService");

            android_app.Types.Remove(intent_service);
            api.RemoveType(intent_service);

            // Create new "mono.android.app.IntentService" type
            var new_intent_service = JavaApiTestHelper.CreateClass(mono_android_app, "IntentService");

            api.AddType(new_intent_service);

            api.ResolveCollection();

            // Ensure we can resolve the type by either name
            Assert.AreSame(new_intent_service, api.FindType("mono.android.app.IntentService"));
            Assert.AreSame(new_intent_service, api.FindType("android.app.IntentService"));
        }