Skip to content

Commit

Permalink
Long: Test returning long values
Browse files Browse the repository at this point in the history
  • Loading branch information
badcel committed May 29, 2024
1 parent a889f46 commit 25a2fb7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Native/GirTestLib/girtest-long-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,48 @@ gsize girtest_long_tester_get_sizeof_l(GirTestLongTester* record)
gsize girtest_long_tester_get_sizeof_ul(GirTestLongTester* record)
{
return sizeof(record->ul);
}

glong girtest_long_tester_get_max_long_value()
{
if(sizeof(long) == 4)
return 2147483647;

if(sizeof(long) == 8)
return 9223372036854775807;

return 0;
}

gboolean girtest_long_tester_is_max_long_value(glong value)
{
if(sizeof(long) == 4 && value == 2147483647)
return TRUE;

if(sizeof(long) == 8 && value == 9223372036854775807)
return TRUE;

return FALSE;
}

glong girtest_long_tester_get_min_long_value()
{
if(sizeof(long) == 4)
return -2147483648;

if(sizeof(long) == 8)
return -9223372036854775808;

return 0;
}

gboolean girtest_long_tester_is_min_long_value(glong value)
{
if(sizeof(long) == 4 && value == -2147483648)
return TRUE;

if(sizeof(long) == 8 && value == -9223372036854775808)
return TRUE;

return FALSE;
}
4 changes: 4 additions & 0 deletions src/Native/GirTestLib/girtest-long-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ struct _GirTestLongTester

gsize girtest_long_tester_get_sizeof_l(GirTestLongTester* record);
gsize girtest_long_tester_get_sizeof_ul(GirTestLongTester* record);
gint girtest_long_tester_get_max_long_value();
gint girtest_long_tester_get_min_long_value();
gboolean girtest_long_tester_is_max_long_value(glong value);
gboolean girtest_long_tester_is_min_long_value(glong value);
G_END_DECLS
36 changes: 36 additions & 0 deletions src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,40 @@ public void ShouldThrowIfValueExceedsUnsignedIntegerSize()
var act = () => obj.Ul = ulong.MaxValue;
act.Should().Throw<OverflowException>();
}

[TestMethod]
public void ReturnsMaxLongValueOn64BitUnix()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !Environment.Is64BitOperatingSystem)
Assert.Inconclusive("Only supported on 64 Bit Unix operating Systems");

LongTester.GetMaxLongValue().Should().Be(long.MaxValue);
}

[TestMethod]
public void ReturnsMaxLongValueOnWindows()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitOperatingSystem)
Assert.Inconclusive("Only supported on windows or 32 bit unix operating Systems");

LongTester.GetMaxLongValue().Should().Be(int.MaxValue);
}

[TestMethod]
public void ReturnsMinLongValueOn64BitUnix()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !Environment.Is64BitOperatingSystem)
Assert.Inconclusive("Only supported on 64 Bit Unix operating Systems");

LongTester.GetMaxLongValue().Should().Be(long.MinValue);
}

[TestMethod]
public void ReturnsMinLongValueOnWindows()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitOperatingSystem)
Assert.Inconclusive("Only supported on windows or 32 bit unix operating Systems");

LongTester.GetMaxLongValue().Should().Be(int.MinValue);
}
}

0 comments on commit 25a2fb7

Please sign in to comment.