Skip to content

Commit

Permalink
Merge pull request CosmosOS#775 from fanoI/master
Browse files Browse the repository at this point in the history
More work on FAT / System.IO
  • Loading branch information
jp2masa authored Jan 5, 2018
2 parents 954d9e8 + 5d18c21 commit e06efd8
Show file tree
Hide file tree
Showing 42 changed files with 2,813 additions and 1,236 deletions.
11 changes: 11 additions & 0 deletions Test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XSharp.x86", "..\XSharp\sou
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Compiler.Tests.TypeSystem", "Tests\Cosmos.Compiler.Tests.TypeSystem\Cosmos.Compiler.Tests.TypeSystem.csproj", "{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Kernel.Tests.Fat2", "Tests\Cosmos.Kernel.Tests.Fat2\Cosmos.Kernel.Tests.Fat2.csproj", "{D4B1618A-3653-43CD-B617-20482B12712B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -599,6 +601,14 @@ Global
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Release|Any CPU.Build.0 = Release|Any CPU
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Release|x86.ActiveCfg = Release|Any CPU
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Release|x86.Build.0 = Release|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Debug|x86.ActiveCfg = Debug|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Debug|x86.Build.0 = Debug|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Release|Any CPU.Build.0 = Release|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Release|x86.ActiveCfg = Release|Any CPU
{D4B1618A-3653-43CD-B617-20482B12712B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -674,6 +684,7 @@ Global
{FF46829E-B612-4D36-80BE-ED04521AD91A} = {E9CD521E-C386-466D-B5F7-A5EB19A61625}
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67} = {E9CD521E-C386-466D-B5F7-A5EB19A61625}
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34} = {ECEA7778-E786-4317-90B9-A2D4427CB91C}
{D4B1618A-3653-43CD-B617-20482B12712B} = {29EEC029-6A2B-478A-B6E5-D63A91388ABA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4418C803-277E-448F-A0A0-52788FA215AD}
Expand Down
38 changes: 38 additions & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/Helper/EqualityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,43 @@ public static bool DoublesAreEqual(double left, double right)
else
return false;
}

/// <summary>
/// Utility method to test Byte[] equality.
/// </summary>
/// <param name="a1">Byte array.</param>
/// <param name="a2">Byte array.</param>
/// <returns>True if the elements in the arrays are equal otherwise false.</returns>
public static bool ByteArrayAreEquals(byte[] a1, byte[] a2)
{
if (ReferenceEquals(a1, a2))
{
//mDebugger.Send("a1 and a2 are the same Object");
return true;
}

if (a1 == null || a2 == null)
{
//mDebugger.Send("a1 or a2 is null so are different");
return false;
}

if (a1.Length != a2.Length)
{
//mDebugger.Send("a1.Length != a2.Length so are different");
return false;
}

for (int i = 0; i < a1.Length; i++)
{
if (a1[i] != a2[i])
{
//mDebugger.Send("In position " + i + " a byte is different");
return false;
}
}

return true;
}
}
}
1 change: 1 addition & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected override void Run()
BitConverterTest.Execute();
UnsafeCodeTest.Execute();
DelegatesTest.Execute();
EncodingTest.Execute();
RandomTests.Execute();

System.Collections.Generic.ListTest.Execute();
Expand Down
115 changes: 115 additions & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/EncodingTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.TestRunner;
using Cosmos.Compiler.Tests.Bcl.Helper;

namespace Cosmos.Compiler.Tests.Bcl.System
{
class EncodingTest
{
static byte[] UTF8EnglishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x20,
0x77, 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6C, 0x21 };
static byte[] UTF8ItalianText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0xC3, 0xA8, 0x20,
0x66, 0x61, 0x6E, 0x74, 0x61, 0x73, 0x74, 0x69, 0x63, 0x6F,
0x21 };
static byte[] UTF8SpanishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x65, 0x73, 0x20,
0x67, 0x65, 0x6E, 0x69, 0x61, 0x6C, 0x21 };
static byte[] UTF8GermanicText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x74,
0x20, 0x67, 0x72, 0x6F, 0xC3, 0x9F, 0x61, 0x72, 0x74, 0x69,
0x67, 0x21 };
static byte[] UTF8GreekText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0xCE, 0xB5, 0xCE,
0xAF, 0xCE, 0xBD, 0xCE, 0xB1, 0xCE, 0xB9, 0x20, 0xCF, 0x85,
0xCF, 0x80, 0xCE, 0xAD, 0xCF, 0x81, 0xCE, 0xBF, 0xCF, 0x87,
0xCE, 0xBF, 0xCF, 0x82, 0x21 };
static byte[] UTF8JapanaseText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0xE7, 0xB4, 0xA0,
0xE6, 0x99, 0xB4, 0xE3, 0x82, 0x89, 0xE3, 0x81, 0x97, 0xE3,
0x81, 0x84, 0xE3, 0x81, 0xA7, 0xE3, 0x81, 0x99, 0x21 };
static byte[] UTF8GothicText = new byte[] { 0xF0, 0x90, 0x8D, 0x88 };

public static void Execute()
{
//CosmosUTF8Encoding Encoder = new CosmosUTF8Encoding();
//Encoder Encoder = new UTF8Encoding().GetEncoder();
Encoding Encoder = new UTF8Encoding();
string text;
byte[] result;
byte[] expectedResult;

text = "Cosmos is wonderful!";
result = Encoder.GetBytes(text);
expectedResult = UTF8EnglishText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of English text failed byte arrays different");

text = "Cosmos è fantastico!";
result = Encoder.GetBytes(text);
expectedResult = UTF8ItalianText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Italian text failed byte arrays different");

text = "Cosmos es genial!";
result = Encoder.GetBytes(text);
expectedResult = UTF8SpanishText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Spanish text failed byte arrays different");

text = "Cosmos ist großartig!";
result = Encoder.GetBytes(text);
expectedResult = UTF8GermanicText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Germanic text failed byte arrays different");

text = "Cosmos είναι υπέροχος!";
result = Encoder.GetBytes(text);
expectedResult = UTF8GreekText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Greek text failed byte arrays different");

text = "Cosmos 素晴らしいです!";
result = Encoder.GetBytes(text);
expectedResult = UTF8JapanaseText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Japanese text failed byte arrays different");

/* This the only case on which UFT-16 must use a surrugate pairs... it is a Gothic letter go figure! */
text = "𐍈";
result = Encoder.GetBytes(text);
expectedResult = UTF8GothicText;
Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Gothic text failed byte arrays different");

/* Now we do the other way: we have a UFT8 byte array and try to convert it in a UFT16 String */
string expectedText;

text = Encoder.GetString(UTF8EnglishText);
expectedText = "Cosmos is wonderful!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of English text failed strings different");

text = Encoder.GetString(UTF8ItalianText);
expectedText = "Cosmos è fantastico!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Italian text failed strings different");

text = Encoder.GetString(UTF8SpanishText);
expectedText = "Cosmos es genial!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Spanish text failed strings different");

text = Encoder.GetString(UTF8GermanicText);
expectedText = "Cosmos ist großartig!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Germanic text failed strings different");

text = Encoder.GetString(UTF8GreekText);
expectedText = "Cosmos είναι υπέροχος!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Greek text failed strings different");

text = Encoder.GetString(UTF8JapanaseText);
expectedText = "Cosmos 素晴らしいです!";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Japanese text failed strings different");

text = Encoder.GetString(UTF8GothicText);
expectedText = "𐍈";
Assert.IsTrue((text == expectedText), "UTF8 Decoding of Gothic text failed strings different");

/* But this not work is searching '437' in some native Windows tables, we need plugs for this sadly! */
//Encoder = Encoding.GetEncoding(437);
//text = "àèìòù";
//result = Encoder.GetBytes(text);
//expectedResult = new byte[] { 0x85, 0x8A, 0x8D, 0x95, 0x97 };
//Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of accents text failed byte arrays different");

}
}
}
34 changes: 33 additions & 1 deletion Tests/Cosmos.Compiler.Tests.Bcl/System/StringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static void Execute()
string substr = str.Substring(0, 6);
Assert.IsTrue((substr == expected), "Substring is not equal to the expected result, result should be \"Cosmos\". Substrings are broken or MichaelTheShifter made an off-by-one error.");


int value1 = 1;
string value2 = "4";
string expected_res = "1 + 3 = 4";
Expand Down Expand Up @@ -66,6 +65,39 @@ public static void Execute()
char[] char_array_expected = { 'c', 'h', 'a', 'r' };
Assert.IsTrue((char_array_test.ToCharArray().Length == 4), "string.ToCharArray() does not work.");

string strA;
string strB;
int comparisionResult;

strA = "Test";
strB = "Test";

comparisionResult = String.Compare(strA, 0, strB, 0, strA.Length, StringComparison.Ordinal);
Assert.IsTrue(comparisionResult == 0, "String.Compare (same string) not working!");

strA = "\x0041\x0042\x0043";
strB = "\x0061\x0062\x0063";

comparisionResult = String.Compare(strA, 0, strB, 0, strA.Length, StringComparison.Ordinal);
Assert.IsTrue(comparisionResult == -32, "String.Compare (uppercase vs lowercase) not working!");

strA = "\x0041\x0042\x0043";
strB = "\x0041\x0062\x0063";

comparisionResult = String.Compare(strA, 0, strB, 0, strA.Length, StringComparison.Ordinal);
Assert.IsTrue(comparisionResult == -32, "String.Compare (first letter same) not working!");

strA = "Horse";
strB = "Morse"; /* . _ . */

comparisionResult = String.Compare(strA, 1, strB, 1, strA.Length, StringComparison.Ordinal);
Assert.IsTrue(comparisionResult == 0, "String.Compare (first letter different skipped) not working!");

strA = "\x0041\x0042\x0043";
strB = "\x0061\x0062\x0063";

comparisionResult = String.Compare(strA, 0, strB, 0, strA.Length, StringComparison.OrdinalIgnoreCase);
Assert.IsTrue(comparisionResult == 0, "String.Compare (uppercase vs lowercase ignoring case) not working!");
}
}
}
27 changes: 24 additions & 3 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/UnsafeCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,31 @@ static ulong Test(ref ulong a)
return a;
}

public static void Execute()
private static unsafe bool StartsWithOrdinal(char* source, uint sourceLength, string value)
{
if (sourceLength < (uint)value.Length) return false;
for (int i = 0; i < value.Length; i++)
{
if (value[i] != source[i]) return false;
}
return true;
}

public static unsafe void TestFixed()
{
String pathAsString = @"0:\DiTest";
int pathLength = pathAsString.Length;
bool val1;
fixed (char* path = pathAsString)
{
val1 = StartsWithOrdinal(path, (uint)pathLength, "\\\\?\\");
}

Assert.IsTrue(val1 == false, "Path is not UNC path");
}

public static void Execute()
{
long val = Int64.MaxValue;
long* p = &val;
long newVal = *p;
Expand All @@ -50,8 +72,7 @@ public static void Execute()
//Console.WriteLine("asLong is : " + BitConverter.ToString(hexDump, 0));
//Assert.IsTrue(asLong == 0x3FF0000000000000, "DoubleToInt64Bits is wrong!");


TestFixed();
}

}
}
Loading

0 comments on commit e06efd8

Please sign in to comment.