示例#1
0
    public void PersistentGetterGeneratesPersistentProperty()
    {
        CppMethod cppGetMethod = new("GetActive")
        {
            Rule =
            {
                Property = true,
                Persist  = true
            }
        };

        var paramType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, cppGetMethod, cppGetMethod.Name)
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = paramType,
                MarshalType = paramType
            }
        };

        var iface = new CsInterface(null, null);

        iface.Add(getMethod);

        CsProperty prop = new(Ioc, null, "Active", getMethod, null);

        propertyBuilder.AttachPropertyToParent(prop);

        Assert.True(prop.IsPersistent);
    }
示例#2
0
    public void SetterVisibilityInternal()
    {
        CppMethod cppSetMethod = new("SetActive")
        {
            Rule =
            {
                Property = true
            }
        };

        var paramType = TypeRegistry.Int32;

        CsMethod setMethod = new(Ioc, cppSetMethod, cppSetMethod.Name)
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType
        });

        var iface = new CsInterface(null, null);

        iface.Add(setMethod);

        CsProperty prop = new(Ioc, null, "Active", null, setMethod);

        propertyBuilder.AttachPropertyToParent(prop);

        Assert.Equal(Visibility.Internal, setMethod.Visibility);
    }
示例#3
0
    public void DoesNotGeneratePropertyIfGetterAndSetterMismatch()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = paramType,
                MarshalType = paramType
            }
        };

        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = TypeRegistry.Int16
        });

        var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

        Assert.Empty(props);
    }
示例#4
0
    public void PropertyNotAttachedWhenSetterAllowPropertyIsFalse()
    {
        CppMethod cppSetMethod = new("SetActive")
        {
            Rule =
            {
                Property = false
            }
        };

        var paramType = TypeRegistry.Int32;

        CsMethod setMethod = new(Ioc, cppSetMethod, cppSetMethod.Name)
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType
        });

        var iface = new CsInterface(null, null);

        iface.Add(setMethod);

        CsProperty prop = new(Ioc, null, "Active", null, setMethod);

        propertyBuilder.AttachPropertyToParent(prop);

        Assert.Null(prop.Parent);
    }
示例#5
0
    public void PropertyAttachedToGetterType()
    {
        var paramType = TypeRegistry.Int32;

        CppMethod cppGetMethod = new("GetActive")
        {
            Rule =
            {
                Property = true
            }
        };

        CsMethod getMethod = new(Ioc, cppGetMethod, cppGetMethod.Name)
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = paramType,
                MarshalType = paramType
            }
        };

        var iface = new CsInterface(null, null);

        iface.Add(getMethod);

        CsProperty prop = new(Ioc, null, "Active", getMethod, null);

        propertyBuilder.AttachPropertyToParent(prop);

        Assert.Equal(iface, prop.Parent);
    }
示例#6
0
    public void DoesNotGeneratePropertyIfGetterAndSetterMismatch_ParameterizedGetter()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
            }
        };

        getMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType,
            Attribute  = CsParameterAttribute.Out
        });

        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = TypeRegistry.Int16
        });

        var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

        Assert.Empty(props);
    }
示例#7
0
    public void GetterWithInvalidSetterDoesNotGenerateProperty()
    {
        var returnType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = returnType,
                MarshalType = returnType
            }
        };

        var invalidSetMethod = new CsMethod(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, invalidSetMethod }));

        Assert.Empty(propertyBuilder.CreateProperties(new[] { invalidSetMethod, getMethod }));
    }
示例#8
0
    public void GetterMethodReturningStatusCodeWithOutParamGeneratesProperty()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
            }
        };

        getMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType,
            Attribute  = CsParameterAttribute.Out
        });


        var properties = propertyBuilder.CreateProperties(new[] { getMethod });

        Assert.True(properties.ContainsKey("Active"));
        var prop = properties["Active"];

        Assert.True(prop.IsPropertyParam);
        Assert.Equal(paramType, prop.PublicType);
    }
示例#9
0
    public void InvalidSetterDoesNotCreateProperty()
    {
        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
    }
示例#10
0
    public void NonPropertyMethodWithNonPropertyNameShouldNotCreateProperty()
    {
        CsMethod setMethod = new(Ioc, null, "MyMethod")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
    }
}
示例#11
0
    public void InvalidGetterDoesNotCreateProperty()
    {
        var returnType = TypeRegistry.Void;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = returnType,
                MarshalType = returnType
            }
        };

        Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod }));
    }
        private InteropType GetInteropTypeForReturnValue(CsReturnValue returnValue,
                                                         PlatformDetectionType platform,
                                                         ref InteropMethodSignatureFlags flags)
        {
            var platformSpecificReturnTypeOverrides = (platform & PlatformDetectionType.Windows) != 0
                                                          ? windowsOnlyReturnTypeOverrides
                                                          : systemvOnlyReturnTypeOverrides;

            // Handle Return Type parameter
            // MarshalType.Type == null, then check that it is a structure
            if (returnValue.PublicType is CsStruct or CsEnum)
            {
                var returnQualifiedName = returnValue.PublicType.QualifiedName;

                if (returnTypeOverrides.TryGetValue(returnQualifiedName, out var interopType))
                {
                    flags |= interopType.SetFlags;
                    return(interopType.NewType);
                }

                if (platformSpecificReturnTypeOverrides.TryGetValue(returnQualifiedName, out interopType))
                {
                    flags |= interopType.SetFlags;
                    return(interopType.NewType);
                }

                return(returnValue.HasNativeValueType
                           ? $"{returnValue.MarshalType.QualifiedName}.__Native"
                           : returnValue.MarshalType.QualifiedName);
            }

            if (returnValue.MarshalType is CsFundamentalType fundamentalReturn)
            {
                return(fundamentalReturn);
            }

            if (returnValue.HasPointer)
            {
                return(returnValue.IsInterface ? TypeRegistry.IntPtr : TypeRegistry.VoidPtr);
            }

            return(null);
        }
示例#13
0
    public void MethodWithNameStartingWithGetCreatesProperty()
    {
        var returnType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = returnType,
                MarshalType = returnType
            }
        };

        var properties = propertyBuilder.CreateProperties(new[] { getMethod });

        Assert.True(properties.ContainsKey("Active"));
        var prop = properties["Active"];

        Assert.Equal(returnType, prop.PublicType);
    }
示例#14
0
    public void DoesNotGeneratePropertyIfOverloaded()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod getMethod = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = paramType,
                MarshalType = paramType
            }
        };

        CsMethod getMethodOverload = new(Ioc, null, "GetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = paramType,
                MarshalType = paramType
            },
        };

        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType
        });

        Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, setMethod, getMethodOverload }));
        Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, getMethodOverload, setMethod }));
    }
示例#15
0
    public void MethodWithNameStartingWithSetAndReturningResultGeneratesProperty()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType
        });

        var properties = propertyBuilder.CreateProperties(new[] { setMethod });

        Assert.True(properties.ContainsKey("Active"), "Property not created");
        var prop = properties["Active"];

        Assert.Equal(paramType, prop.PublicType);
    }
示例#16
0
    public void MethodWithNameStartingWithSetCreatesProperty()
    {
        var paramType = TypeRegistry.Int32;

        CsMethod setMethod = new(Ioc, null, "SetActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType = TypeRegistry.Void
            }
        };

        setMethod.Add(new CsParameter(Ioc, null, null)
        {
            PublicType = paramType
        });

        var properties = propertyBuilder.CreateProperties(new[] { setMethod });

        Assert.True(properties.ContainsKey("Active"));
        var prop = properties["Active"];

        Assert.Equal(paramType, prop.PublicType);
    }