Skip to content

Commit

Permalink
Merge pull request #989 from gircore/base-enumerations-on-integer-dat…
Browse files Browse the repository at this point in the history
…atypes

Rebase enumerations on integer datatypes
  • Loading branch information
badcel authored Dec 14, 2023
2 parents 416af19 + e8444ed commit 96a71bb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Public/Bitfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {Namespace.GetPublicName(bitfield.Namespace)};
{PlatformSupportAttribute.Render(bitfield as GirModel.PlatformDependent)}
[Flags]
public enum {bitfield.Name} : ulong
public enum {bitfield.Name} : uint
{{
{bitfield
.Members
Expand Down
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Public/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace {Namespace.GetPublicName(enumeration.Namespace)};
// AUTOGENERATED FILE - DO NOT MODIFY
{PlatformSupportAttribute.Render(enumeration as GirModel.PlatformDependent)}
public enum {enumeration.Name} : long
public enum {enumeration.Name} : int
{{
{enumeration
.Members
Expand Down
4 changes: 2 additions & 2 deletions src/Libs/GObject-2.0/Public/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public ParamSpec GetParam()
public long GetLong() => Internal.Value.GetLong(Handle);
public double GetDouble() => Internal.Value.GetDouble(Handle);
public float GetFloat() => Internal.Value.GetFloat(Handle);
public ulong GetFlags() => Internal.Value.GetFlags(Handle);
public long GetEnum() => Internal.Value.GetEnum(Handle);
public uint GetFlags() => Internal.Value.GetFlags(Handle);
public int GetEnum() => Internal.Value.GetEnum(Handle);
public string? GetString() => GetString(Handle).ConvertToString();
public GLib.Variant? GetVariant()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Native/GirTestLib/girtest-bitfield-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
G_BEGIN_DECLS

/**
* DemoFlags:
* GirTestBitfieldTesterSimpleFlags:
* @ZERO: No flags set.
* @ONE: Set first flag.
* @TWO: Set second flag.
* @MAX: Set last flag
*
* Flags to test bindings
* Flags to test bindings.
*/
typedef enum {
SIMPLE_FAGS_ZERO = 0,
SIMPLE_FAGS_ONE = (1 << 0),
SIMPLE_FAGS_TWO = (1 << 1)
SIMPLE_FAGS_TWO = (1 << 1),
SIMPLE_FAGS_MAX = (1 << 31)
} GirTestBitfieldTesterSimpleFlags;

#define GIRTEST_TYPE_BITFIELD_TESTER girtest_bitfield_tester_get_type()
Expand Down
10 changes: 7 additions & 3 deletions src/Native/GirTestLib/girtest-enum-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
G_BEGIN_DECLS

/**
* EnumTesterSimpleEnum:
* GirTestEnumTesterSimpleEnum:
* @A: 1
* @B: 2
* @C: 3
* @MAX: Max int value
* @MIN: Min int value
*
* Enum to test bindings
* Enum to test bindings.
*/
typedef enum {
SIMPLE_ENUM_A = 1,
SIMPLE_ENUM_B = 2,
SIMPLE_ENUM_C = 3
SIMPLE_ENUM_C = 3,
SIMPLE_ENUM_MAX = 2147483647,
SIMPLE_ENUM_MIN = -2147483648
} GirTestEnumTesterSimpleEnum;

#define GIRTEST_TYPE_ENUM_TESTER girtest_enum_tester_get_type()
Expand Down
13 changes: 13 additions & 0 deletions src/Tests/Libs/GirTest-0.1.Tests/BitfieldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public void CanBeUsedInGValue()
var result = value.Extract<BitfieldTesterSimpleFlags>();
result.Should().Be(flags);
}

[TestMethod]
public void CanUseMaxInGValue()
{
var max = (uint) BitfieldTesterSimpleFlags.Max;
max.Should().Be(1u << 31);

var value = new Value(Type.Flags);
value.Set(BitfieldTesterSimpleFlags.Max);

value.Extract<BitfieldTesterSimpleFlags>().Should().Be(BitfieldTesterSimpleFlags.Max);
value.GetFlags().Should().Be(1u << 31);
}
}
26 changes: 21 additions & 5 deletions src/Tests/Libs/GirTest-0.1.Tests/EnumerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ namespace GirTest.Tests;
public class EnumerationTest : Test
{
[TestMethod]
public void CanBeUsedInGValue()
public void CanUseMaxInGValue()
{
var e = EnumTesterSimpleEnum.A;
var max = (int) EnumTesterSimpleEnum.Max;
max.Should().Be(0x7FFFFFFF);

var value = new Value(Type.Enum);
value.Set(e);
var result = value.Extract<EnumTesterSimpleEnum>();
result.Should().Be(e);
value.Set(EnumTesterSimpleEnum.Max);

value.Extract<EnumTesterSimpleEnum>().Should().Be(EnumTesterSimpleEnum.Max);
value.GetEnum().Should().Be(0x7FFFFFFF);
}

[TestMethod]
public void CanUseMinInGValue()
{
var min = (int) EnumTesterSimpleEnum.Min;
min.Should().Be(1 << 31);

var value = new Value(Type.Enum);
value.Set(EnumTesterSimpleEnum.Min);

value.Extract<EnumTesterSimpleEnum>().Should().Be(EnumTesterSimpleEnum.Min);
value.GetEnum().Should().Be(1 << 31);
}
}

0 comments on commit 96a71bb

Please sign in to comment.