From 1a930e31812b85ed1767cb4514d2a66aebbdef58 Mon Sep 17 00:00:00 2001 From: Quajak Date: Tue, 9 Oct 2018 22:04:15 +0200 Subject: [PATCH] Fixed and Added Tests Fixed tests for Int32 and Int64, so that they actually work. Added tests for UInt32 and UInt64 --- .../System/Int32Test.cs | 24 ++++++++------ .../System/Int64Test.cs | 23 ++++++++------ .../System/UInt32Test.cs | 29 +++++++++++++++++ .../System/UInt64Test.cs | 31 +++++++++++++++++++ 4 files changed, 89 insertions(+), 18 deletions(-) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int32Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int32Test.cs index 13a2ae6b0..5ca3eef3e 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int32Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int32Test.cs @@ -143,31 +143,37 @@ namespace Cosmos.Compiler.Tests.Bcl.System ByRefTestMethod(ref value); Assert.IsTrue(value == 61, "Passing an Int32 by ref to a method doesn't work"); - //Test StackOverflow Exceptions - int val3o; + //Test Overflow Exceptions + int val3o = 10000; efuse = false; - val3o = 10000; try { - val3o += 2147483647; + checked + { + val3o += 2147483647; + } } - catch (OverflowException e) + catch (OverflowException) { efuse = true; } - Assert.IsTrue(efuse, "Add_Ovf for Int32 doesn't work"); + Assert.IsTrue(efuse, "Add_Ovf for Int32 doesn't work: " + val3o); efuse = false; val3o = -10000; try { - val3o -= 2147483647; + checked + { + val3o -= 2147483647; + } } - catch (OverflowException e) + catch (OverflowException) { efuse = true; } - Assert.IsTrue(efuse, "Sub_Ovf for Int32 doesn't work"); + Assert.IsTrue(efuse, "Sub_Ovf for Int32 doesn't work: " + val3o); + Console.WriteLine("Finished Int32 Tests!"); } public static int TestMethod(int aParam) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs index 7df5b3760..08d5f5622 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs @@ -149,31 +149,36 @@ namespace Cosmos.Compiler.Tests.Bcl.System ByRefTestMethod(ref value); Assert.IsTrue(value == 61, "Passing an Int64 by ref to a method doesn't work"); - //Test StackOverflow Exceptions - long val3o; + //Test Overflow Exceptions + long val3o = 1000000; efuse = false; - val3o = 1000000; try { - val3o += long.MaxValue; + checked + { + val3o += long.MaxValue; + } } - catch (OverflowException e) + catch (OverflowException) { efuse = true; } - Assert.IsTrue(efuse, "Add_Ovf for Int16 doesn't work"); + Assert.IsTrue(efuse, "Add_Ovf for Int64 doesn't work"); efuse = false; val3o = -10000; try { - val3o -= long.MaxValue; + checked + { + val3o -= long.MaxValue; + } } - catch (OverflowException e) + catch (OverflowException) { efuse = true; } - Assert.IsTrue(efuse, "Sub_Ovf for Int16 doesn't work"); + Assert.IsTrue(efuse, "Sub_Ovf for Int64 doesn't work"); } public static long TestMethod(long aParam) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt32Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt32Test.cs index 14dd77009..9663e8751 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt32Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt32Test.cs @@ -141,6 +141,35 @@ namespace Cosmos.Compiler.Tests.Bcl.System ByRefTestMethod(ref value); Assert.IsTrue(value == 61, "Passing an UInt32 by ref to a method doesn't work"); + uint val3o = 10000; + bool efuse = false; + try + { + checked + { + val3o += uint.MaxValue; + } + } + catch (OverflowException) + { + efuse = true; + } + Assert.IsTrue(efuse, "Add_Ovf for UInt32 doesn't work: " + val3o); + + efuse = false; + val3o = 10000; + try + { + checked + { + val3o -= 2147483647; + } + } + catch (OverflowException) + { + efuse = true; + } + Assert.IsTrue(efuse, "Sub_Ovf for UInt32 doesn't work: " + val3o); } public static uint TestMethod(uint aParam) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs index b12a5f931..512e3578e 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs @@ -147,6 +147,37 @@ namespace Cosmos.Compiler.Tests.Bcl.System ByRefTestMethod(ref value); Assert.IsTrue(value == 61, "Passing an UInt64 by ref to a method doesn't work"); + + //Test Overflow Exceptions + ulong val3o = 10000; + bool efuse = false; + try + { + checked + { + val3o += ulong.MaxValue; + } + } + catch (OverflowException) + { + efuse = true; + } + Assert.IsTrue(efuse, "Add_Ovf for UInt64 doesn't work: " + val3o); + + efuse = false; + val3o = 10000; + try + { + checked + { + val3o -= 2147483647; + } + } + catch (OverflowException) + { + efuse = true; + } + Assert.IsTrue(efuse, "Sub_Ovf for UInt64 doesn't work: " + val3o); } public static ulong TestMethod(ulong aParam)