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); }
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); }
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); }
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); }
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); }
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); }
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 })); }
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); }
public void InvalidSetterDoesNotCreateProperty() { CsMethod setMethod = new(Ioc, null, "SetActive") { ReturnValue = new CsReturnValue(Ioc, null) { PublicType = TypeRegistry.Void } }; Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod })); }
public void NonPropertyMethodWithNonPropertyNameShouldNotCreateProperty() { CsMethod setMethod = new(Ioc, null, "MyMethod") { ReturnValue = new CsReturnValue(Ioc, null) { PublicType = TypeRegistry.Void } }; Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod })); } }
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); }
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); }
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 })); }
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); }
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); }