From aabb8b02e54b10df496f7d85527ad06cb7d4113f Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Fri, 22 May 2020 18:46:45 +0300 Subject: [PATCH] add runtime test --- VirtualMachine.sln | 7 +++++ test/RuntimeTest/NativeStringTest.cs | 44 ++++++++++++++++++++++++---- test/RuntimeTest/RuntimeTest.csproj | 13 +++++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/VirtualMachine.sln b/VirtualMachine.sln index e192ecf..b2701b6 100644 --- a/VirtualMachine.sln +++ b/VirtualMachine.sln @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "submodules", "submodules", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Runtime", "submodules\runtime\src\Ancient.Runtime.csproj", "{267CF9D7-0E11-45D6-82E0-72B0B2B66673}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RuntimeTest", "test\RuntimeTest\RuntimeTest.csproj", "{5646B0E1-10FA-41F3-9110-8C616307DD6C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -65,6 +67,10 @@ Global {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Debug|Any CPU.Build.0 = Debug|Any CPU {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.ActiveCfg = Release|Any CPU {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.Build.0 = Release|Any CPU + {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -78,6 +84,7 @@ Global {E2D48827-C38C-4689-B0A1-9FD395904FB3} = {3E153A17-EBC1-4471-BD65-0C306499D3F2} {00506E30-C4CB-4734-BA64-920CEE5CE926} = {3E153A17-EBC1-4471-BD65-0C306499D3F2} {267CF9D7-0E11-45D6-82E0-72B0B2B66673} = {B29BF648-1A51-4597-BE5E-E96D2C9EDD34} + {5646B0E1-10FA-41F3-9110-8C616307DD6C} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {77DF946F-0A1C-4A24-8A58-E2136BF8FC38} diff --git a/test/RuntimeTest/NativeStringTest.cs b/test/RuntimeTest/NativeStringTest.cs index 5252e39..d7220fa 100644 --- a/test/RuntimeTest/NativeStringTest.cs +++ b/test/RuntimeTest/NativeStringTest.cs @@ -1,20 +1,52 @@ namespace Tests { + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; using System.Text; + using ancient.runtime; using ancient.runtime.@unsafe; - using NUnit.Framework; + using Xunit; public unsafe class NativeStringTest { - [Test] + [Fact] public void AllocateTest() { var str = "foo-bar"; var p = NativeString.Wrap(str); - Assert.AreEqual(str.Length, p.GetLen()); - Assert.AreEqual(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length); - Assert.AreEqual(Encoding.UTF8, p.GetEncoding()); - Assert.AreEqual(NativeString.GetHashCode(str), p.GetHashCode()); + Assert.Equal(str.Length, p.GetLen()); + Assert.Equal(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length); + Assert.Equal(Encoding.UTF8, p.GetEncoding()); + Assert.Equal(NativeString.GetHashCode(str), p.GetHashCode()); + } + public class StringGenerator : IEnumerable, IEnumerable + { + public string[][] Data() => + Enumerable.Range(0, 1) + .Select(i => Enumerable.Range(0, (int) Math.Pow(10, i)) + .Select(v => Guid.NewGuid().ToString()) + .ToArray()).ToArray(); + + + public IEnumerator GetEnumerator() + => Data().ToList().GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => Data().Select(x => new object[]{x}).GetEnumerator(); + } + + //[Theory(Timeout = 1000 * 120)] + //[ClassData(typeof(StringGenerator))] + public void LoadTest(string[] data) + { + var hashMap = new HashSet(); + + foreach (var s in data) + Assert.True(hashMap.Add(NativeString.GetHashCode(s))); + } } } \ No newline at end of file diff --git a/test/RuntimeTest/RuntimeTest.csproj b/test/RuntimeTest/RuntimeTest.csproj index 313de3a..1d864c1 100644 --- a/test/RuntimeTest/RuntimeTest.csproj +++ b/test/RuntimeTest/RuntimeTest.csproj @@ -10,13 +10,18 @@ - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - +