From 25a2fb7bf5b818c08c2d2b66c849372cbff83243 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Wed, 29 May 2024 22:03:31 +0200 Subject: [PATCH] Long: Test returning long values --- src/Native/GirTestLib/girtest-long-tester.c | 44 ++++++++++++++++++++ src/Native/GirTestLib/girtest-long-tester.h | 4 ++ src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs | 36 ++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/src/Native/GirTestLib/girtest-long-tester.c b/src/Native/GirTestLib/girtest-long-tester.c index 2219c2038..88ad358d7 100644 --- a/src/Native/GirTestLib/girtest-long-tester.c +++ b/src/Native/GirTestLib/girtest-long-tester.c @@ -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; } \ No newline at end of file diff --git a/src/Native/GirTestLib/girtest-long-tester.h b/src/Native/GirTestLib/girtest-long-tester.h index 0b5c5f3f7..7e5b123c8 100644 --- a/src/Native/GirTestLib/girtest-long-tester.h +++ b/src/Native/GirTestLib/girtest-long-tester.h @@ -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 \ No newline at end of file diff --git a/src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs b/src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs index 1a4e3b82a..3ec1f248b 100644 --- a/src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs +++ b/src/Tests/Libs/GirTest-0.1.Tests/LongTest.cs @@ -103,4 +103,40 @@ public void ShouldThrowIfValueExceedsUnsignedIntegerSize() var act = () => obj.Ul = ulong.MaxValue; act.Should().Throw(); } + + [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); + } }