|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +#if !NETCOREAPP3_1_OR_GREATER |
| 6 | + |
| 7 | +using System; |
| 8 | +using CommunityToolkit.HighPerformance.Helpers.Internals; |
| 9 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 10 | + |
| 11 | +#pragma warning disable CS0649 |
| 12 | + |
| 13 | +namespace CommunityToolkit.HighPerformance.UnitTests.Helpers.Internals; |
| 14 | + |
| 15 | +[TestClass] |
| 16 | +public class Test_RuntimeHelpers |
| 17 | +{ |
| 18 | + [TestMethod] |
| 19 | + public void Test_RuntimeHelpers_ManagedTypes() |
| 20 | + { |
| 21 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<object>()); |
| 22 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<string>()); |
| 23 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<int[]>()); |
| 24 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<Memory<int>>()); |
| 25 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<ManagedStruct1>()); |
| 26 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<ManagedStruct2>()); |
| 27 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<ManagedStruct3>()); |
| 28 | + } |
| 29 | + |
| 30 | + [TestMethod] |
| 31 | + public void Test_RuntimeHelpers_UnmanagedTypes() |
| 32 | + { |
| 33 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<byte>()); |
| 34 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<int>()); |
| 35 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<IntPtr>()); |
| 36 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<Guid>()); |
| 37 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<byte>()); |
| 38 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<UnmanagedStruct1>()); |
| 39 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<UnmanagedStruct2>()); |
| 40 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<GenericStruct<UnmanagedStruct1>>()); |
| 41 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<GenericStruct<UnmanagedStruct2>>()); |
| 42 | + } |
| 43 | + |
| 44 | + private unsafe struct ManagedStruct1 |
| 45 | + { |
| 46 | + public int A; |
| 47 | + public Memory<int> B; |
| 48 | + } |
| 49 | + |
| 50 | + private struct ManagedStruct2 |
| 51 | + { |
| 52 | + public int A; |
| 53 | + public ManagedStruct1 B; |
| 54 | + } |
| 55 | + |
| 56 | + private struct ManagedStruct3 |
| 57 | + { |
| 58 | + public GenericStruct<Memory<int>> A; |
| 59 | + } |
| 60 | + |
| 61 | + private unsafe struct UnmanagedStruct1 |
| 62 | + { |
| 63 | + public int A; |
| 64 | + public double B; |
| 65 | + public Guid C; |
| 66 | + public IntPtr D; |
| 67 | + public int* E; |
| 68 | + public void** F; |
| 69 | + public GenericStruct<int> G; |
| 70 | + public GenericStruct<Guid> H; |
| 71 | + } |
| 72 | + |
| 73 | + private struct UnmanagedStruct2 |
| 74 | + { |
| 75 | + public int A; |
| 76 | + public UnmanagedStruct1 B; |
| 77 | + public UnmanagedStruct1? C; |
| 78 | + public Guid? D; |
| 79 | + } |
| 80 | + |
| 81 | + private struct GenericStruct<T> |
| 82 | + where T : struct |
| 83 | + { |
| 84 | + public T A; |
| 85 | + public T? B; |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +#endif |
0 commit comments