mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-13 03:31:22 +00:00
Added some globalization and culture plugs. Also added string and struct tests.
This commit is contained in:
parent
d790a6ad52
commit
815f2f78a4
13 changed files with 262 additions and 75 deletions
|
|
@ -1,16 +1,28 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Cosmos.TestRunner;
|
||||
|
||||
namespace Cosmos.Compiler.Tests.Bcl.System
|
||||
{
|
||||
public static class StringTest
|
||||
{
|
||||
static Debugger mDebugger = new Debugger("Tests", "String Tests");
|
||||
|
||||
public static void Execute()
|
||||
{
|
||||
Assert.IsTrue(("a" + "b") == "ab", "concatting 2 string using + doesn't work");
|
||||
Assert.IsTrue(("a" + 'b') == "ab", "concatting 1 string and 1 character doesn't work");
|
||||
Assert.IsTrue(string.Empty == "", "string.Empty == \"\"");
|
||||
int xResult = string.Compare("a", "a");
|
||||
mDebugger.Send(xResult.ToString());
|
||||
Assert.IsTrue(xResult == 0, "string.Compare(\"a\", \"a\") == 0");
|
||||
|
||||
Assert.IsTrue(
|
||||
string.Compare("abc", "abc") == 0, "string.Compare(\"abc\", \"abc\") == 0");
|
||||
Assert.IsTrue(("a" + "b") == "ab", "(\"a\" + \"b\") == \"ab\"");
|
||||
Assert.IsTrue(("a" + 'b') == "ab", "concatting 1 string and 1 character doesn\"t work");
|
||||
Assert.IsTrue(string.Concat("a", "b") == "ab", "string.Concat(\"a\", \"b\") == \"ab\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Sys = Cosmos.System;
|
|||
|
||||
namespace SimpleStructsAndArraysTest
|
||||
{
|
||||
public class Kernel: Sys.Kernel
|
||||
public class Kernel : Sys.Kernel
|
||||
{
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
|
|
@ -53,13 +53,13 @@ namespace SimpleStructsAndArraysTest
|
|||
//Console.Write("Char: ");
|
||||
//Console.WriteLine(xResult.KeyChar);
|
||||
var xItem = new MyStruct
|
||||
{
|
||||
A = 1,
|
||||
B = 2,
|
||||
C = 3,
|
||||
D = 4,
|
||||
E = 5
|
||||
};
|
||||
{
|
||||
A = 1,
|
||||
B = 2,
|
||||
C = 3,
|
||||
D = 4,
|
||||
E = 5
|
||||
};
|
||||
|
||||
var xArray = new MyStruct[1];
|
||||
xArray[0] = xItem;
|
||||
|
|
@ -216,8 +216,8 @@ namespace SimpleStructsAndArraysTest
|
|||
var xListClasses = new OurList<KVPClass>();
|
||||
var xListStructs = new OurList<KVPStruct>();
|
||||
|
||||
xListClasses.Add(new KVPClass {Key = 1, Value = 2});
|
||||
xListClasses.Add(new KVPClass {Key = 2, Value = 5});
|
||||
xListClasses.Add(new KVPClass { Key = 1, Value = 2 });
|
||||
xListClasses.Add(new KVPClass { Key = 2, Value = 5 });
|
||||
|
||||
OurList<KVPClass>.ExpectedIndex = 0;
|
||||
var xListItem = xListClasses[0];
|
||||
|
|
@ -225,11 +225,11 @@ namespace SimpleStructsAndArraysTest
|
|||
Assert.AreEqual(2, xListItem.Value, "xListClasses[0].Value == 2");
|
||||
OurList<KVPClass>.ExpectedIndex = 1;
|
||||
xListItem = xListClasses[1];
|
||||
Assert.AreEqual(2, xListItem.Key, "xListClasses[1].Key == 2");
|
||||
Assert.AreEqual(2, xListItem.Key, "xListClasses[1].Key == 2");
|
||||
Assert.AreEqual(5, xListItem.Value, "xListClasses[1].Value == 5");
|
||||
|
||||
xListStructs.Add(new KVPStruct {Key = 1, Value = 2});
|
||||
xListStructs.Add(new KVPStruct {Key = 2, Value = 5});
|
||||
xListStructs.Add(new KVPStruct { Key = 1, Value = 2 });
|
||||
xListStructs.Add(new KVPStruct { Key = 2, Value = 5 });
|
||||
|
||||
OurList<KVPStruct>.ExpectedIndex = 0;
|
||||
var xStructItem = xListStructs[0];
|
||||
|
|
@ -268,6 +268,32 @@ namespace SimpleStructsAndArraysTest
|
|||
Assert.AreEqual(5, xStructItem.Value, "xListStructs[1].Value == 5");
|
||||
}
|
||||
|
||||
private interface ITestMutate
|
||||
{
|
||||
void Mutate();
|
||||
}
|
||||
|
||||
private struct TestMutateStruct : ITestMutate
|
||||
{
|
||||
int a;
|
||||
|
||||
public void Mutate()
|
||||
{
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
private void DoMutate<T>(ref T x) where T : ITestMutate
|
||||
{
|
||||
x.Mutate();
|
||||
}
|
||||
|
||||
private void MutateStructTest()
|
||||
{
|
||||
TestMutateStruct a = new TestMutateStruct();
|
||||
DoMutate(ref a);
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
TestStep1();
|
||||
|
|
@ -275,6 +301,8 @@ namespace SimpleStructsAndArraysTest
|
|||
Assert.IsTrue(true, "After TestOurList");
|
||||
TestStandardList();
|
||||
Assert.IsTrue(true, "After TestStandardList");
|
||||
MutateStructTest();
|
||||
Assert.IsTrue(true, "After MutateTestStruct");
|
||||
TestController.Completed();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,15 @@ namespace Cosmos.Common
|
|||
{
|
||||
internal static Debugger mDebugger = new Debugger("Common", "String Helpers");
|
||||
|
||||
internal enum StringComparisonResultEnum
|
||||
{
|
||||
Less = -1,
|
||||
|
||||
Equal = 0,
|
||||
|
||||
Greater = 1
|
||||
}
|
||||
|
||||
public static string GetCharArrayString(char[] aArray)
|
||||
{
|
||||
if (aArray == null)
|
||||
|
|
@ -131,5 +140,36 @@ namespace Cosmos.Common
|
|||
|
||||
return xNumber;
|
||||
}
|
||||
|
||||
public static int Compare(
|
||||
string aString1,
|
||||
int aIndex1,
|
||||
string aString2,
|
||||
int aIndex2,
|
||||
int aLength1,
|
||||
int aLength2)
|
||||
{
|
||||
if (aString1.Length < aString2.Length)
|
||||
{
|
||||
return (int)StringComparisonResultEnum.CSTR_LESS_THAN;
|
||||
}
|
||||
if (aString1.Length > aString2.Length)
|
||||
{
|
||||
return (int)StringComparisonResultEnum.CSTR_GREATER_THAN;
|
||||
}
|
||||
|
||||
for (int i = aString1.Length; i < aString1.Length; i++)
|
||||
{
|
||||
if (aString1[i] < aString2[i])
|
||||
{
|
||||
return (int)StringComparisonResultEnum.CSTR_LESS_THAN;
|
||||
}
|
||||
if (aString1[i] > aString2[i])
|
||||
{
|
||||
return (int)StringComparisonResultEnum.CSTR_GREATER_THAN;
|
||||
}
|
||||
}
|
||||
return (int)StringComparisonResultEnum.CSTR_EQUAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@
|
|||
<Compile Include="System\Assemblers\InvokeImplAssembler.cs" />
|
||||
<Compile Include="System\Buffer.cs" />
|
||||
<Compile Include="System\DelegateImpl.cs" />
|
||||
<Compile Include="System\Globalization\CompareInfoImpl.cs" />
|
||||
<Compile Include="System\Globalization\CultureInfoImpl.cs" />
|
||||
<Compile Include="System\Globalization\NumberFormatInfoImpl.cs" />
|
||||
<Compile Include="System\Globalization\TextInfoImpl.cs" />
|
||||
<Compile Include="System\IO\PathHelperImpl.cs" />
|
||||
<Compile Include="System\MulticastDelegateImpl.cs" />
|
||||
<Compile Include="System\NormalDelegateImpl.cs" />
|
||||
|
|
@ -130,6 +134,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Cosmos.snk" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
#define COSMOSDEBUG
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cosmos.Common;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Cosmos.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Core.Plugs.System.Globalization
|
||||
{
|
||||
[Plug(Target = typeof(CompareInfo))]
|
||||
public static class CompareInfoImpl
|
||||
{
|
||||
static Debugger mDebugger = new Debugger("Core", "Compare Info Plug");
|
||||
|
||||
public static void Ctor(CompareInfo aThis, CultureInfo culture)
|
||||
{
|
||||
mDebugger.SendInternal("CompareInfo::Ctor");
|
||||
}
|
||||
|
||||
public static int Compare(CompareInfo aThis, string aString1, string aString2, CompareOptions aOptions)
|
||||
{
|
||||
#warning TODO: Implement CompareOptions
|
||||
mDebugger.SendInternal("CompareInfo.Compare");
|
||||
return StringHelper.Compare(aString1, 0, aString2, 0, aString1.Length, aString2.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
using System.Globalization;
|
||||
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Cosmos.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Core.Plugs.System.Globalization
|
||||
{
|
||||
[Plug(Target = typeof(CultureInfo))]
|
||||
public static class CultureInfoImpl
|
||||
{
|
||||
static Debugger mDebugger = new Debugger("Core", "Compare Info Plug");
|
||||
|
||||
public static void Ctor(CultureInfo aThis, string name, bool useUserOverride)
|
||||
{
|
||||
}
|
||||
|
||||
public static bool get_UseUserOverride(CultureInfo aThis)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static CultureInfo get_CurrentCulture()
|
||||
{
|
||||
return new CultureInfo("en-us");
|
||||
}
|
||||
|
||||
public static CultureInfo get_InvariantCulture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void CCtor()
|
||||
{
|
||||
}
|
||||
|
||||
public static CultureInfo GetCultureInfo(string aName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool Equals(CultureInfo aThis, object aThat)
|
||||
{
|
||||
return ReferenceEquals(aThis, aThat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using Cosmos.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Core.Plugs.System.Globalization
|
||||
{
|
||||
[Plug(Target = typeof(NumberFormatInfo))]
|
||||
public static class NumberFormatInfoImpl
|
||||
{
|
||||
public static NumberFormatInfo GetInstance(IFormatProvider aProvider)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static NumberFormatInfo get_CurrentInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cosmos.Common;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Cosmos.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Core.Plugs.System.Globalization
|
||||
{
|
||||
[Plug(Target = typeof(TextInfo))]
|
||||
public static class TextInfoImpl
|
||||
{
|
||||
static Debugger mDebugger = new Debugger("Core", "Compare Info Plug");
|
||||
|
||||
public static void Ctor(TextInfo aThis, object cultureData)
|
||||
{
|
||||
}
|
||||
|
||||
public static int InternalCompareStringOrdinalIgnoreCase(string aString1, int aIndex1, string aString2, int aIndex2, int aLength1, int aLength2)
|
||||
{
|
||||
mDebugger.SendInternal("InternalCompareStringOrdinalIgnoreCase");
|
||||
mDebugger.SendInternal(aString1);
|
||||
mDebugger.SendInternal(aString2);
|
||||
|
||||
string xString1 = aString1.ToLower();
|
||||
string xString2 = aString2.ToLower();
|
||||
return StringHelper.Compare(xString1, aIndex1, xString2, aIndex2, aLength1, aLength2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
using Cosmos.Common;
|
||||
using Cosmos.IL2CPU.Plugs;
|
||||
|
|
@ -51,11 +50,11 @@ namespace Cosmos.Core.Plugs.System
|
|||
}
|
||||
|
||||
public static unsafe void Ctor(
|
||||
string aThis,
|
||||
char[] aChars,
|
||||
[FieldAccess(Name = "System.String System.String.Empty")] ref string aStringEmpty,
|
||||
[FieldAccess(Name = "System.Int32 System.String.m_stringLength")] ref int aStringLength,
|
||||
[FieldAccess(Name = "System.Char System.String.m_firstChar")] char* aFirstChar)
|
||||
string aThis,
|
||||
char[] aChars,
|
||||
[FieldAccess(Name = "System.String System.String.Empty")] ref string aStringEmpty,
|
||||
[FieldAccess(Name = "System.Int32 System.String.m_stringLength")] ref int aStringLength,
|
||||
[FieldAccess(Name = "System.Char System.String.m_firstChar")] char* aFirstChar)
|
||||
{
|
||||
aStringEmpty = "";
|
||||
aStringLength = aChars.Length;
|
||||
|
|
@ -595,8 +594,6 @@ namespace Cosmos.Core.Plugs.System
|
|||
}
|
||||
}
|
||||
|
||||
// System.Int32 System.String.IndexOf(System.String, System.Int32, System.Int32, System.StringComparison)
|
||||
|
||||
public static bool Equals(string aThis, string aThat, StringComparison aComparison)
|
||||
{
|
||||
#warning TODO: implement
|
||||
|
|
@ -609,9 +606,23 @@ namespace Cosmos.Core.Plugs.System
|
|||
return EqualsHelper(aThis, aThat);
|
||||
}
|
||||
|
||||
public static bool EqualsHelper(string aStrA, string aStrB)
|
||||
public static bool EqualsHelper(string strA, string strB)
|
||||
{
|
||||
return aStrA.CompareTo(aStrB) == 0;
|
||||
int xLength1 = strA.Length;
|
||||
int xLength2 = strB.Length;
|
||||
|
||||
if (xLength1 != xLength2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < xLength1; i++)
|
||||
{
|
||||
if (strA[i] != strB[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool CharArrayContainsChar(char[] aArray, char aChar)
|
||||
|
|
|
|||
|
|
@ -110,8 +110,6 @@
|
|||
</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Plugs\System\GCImpl.cs" />
|
||||
<Compile Include="Plugs\System\Globalization\CultureInfoImpl.cs" />
|
||||
<Compile Include="Plugs\System\Globalization\NumberFormatInfoImpl.cs" />
|
||||
<Compile Include="Plugs\System\ObjectImpl.cs">
|
||||
<SubType>
|
||||
</SubType>
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace Cosmos.IL2CPU.Plugs.System.Globalization {
|
||||
[Plug(Target = typeof(CultureInfo))]
|
||||
public static class CultureInfoImpl {
|
||||
public static CultureInfo get_CurrentCulture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CultureInfo get_InvariantCulture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//[PlugMethod(Signature = "System_Void__System_Globalization_CultureInfo__cctor__")]
|
||||
public static void CCtor()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool Equals(CultureInfo aThis, object aThat)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Cosmos.IL2CPU.Plugs.System.Globalization {
|
||||
[Plug(Target=typeof(NumberFormatInfo))]
|
||||
public static class NumberFormatInfoImpl {
|
||||
public static NumberFormatInfo GetInstance(IFormatProvider aProvider) {
|
||||
//Console.WriteLine("NumberFormatInfo.GetInstance(IFormatProvider) is not working!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static NumberFormatInfo get_CurrentInfo()
|
||||
{
|
||||
//Console.WriteLine("NumberFormatInfo.get_CurrentInfo is not working!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -294,13 +294,14 @@ namespace Cosmos.System.FileSystem.VFS
|
|||
|
||||
public static char[] GetInvalidFileNameChars()
|
||||
{
|
||||
return new[]
|
||||
{ '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', ':', '*', '?', '\\', '/' };
|
||||
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', ':', '*', '?', '\\', '/' };
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
public static char[] GetInvalidPathCharsWithAdditionalChecks()
|
||||
{
|
||||
return new[] { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '*', '?' };
|
||||
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '*', '?' };
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
public static char GetPathSeparator()
|
||||
|
|
@ -310,7 +311,8 @@ namespace Cosmos.System.FileSystem.VFS
|
|||
|
||||
public static char[] GetRealInvalidPathChars()
|
||||
{
|
||||
return new[] { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r' };
|
||||
char[] xReturn = { '"', '<', '>', '|', '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r' };
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
public static char[] GetTrimEndChars()
|
||||
|
|
|
|||
Loading…
Reference in a new issue