|
| 1 | +// Copyright (c) Ubiquity.NET Contributors. All rights reserved. |
| 2 | +// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information. |
| 3 | + |
| 4 | +using System; |
| 5 | + |
| 6 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 7 | + |
| 8 | +using Ubiquity.NET.Llvm.Instructions; |
| 9 | +using Ubiquity.NET.Llvm.Values; |
| 10 | + |
| 11 | +namespace Ubiquity.NET.Llvm.UT.Instructions |
| 12 | +{ |
| 13 | + [TestClass] |
| 14 | + public class PointerCasts |
| 15 | + { |
| 16 | +#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. |
| 17 | + [TestMethod] |
| 18 | + public void IntToPointer_throws_with_invalid_input( ) |
| 19 | + { |
| 20 | + using var ctx = new Context(); |
| 21 | + using var module = ctx.CreateBitcodeModule("test"u8); |
| 22 | + var doulbeFuncType = ctx.GetFunctionType(ctx.DoubleType); |
| 23 | + var doubleFunc = module.CreateFunction("test"u8, doulbeFuncType); |
| 24 | + var block = ctx.CreateBasicBlock("testBlock"u8); |
| 25 | + |
| 26 | + using var irBuilder = new InstructionBuilder(block); |
| 27 | + Value nonConstValue = irBuilder.Call(doubleFunc); |
| 28 | + Value nonIntConstantValue = ctx.CreateConstant(1.23); |
| 29 | + |
| 30 | + var ptrBoolType = ctx.BoolType.CreatePointerType(); |
| 31 | + var constInt = ctx.CreateConstant(0x1234u); |
| 32 | + var argNullEx = Assert.ThrowsExactly<ArgumentNullException>(()=> |
| 33 | + { |
| 34 | + _ = irBuilder.IntToPointer( null, ptrBoolType ); |
| 35 | + }); |
| 36 | + Assert.AreEqual( "intValue", argNullEx.ParamName); |
| 37 | + |
| 38 | + argNullEx = Assert.ThrowsExactly<ArgumentNullException>(()=> |
| 39 | + { |
| 40 | + _ = irBuilder.IntToPointer( constInt, null ); |
| 41 | + }); |
| 42 | + Assert.AreEqual( "ptrType", argNullEx.ParamName ); |
| 43 | + |
| 44 | + var argEx = Assert.ThrowsExactly<ArgumentException>( ( ) => |
| 45 | + { |
| 46 | + _ = irBuilder.IntToPointer( nonIntConstantValue, ptrBoolType ); |
| 47 | + } ); |
| 48 | + Assert.AreEqual( "intValue", argEx.ParamName ); |
| 49 | + |
| 50 | + argEx = Assert.ThrowsExactly<ArgumentException>( ( ) => |
| 51 | + { |
| 52 | + _ = irBuilder.IntToPointer( nonConstValue, ptrBoolType ); |
| 53 | + } ); |
| 54 | + Assert.AreEqual( "intValue", argEx.ParamName ); |
| 55 | + } |
| 56 | +#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. |
| 57 | + } |
| 58 | +} |
0 commit comments