diff --git a/Test.sln b/Test.sln index e3d1dc998..d81f077b7 100644 --- a/Test.sln +++ b/Test.sln @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Compiler.Tests.TypeS 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 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTest", "Tests\ConsoleTest\ConsoleTest.csproj", "{7A06CD95-A1D3-4989-A9F2-4088C27F8752}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -609,6 +611,14 @@ Global {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 + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Debug|x86.ActiveCfg = Debug|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Debug|x86.Build.0 = Debug|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Release|Any CPU.Build.0 = Release|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Release|x86.ActiveCfg = Release|Any CPU + {7A06CD95-A1D3-4989-A9F2-4088C27F8752}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -685,6 +695,7 @@ Global {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} + {7A06CD95-A1D3-4989-A9F2-4088C27F8752} = {ECEA7778-E786-4317-90B9-A2D4427CB91C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4418C803-277E-448F-A0A0-52788FA215AD} diff --git a/Tests/ConsoleTest/ConsoleTest.Cosmos b/Tests/ConsoleTest/ConsoleTest.Cosmos new file mode 100644 index 000000000..5ae2ea6d9 --- /dev/null +++ b/Tests/ConsoleTest/ConsoleTest.Cosmos @@ -0,0 +1,60 @@ + + + + Debug + 2.0 + {9246ba1f-fbdb-4b09-806a-7968bf4d3eb9} + false + ConsoleTestBoot + elf + v4.5.2 + + + + VMware + true + Source + User + False + false + Player + bin\Debug\ + ConsoleTestBoot + Use VMware Player or Workstation to deploy and debug. + ISO + VMware + Pipe: Cosmos\Serial + + + + Cosmos.HAL + {6a991d03-1435-4005-9809-b8bacdf3b021} + True + + + Cosmos.System + {3def0461-08ab-471a-8f03-a9c556652a0f} + True + + + Cosmos.TestRunner.Core + {758faf24-9974-4db8-82ef-1b64daf2f0bc} + True + + + ConsoleTest + {fb23bd72-aec3-485e-b86c-8e7db0b3bb9b} + + + + + + + + + + diff --git a/Tests/ConsoleTest/ConsoleTest.csproj b/Tests/ConsoleTest/ConsoleTest.csproj new file mode 100644 index 000000000..6bf358aa9 --- /dev/null +++ b/Tests/ConsoleTest/ConsoleTest.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0 + + + + + + + + + + + + + diff --git a/Tests/ConsoleTest/Kernel.cs b/Tests/ConsoleTest/Kernel.cs new file mode 100644 index 000000000..f3b2d49fb --- /dev/null +++ b/Tests/ConsoleTest/Kernel.cs @@ -0,0 +1,131 @@ +using System; +using Sys = Cosmos.System; +using Cosmos.TestRunner; +using Cosmos.System.Graphics; +using System.Text; +using Cosmos.System.ExtendedASCII; +using Cosmos.System.ScanMaps; + +/* + * Please note this is an atypical TestRunner: + * - no Assertion can be done + * - it cannot be executed automatically + * + * it exists to make easier tests while changing low level stuff (it would be better and faster to use the Demo kernel but + * sometimes it is a problem to make it see modifications done at low level) + * + * Remember to comment this test again on TestKernelSets.cs when you are ready to merge your modifications! + */ +namespace ConsoleTest +{ + public class Kernel : Sys.Kernel + { + protected override void BeforeRun() + { + Console.WriteLine("Cosmos booted successfully. Let's Test Console!"); + + /* This is needed to enable the Codepage based Encodings */ + Encoding.RegisterProvider(CosmosEncodingProvider.Instance); + } + + protected override void Run() + { + try + { + Console.Clear(); + + Console.WriteLine("Testing Console Enconding"); + + Console.WriteLine($"ConsoleInputEncoding {Console.InputEncoding.BodyName}"); + + Console.WriteLine($"ConsoleOutputEncoding {Console.OutputEncoding.BodyName}"); + + /* Let's change it in the legacy IBM437 encoding */ + Console.InputEncoding = Encoding.GetEncoding(437); + Console.OutputEncoding = Encoding.GetEncoding(437); + + Console.WriteLine($"ConsoleInputEncoding in now {Console.InputEncoding.BodyName}"); + Console.WriteLine($"ConsoleOutputEncoding in now {Console.OutputEncoding.BodyName}"); + + Console.WriteLine("Let's write some accented characters: èòàùì"); + Console.WriteLine("Let's print all the CP437 codepage"); + + Sys.Global.mDebugger.SendInternal(""); + + Console.Write("Ç ü é â ä à å ç ê ë è ï î ì Ä Å\n" + + "É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ\n" + + "á í ó ú ñ Ñ ª º ¿ ⌐ ¬ ½ ¼ ¡ « »\n" + + "░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐\n" + + "└ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧\n" + + "╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀\n" + + "α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩\n" + + "≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■ \u00A0\n"); + //Console.WriteLine(); + + Console.WriteLine("The following line should appear as a continuos line of '─'"); + Console.WriteLine("──────────────────────────────────────────────────────────"); + + Console.ReadKey(); + Console.WriteLine("The next line should be empty"); + Console.WriteLine(); + Console.WriteLine("True follows..."); + Console.WriteLine(true); + Console.WriteLine("The letter 'A'"); + Console.WriteLine('A'); + char[] charBuffer = new char[] { 'A', 'B', 'C' }; + Console.WriteLine("Then ABC"); + Console.WriteLine(charBuffer); + Console.WriteLine("...42.42"); + Console.WriteLine(42.42); + Console.WriteLine("...42.42 (float)"); + Console.WriteLine(42.42f); + Console.WriteLine("...42"); + Console.WriteLine(42); + Console.WriteLine("...42 (long)"); + Console.WriteLine(42L); + Console.ReadKey(); + object test = "Test"; + Console.WriteLine("...Test (as object)"); + Console.WriteLine(test); + Console.WriteLine("The next line should be empty (null object)"); + object s = null; + Console.WriteLine(s); + Console.WriteLine("...42 (uint)"); + Console.WriteLine(42U); + Console.WriteLine("...42 (ulong)"); + Console.WriteLine(42UL); + Console.WriteLine("...BC"); + Console.WriteLine(charBuffer, 1, 2); + + Console.WriteLine("Test Format arg0 {0}", "test"); + Console.WriteLine("Test Format arg0 {0} arg1 {1}", "test", 42); + Console.WriteLine("Test Format arg0 {0} arg1 {1} arg2 {2}", "test", 42, 69.69); + Console.WriteLine("Test Format arg0 {0} arg1 {1} arg2 {2} arg3 {3}", "test", 42, 69.69, 25000L); + /* String.Format does not support x or X and probably neither the rest of "special" formatting */ + //Console.WriteLine("Test Format (hex) {0:x}", 42); + + Console.WriteLine("Layout switched to DE..."); + SetKeyboardScanMap(new DE_Standard()); + Console.WriteLine("Write in germanic now I'll read it with Console.ReadLine()..."); + + var str = Console.ReadLine(); + Console.WriteLine($"You have written: {str}"); + + Console.WriteLine("Write in germanic now I'll read it with Console.ReadKey()..."); + var character = Console.ReadKey(); + Console.WriteLine($"You have written: {character.KeyChar}"); + + Console.WriteLine("Press any key to terminate this test..."); + + Console.ReadKey(); + TestController.Completed(); + } + catch (Exception e) + { + mDebugger.Send("Exception occurred: " + e.Message); + mDebugger.Send(e.Message); + TestController.Failed(); + } + } + } +} diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs b/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs index 25b2c1da2..a5c71d100 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs @@ -5,7 +5,6 @@ using Cosmos.TestRunner; using Sys = Cosmos.System; using Cosmos.Compiler.Tests.Bcl.System; using Cosmos.Compiler.Tests.Bcl.System.Collections.Generic; -using Cosmos.Compiler.Tests.Bcl.System.Collections.Not_Generic; namespace Cosmos.Compiler.Tests.Bcl { @@ -51,7 +50,6 @@ namespace Cosmos.Compiler.Tests.Bcl ListTest.Execute(); QueueTest.Execute(); //DictionaryTest.Execute(); - HashtableTest.Execute(); TestController.Completed(); } diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/Collections/Not Generic/HashtableTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/Collections/Not Generic/HashtableTest.cs deleted file mode 100644 index 700e6bdc7..000000000 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/Collections/Not Generic/HashtableTest.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections; -using Cosmos.TestRunner; -using Cosmos.Compiler.Tests.Bcl.Helper; -using Cosmos.Debug.Kernel; - -namespace Cosmos.Compiler.Tests.Bcl.System.Collections.Not_Generic -{ - class HashtableTest - { - public static void Execute() - { - var h = new Hashtable(); - h.Add(42, "Test"); - - Assert.IsTrue(h.ContainsKey(42), "Hashtable.ContainsKey() failed: existing key not found"); - Assert.IsFalse(h.ContainsKey(24), "Hashtable.ContainsKey() failed: not existing key not found"); - - /* This really requires Thread.Sleep() to work? */ - //Assert.IsTrue((string)h[42] == "Test", "Hashtable indexer not working"); - - } - } -} diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/EncodingTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/EncodingTest.cs deleted file mode 100644 index 1bbcb02fa..000000000 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/EncodingTest.cs +++ /dev/null @@ -1,369 +0,0 @@ -#define COSMOSDEBUG -using System; -using System.Collections.Generic; -using System.Text; -using Cosmos.TestRunner; -using Cosmos.Compiler.Tests.Bcl.Helper; -using Cosmos.Debug.Kernel; -using Cosmos.System.ExtendedASCII; - -namespace Cosmos.Compiler.Tests.Bcl.System -{ - class EncodingTest - { - static Debugger mDebugger = new Debugger("System", "Enconding Test"); - - 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 }; - static byte[] CP437EnglishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x20, - 0x77, 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6C, 0x21 }; - static byte[] CP437ItalianText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x8A, 0x20, 0x66, - 0x61, 0x6E, 0x74, 0x61, 0x73, 0x74, 0x69, 0x63, 0x6F, 0x21 }; - - static byte[] CP437SpanishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x65, 0x73, 0x20, - 0x67, 0x65, 0x6E, 0x69, 0x61, 0x6C, 0x21 }; - - static byte[] CP437GermanicText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x74, 0x20, - 0x67, 0x72, 0x6F, 0xE1, 0x61, 0x72, 0x74, 0x69, 0x67, 0x21 }; - static byte[] CP437GreekText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0xEE, 0x3F, 0x3F, 0xE0, - 0x3F, 0x20, 0x3F, 0xE3, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x21 }; - static byte[] CP437JapanaseText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, - 0x3F, 0x3F, 0x3F, 0x21 }; - static byte[] CP437GothicText = new byte[] { 0x3F, 0x3F }; - static byte[] CP858EnglishText = CP437EnglishText; - static byte[] CP858ItalianText = CP437ItalianText; - static byte[] CP858SpanishText = CP437SpanishText; - static byte[] CP858GermanicText = CP437GermanicText; - /* CP858 has no Greek characters they are all replaced by '?' (0x3F) */ - static byte[] CP858GreekText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, - 0x3F, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x21 }; - static byte[] CP858JapanaseText = CP437JapanaseText; - static byte[] CP858GothicText = CP437GothicText; - - static void TestGetBytes(Encoding xEncoding, string text, byte[] expectedResult, string desc) - { - byte[] result; - - result = xEncoding.GetBytes(text); - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), $"{xEncoding.BodyName} Encoding of {desc} text failed byte arrays different"); - } - - - static void TestGetString(Encoding xEncoding, byte[] bytes, string expectedText, string desc) - { - string text; - - text = xEncoding.GetString(bytes); - Assert.IsTrue((text == expectedText), $"{xEncoding.BodyName} Decoding of {desc} text failed strings different"); - } - - static void TestUTF8() - { - //Encoding xEncoding = new UTF8Encoding(); - Encoding xEncoding = Encoding.UTF8; - mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); - - Assert.IsTrue(xEncoding.BodyName == "UTF-8", "UTF8 BodyName failed not 'UTF-8"); - Assert.IsTrue(xEncoding.IsSingleByte == false, "UTF8.IsSingleByte failed: it returns true"); - - TestGetBytes(xEncoding, "Cosmos is wonderful!", UTF8EnglishText, "English"); - TestGetBytes(xEncoding, "Cosmos è fantastico!", UTF8ItalianText, "Italian"); - TestGetBytes(xEncoding, "Cosmos es genial!", UTF8SpanishText, "Spanish"); - TestGetBytes(xEncoding, "Cosmos ist großartig!", UTF8GermanicText, "Germanic"); - TestGetBytes(xEncoding, "Cosmos είναι υπέροχος!", UTF8GreekText, "Greek"); - TestGetBytes(xEncoding, "Cosmos 素晴らしいです!", UTF8JapanaseText, "Japanese"); - TestGetBytes(xEncoding, "𐍈", UTF8GothicText, "Gothic"); - - TestGetString(xEncoding, UTF8EnglishText, "Cosmos is wonderful!", "English"); - TestGetString(xEncoding, UTF8ItalianText, "Cosmos è fantastico!", "Italian"); - TestGetString(xEncoding, UTF8SpanishText, "Cosmos es genial!", "Spanish"); - TestGetString(xEncoding, UTF8GermanicText, "Cosmos ist großartig!", "Germanic"); - /* CP437 replaces not representable characters with '?' */ - TestGetString(xEncoding, UTF8GreekText, "Cosmos είναι υπέροχος!", "Greek"); - TestGetString(xEncoding, UTF8JapanaseText, "Cosmos 素晴らしいです!", "Japanese"); - TestGetString(xEncoding, UTF8GothicText, "𐍈", "Gothic"); - - mDebugger.SendInternal($"Finished Test {xEncoding.BodyName} Encoding / Decoding"); - } - - static void TestCP437() - { - Encoding xEncoding = Encoding.GetEncoding(437); - - mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); - - Assert.IsTrue(xEncoding.BodyName == "IBM437", "437 BodyName failed not 'IBM437"); - Assert.IsTrue(xEncoding.IsSingleByte == true, "437.IsSingleByte failed: it returns false"); - - TestGetBytes(xEncoding, "Cosmos is wonderful!", CP437EnglishText, "English"); - TestGetBytes(xEncoding, "Cosmos è fantastico!", CP437ItalianText, "Italian"); - TestGetBytes(xEncoding, "Cosmos es genial!", CP437SpanishText, "Spanish"); - TestGetBytes(xEncoding, "Cosmos ist großartig!", CP437GermanicText, "Germanic"); - /* - * From this point on a lot of characters will be replaced by 0x3F ('?') because - * cannot really represented on CP437 - */ - TestGetBytes(xEncoding, "Cosmos είναι υπέροχος!", CP437GreekText, "Greek"); - TestGetBytes(xEncoding, "Cosmos 素晴らしいです!", CP437JapanaseText, "Japanese"); - TestGetBytes(xEncoding, "𐍈", CP437GothicText, "Gothic"); - - TestGetString(xEncoding, CP437EnglishText, "Cosmos is wonderful!", "English"); - TestGetString(xEncoding, CP437ItalianText, "Cosmos è fantastico!", "Italian"); - TestGetString(xEncoding, CP437SpanishText, "Cosmos es genial!", "Spanish"); - TestGetString(xEncoding, CP437GermanicText, "Cosmos ist großartig!", "Germanic"); - /* CP437 replaces not representable characters with '?' */ - TestGetString(xEncoding, CP437GreekText, "Cosmos ε??α? ?π??????!", "Greek"); - TestGetString(xEncoding, CP437JapanaseText, "Cosmos ???????!", "Japanese"); - TestGetString(xEncoding, CP437GothicText, "??", "Gothic"); - - mDebugger.SendInternal("Finished Test {xEncoding.BodyName} Encoding / Decoding"); - } - - static void TestCP858() - { - Encoding xEncoding = Encoding.GetEncoding(858); - - mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); - - Assert.IsTrue(xEncoding.BodyName == "IBM00858", "858 BodyName failed not 'IBM00858"); - Assert.IsTrue(xEncoding.IsSingleByte == true, "858.IsSingleByte failed: it returns false"); - - TestGetBytes(xEncoding, "Cosmos is wonderful!", CP858EnglishText, "English"); - TestGetBytes(xEncoding, "Cosmos è fantastico!", CP858ItalianText, "Italian"); - TestGetBytes(xEncoding, "Cosmos es genial!", CP858SpanishText, "Spanish"); - TestGetBytes(xEncoding, "Cosmos ist großartig!", CP858GermanicText, "Germanic"); - /* - * From this point on a lot of characters will be replaced by 0x3F ('?') because - * cannot really represented on CP858 - */ - TestGetBytes(xEncoding, "Cosmos είναι υπέροχος!", CP858GreekText, "Greek"); - TestGetBytes(xEncoding, "Cosmos 素晴らしいです!", CP858JapanaseText, "Japanese"); - TestGetBytes(xEncoding, "𐍈", CP858GothicText, "Gothic"); - - TestGetString(xEncoding, CP858EnglishText, "Cosmos is wonderful!", "English"); - TestGetString(xEncoding, CP858ItalianText, "Cosmos è fantastico!", "Italian"); - TestGetString(xEncoding, CP858SpanishText, "Cosmos es genial!", "Spanish"); - TestGetString(xEncoding, CP858GermanicText, "Cosmos ist großartig!", "Germanic"); - /* CP858 replaces not representable characters with '?' */ - TestGetString(xEncoding, CP858GreekText, "Cosmos ????? ????????!", "Greek"); - TestGetString(xEncoding, CP858JapanaseText, "Cosmos ???????!", "Japanese"); - TestGetString(xEncoding, CP858GothicText, "??", "Gothic"); - - mDebugger.SendInternal("Finished Test CP858 Encoding / Decoding"); - } - -#if true - public static void Execute() - { - /* - * Net Core has removed all the legacy codepages from Encoding, only Unicode and ASCII are supported - * the correct way to add them is to create an Encoding Provider. - * Microsoft has created a CodePageEncodingProvider for this but it is too much complex to use it in - * Cosmos now, but we should use surely this in future. - * As a replacement for it I have created CosmosEncodingProvider that is more simple (but less efficient). - */ - Encoding.RegisterProvider(CosmosEncodingProvider.Instance); - - TestUTF8(); - // TestAscii(); - - TestCP437(); - TestCP858(); - } -#endif - -#if false - public static void Execute() - { - /* - * Net Core has removed all the legacy codepages from Encoding, only Unicode and ASCII are supported - * the correct way to add them is to create an Encoding Provider. - * Microsoft has created a CodePageEncodingProvider for this but it is too much complex to use it in - * Cosmos now, but we should use surely this in future. - * As a replacement for it I have created CosmosEncodingProvider that is more simple (but less efficient). - */ - Encoding.RegisterProvider(CosmosEncodingProvider.Instance); - - Encoding xEncoding = new UTF8Encoding(); - string text; - byte[] result; - byte[] expectedResult; - - Assert.IsTrue(!xEncoding.IsSingleByte, "IsSingleByte failed return true for UTF8"); - -#if true - mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); - - text = "Cosmos is wonderful!"; - result = xEncoding.GetBytes(text); - expectedResult = UTF8EnglishText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of English text failed byte arrays different"); - - text = "Cosmos è fantastico!"; - result = xEncoding.GetBytes(text); - expectedResult = UTF8ItalianText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Italian text failed byte arrays different"); - - text = "Cosmos es genial!"; - result = xEncoding.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 = xEncoding.GetBytes(text); - expectedResult = UTF8GermanicText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Germanic text failed byte arrays different"); - - text = "Cosmos είναι υπέροχος!"; - result = xEncoding.GetBytes(text); - expectedResult = UTF8GreekText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "UTF8 Encoding of Greek text failed byte arrays different"); - - text = "Cosmos 素晴らしいです!"; - result = xEncoding.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 = xEncoding.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 = xEncoding.GetString(UTF8EnglishText); - expectedText = "Cosmos is wonderful!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of English text failed strings different"); - - text = xEncoding.GetString(UTF8ItalianText); - expectedText = "Cosmos è fantastico!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Italian text failed strings different"); - - text = xEncoding.GetString(UTF8SpanishText); - expectedText = "Cosmos es genial!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Spanish text failed strings different"); - - text = xEncoding.GetString(UTF8GermanicText); - expectedText = "Cosmos ist großartig!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Germanic text failed strings different"); - - text = xEncoding.GetString(UTF8GreekText); - expectedText = "Cosmos είναι υπέροχος!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Greek text failed strings different"); - - text = xEncoding.GetString(UTF8JapanaseText); - expectedText = "Cosmos 素晴らしいです!"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Japanese text failed strings different"); - - text = xEncoding.GetString(UTF8GothicText); - expectedText = "𐍈"; - Assert.IsTrue((text == expectedText), "UTF8 Decoding of Gothic text failed strings different"); - - xEncoding = Encoding.ASCII; - - Assert.IsTrue(xEncoding.IsSingleByte, "IsSingleByte failed return false for ASCII"); - - text = "Cosmos is wonderful!"; - result = xEncoding.GetBytes(text); - expectedResult = UTF8EnglishText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "Ascii Encoding of English text failed byte arrays different"); -#endif - - xEncoding = Encoding.GetEncoding(437); - var yEncoding = Encoding.GetEncoding("IBM437"); - - Assert.IsTrue(xEncoding.CodePage == yEncoding.CodePage, "437 and 'IBM437' not the same Encoding"); - - Assert.IsTrue(xEncoding.IsSingleByte, "IsSingleByte failed return false for CP437"); - - text = "Cosmos is wonderful!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437EnglishText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of English text failed byte arrays different"); - - text = "Cosmos è fantastico!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437ItalianText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Italian text failed byte arrays different"); - - text = "Cosmos es genial!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437SpanishText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Spanish text failed byte arrays different"); - - text = "Cosmos ist großartig!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437GermanicText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Germanic text failed byte arrays different"); - - /* - * From this point on a lot of characters will be replaced by 0x3F ('?') because - * cannot be really represented on CP437 - */ - text = "Cosmos είναι υπέροχος!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437GreekText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Greek text failed byte arrays different"); - - text = "Cosmos 素晴らしいです!"; - result = xEncoding.GetBytes(text); - expectedResult = CP437JapanaseText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Japanese text failed byte arrays different"); - - text = "𐍈"; - result = xEncoding.GetBytes(text); - expectedResult = CP437GothicText; - Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), "CP437 Encoding of Gothic text failed byte arrays different"); - - //string expectedText; - /* Now we do the other way: we have a CP437 byte array and try to convert it in a UFT16 String */ - text = xEncoding.GetString(CP437EnglishText); - expectedText = "Cosmos is wonderful!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of English text failed strings different"); - - text = xEncoding.GetString(CP437ItalianText); - expectedText = "Cosmos è fantastico!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Italian text failed strings different"); - - text = xEncoding.GetString(CP437SpanishText); - expectedText = "Cosmos es genial!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Spanish text failed strings different"); - - text = xEncoding.GetString(CP437GermanicText); - expectedText = "Cosmos ist großartig!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Germanic text failed strings different"); - - /* CP437 replaces not representable characters with '?' */ - text = xEncoding.GetString(CP437GreekText); - expectedText = "Cosmos ε??α? ?π??????!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Greek text failed strings different"); - - text = xEncoding.GetString(CP437JapanaseText); - expectedText = "Cosmos ???????!"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Japanese text failed strings different"); - - text = xEncoding.GetString(CP437GothicText); - expectedText = "??"; - Assert.IsTrue((text == expectedText), "CP437 Decoding of Gothic text failed strings different"); - } -#endif - } -} diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/Text/EncodingTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/Text/EncodingTest.cs new file mode 100644 index 000000000..a689c03bc --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/Text/EncodingTest.cs @@ -0,0 +1,192 @@ +#define COSMOSDEBUG +using System; +using System.Collections.Generic; +using System.Text; +using Cosmos.TestRunner; +using Cosmos.Compiler.Tests.Bcl.Helper; +using Cosmos.Debug.Kernel; +using Cosmos.System.ExtendedASCII; + +namespace Cosmos.Compiler.Tests.Bcl.System +{ + class EncodingTest + { + static Debugger mDebugger = new Debugger("System", "Enconding Test"); + + 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 }; + static byte[] CP437EnglishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x20, + 0x77, 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6C, 0x21 }; + static byte[] CP437ItalianText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x8A, 0x20, 0x66, + 0x61, 0x6E, 0x74, 0x61, 0x73, 0x74, 0x69, 0x63, 0x6F, 0x21 }; + + static byte[] CP437SpanishText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x65, 0x73, 0x20, + 0x67, 0x65, 0x6E, 0x69, 0x61, 0x6C, 0x21 }; + + static byte[] CP437GermanicText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x74, 0x20, + 0x67, 0x72, 0x6F, 0xE1, 0x61, 0x72, 0x74, 0x69, 0x67, 0x21 }; + static byte[] CP437GreekText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0xEE, 0x3F, 0x3F, 0xE0, + 0x3F, 0x20, 0x3F, 0xE3, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x21 }; + static byte[] CP437JapanaseText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, + 0x3F, 0x3F, 0x3F, 0x21 }; + static byte[] CP437GothicText = new byte[] { 0x3F, 0x3F }; + static byte[] CP858EnglishText = CP437EnglishText; + static byte[] CP858ItalianText = CP437ItalianText; + static byte[] CP858SpanishText = CP437SpanishText; + static byte[] CP858GermanicText = CP437GermanicText; + /* CP858 has no Greek characters they are all replaced by '?' (0x3F) */ + static byte[] CP858GreekText = new byte[] { 0x43, 0x6F, 0x73, 0x6D, 0x6F, 0x73, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, + 0x3F, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x21 }; + static byte[] CP858JapanaseText = CP437JapanaseText; + static byte[] CP858GothicText = CP437GothicText; + + static void TestGetBytes(Encoding xEncoding, string xName, string text, byte[] expectedResult, string desc) + { + byte[] result; + + result = xEncoding.GetBytes(text); + Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), $"{xName} Encoding of {desc} text failed byte arrays different"); + } + + + static void TestGetString(Encoding xEncoding, string xName, byte[] bytes, string expectedText, string desc) + { + string text; + + text = xEncoding.GetString(bytes); + Assert.IsTrue((text == expectedText), $"{xName} Decoding of {desc} text failed strings different"); + } + + static void TestUTF8() + { + //Encoding xEncoding = new UTF8Encoding(); + Encoding xEncoding = Encoding.UTF8; + mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); + + Assert.IsTrue(xEncoding.IsSingleByte == false, "UTF8.IsSingleByte failed: it returns true"); + + string BodyName = xEncoding.BodyName; + Assert.IsTrue(BodyName == "UTF-8", "UTF8 BodyName failed not 'UTF-8"); + + TestGetBytes(xEncoding, BodyName, "Cosmos is wonderful!", UTF8EnglishText, "English"); + TestGetBytes(xEncoding, BodyName, "Cosmos è fantastico!", UTF8ItalianText, "Italian"); + TestGetBytes(xEncoding, BodyName, "Cosmos es genial!", UTF8SpanishText, "Spanish"); + TestGetBytes(xEncoding, BodyName, "Cosmos ist großartig!", UTF8GermanicText, "Germanic"); + TestGetBytes(xEncoding, BodyName, "Cosmos είναι υπέροχος!", UTF8GreekText, "Greek"); + TestGetBytes(xEncoding, BodyName, "Cosmos 素晴らしいです!", UTF8JapanaseText, "Japanese"); + TestGetBytes(xEncoding, BodyName, "𐍈", UTF8GothicText, "Gothic"); + + TestGetString(xEncoding, BodyName, UTF8EnglishText, "Cosmos is wonderful!", "English"); + TestGetString(xEncoding, BodyName, UTF8ItalianText, "Cosmos è fantastico!", "Italian"); + TestGetString(xEncoding, BodyName, UTF8SpanishText, "Cosmos es genial!", "Spanish"); + TestGetString(xEncoding, BodyName, UTF8GermanicText, "Cosmos ist großartig!", "Germanic"); + /* CP437 replaces not representable characters with '?' */ + TestGetString(xEncoding, BodyName, UTF8GreekText, "Cosmos είναι υπέροχος!", "Greek"); + TestGetString(xEncoding, BodyName, UTF8JapanaseText, "Cosmos 素晴らしいです!", "Japanese"); + TestGetString(xEncoding, BodyName, UTF8GothicText, "𐍈", "Gothic"); + + mDebugger.SendInternal($"Finished Test {BodyName} Encoding / Decoding"); + } + + static void TestCP437() + { + Encoding xEncoding = Encoding.GetEncoding(437); + + mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); + + Assert.IsTrue(xEncoding.IsSingleByte == true, "437.IsSingleByte failed: it returns false"); + + string BodyName = xEncoding.BodyName; + Assert.IsTrue(BodyName == "IBM437", "437 BodyName failed not 'IBM437"); + + TestGetBytes(xEncoding, BodyName, "Cosmos is wonderful!", CP437EnglishText, "English"); + TestGetBytes(xEncoding, BodyName, "Cosmos è fantastico!", CP437ItalianText, "Italian"); + TestGetBytes(xEncoding, BodyName, "Cosmos es genial!", CP437SpanishText, "Spanish"); + TestGetBytes(xEncoding, BodyName, "Cosmos ist großartig!", CP437GermanicText, "Germanic"); + /* + * From this point on a lot of characters will be replaced by 0x3F ('?') because + * cannot really represented on CP437 + */ + TestGetBytes(xEncoding, BodyName, "Cosmos είναι υπέροχος!", CP437GreekText, "Greek"); + TestGetBytes(xEncoding, BodyName, "Cosmos 素晴らしいです!", CP437JapanaseText, "Japanese"); + TestGetBytes(xEncoding, BodyName, "𐍈", CP437GothicText, "Gothic"); + + TestGetString(xEncoding, BodyName, CP437EnglishText, "Cosmos is wonderful!", "English"); + TestGetString(xEncoding, BodyName, CP437ItalianText, "Cosmos è fantastico!", "Italian"); + TestGetString(xEncoding, BodyName, CP437SpanishText, "Cosmos es genial!", "Spanish"); + TestGetString(xEncoding, BodyName, CP437GermanicText, "Cosmos ist großartig!", "Germanic"); + /* CP437 replaces not representable characters with '?' */ + TestGetString(xEncoding, BodyName, CP437GreekText, "Cosmos ε??α? ?π??????!", "Greek"); + TestGetString(xEncoding, BodyName, CP437JapanaseText, "Cosmos ???????!", "Japanese"); + TestGetString(xEncoding, BodyName, CP437GothicText, "??", "Gothic"); + + mDebugger.SendInternal($"Finished Test {BodyName} Encoding / Decoding"); + } + + static void TestCP858() + { + Encoding xEncoding = Encoding.GetEncoding(858); + + mDebugger.SendInternal($"Starting Test {xEncoding.BodyName} Encoding / Decoding"); + + Assert.IsTrue(xEncoding.IsSingleByte == true, "858.IsSingleByte failed: it returns false"); + + string BodyName = xEncoding.BodyName; + Assert.IsTrue(BodyName == "IBM00858", "858 BodyName failed not 'IBM00858"); + + TestGetBytes(xEncoding, BodyName, "Cosmos è fantastico!", CP858ItalianText, "Italian"); + TestGetBytes(xEncoding, BodyName, "Cosmos es genial!", CP858SpanishText, "Spanish"); + TestGetBytes(xEncoding, BodyName, "Cosmos ist großartig!", CP858GermanicText, "Germanic"); + /* + * From this point on a lot of characters will be replaced by 0x3F ('?') because + * cannot really represented on CP858 + */ + TestGetBytes(xEncoding, BodyName, "Cosmos είναι υπέροχος!", CP858GreekText, "Greek"); + TestGetBytes(xEncoding, BodyName, "Cosmos 素晴らしいです!", CP858JapanaseText, "Japanese"); + TestGetBytes(xEncoding, BodyName, "𐍈", CP858GothicText, "Gothic"); + + TestGetString(xEncoding, BodyName, CP858EnglishText, "Cosmos is wonderful!", "English"); + TestGetString(xEncoding, BodyName, CP858ItalianText, "Cosmos è fantastico!", "Italian"); + TestGetString(xEncoding, BodyName, CP858SpanishText, "Cosmos es genial!", "Spanish"); + TestGetString(xEncoding, BodyName, CP858GermanicText, "Cosmos ist großartig!", "Germanic"); + /* CP858 replaces not representable characters with '?' */ + TestGetString(xEncoding, BodyName, CP858GreekText, "Cosmos ????? ????????!", "Greek"); + TestGetString(xEncoding, BodyName, CP858JapanaseText, "Cosmos ???????!", "Japanese"); + TestGetString(xEncoding, BodyName, CP858GothicText, "??", "Gothic"); + + mDebugger.SendInternal($"Finished Test {BodyName} Encoding / Decoding"); + } + + public static void Execute() + { + /* + * Net Core has removed all the legacy codepages from Encoding, only Unicode and ASCII are supported + * the correct way to add them is to create an Encoding Provider. + * Microsoft has created a CodePageEncodingProvider for this but it is too much complex to use it in + * Cosmos now, but we should use surely this in future. + * As a replacement for it I have created CosmosEncodingProvider that is more simple (but less efficient). + */ + Encoding.RegisterProvider(CosmosEncodingProvider.Instance); + + TestUTF8(); + TestCP437(); + TestCP858(); + } + } +} diff --git a/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj b/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj index c0ad9bf07..343cab4ed 100644 --- a/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj +++ b/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj @@ -50,6 +50,7 @@ + diff --git a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs index 7606259dc..1629f772a 100644 --- a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs +++ b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs @@ -36,6 +36,8 @@ namespace Cosmos.TestRunner.Core /* Please see the notes on the kernel itself before enabling it */ //yield return typeof(GraphicTest.Kernel); + /* Please see the notes on the kernel itself before enabling it */ + //yield return typeof(ConsoleTest.Kernel); } } } diff --git a/source/Cosmos.Core_Plugs/System/DelegateImpl.cs b/source/Cosmos.Core_Plugs/System/DelegateImpl.cs index 5c6326e00..48d81902a 100644 --- a/source/Cosmos.Core_Plugs/System/DelegateImpl.cs +++ b/source/Cosmos.Core_Plugs/System/DelegateImpl.cs @@ -5,18 +5,17 @@ using IL2CPU.API.Attribs; namespace Cosmos.Core_Plugs.System { - [Plug(Target = typeof(Delegate))] + [Plug(Target = typeof(Delegate), Inheritable = true)] + [PlugField(FieldType = typeof(int), FieldId = "$$ArgSize$$")] + [PlugField(FieldType = typeof(int), FieldId = "$$ReturnsValue$$")] public static class DelegateImpl { - [PlugMethod(Signature = "System_Boolean__System_Delegate_Equals_System_Object_")] public static bool Equals(Delegate aThis, object aThat) { // todo: implement proper Delegate.Equals(object) - //return false; - throw new NotImplementedException(); + return false; } - [PlugMethod(Signature = "System_Boolean__System_Delegate_InternalEqualTypes_System_Object__System_Object_")] public static unsafe bool InternalEqualTypes([ObjectPointerAccess] uint** a, [ObjectPointerAccess] uint** b) { var xTypeA = a[0][0]; @@ -24,13 +23,7 @@ namespace Cosmos.Core_Plugs.System return xTypeA == xTypeB; } - } - [Plug(Target = typeof(Delegate), Inheritable = true)] - [PlugField(FieldType = typeof(int), FieldId = "$$ArgSize$$")] - [PlugField(FieldType = typeof(int), FieldId = "$$ReturnsValue$$")] - public static class DelegateImplInherit - { [PlugMethod(Signature = "System_MulticastDelegate__System_Delegate_InternalAllocLike_System_Delegate_")] public static unsafe uint InternalAllocLike(uint* aDelegate) { diff --git a/source/Cosmos.Core_Plugs/System/Globalization/CultureInfoImpl.cs b/source/Cosmos.Core_Plugs/System/Globalization/CultureInfoImpl.cs index 385244871..a498cbbce 100644 --- a/source/Cosmos.Core_Plugs/System/Globalization/CultureInfoImpl.cs +++ b/source/Cosmos.Core_Plugs/System/Globalization/CultureInfoImpl.cs @@ -19,15 +19,9 @@ namespace Cosmos.Core_Plugs.System.Globalization public static int GetHashCode(CultureInfo aThis) { - throw new NotImplementedException("CultureInfo.GetHashCode()"); + throw new NotImplementedException(); } - public static bool Equals(CultureInfo aThis, object value) - { - throw new NotImplementedException("CultureInfo.Equals()"); - } - - public static void CCtor() { } diff --git a/source/Cosmos.Core_Plugs/System/Text/ASCIIEncodingImpl.cs b/source/Cosmos.Core_Plugs/System/Text/ASCIIEncodingImpl.cs deleted file mode 100644 index 47c50f6df..000000000 --- a/source/Cosmos.Core_Plugs/System/Text/ASCIIEncodingImpl.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Text; -using IL2CPU.API.Attribs; - -namespace Cosmos.Core_Plugs.System.Text -{ - [Plug(Target = typeof(ASCIIEncoding))] - public class ASCIIEncodingImpl - { - - // TODO: remove this function - // old comment :Plug string.GetStringFromEncoding instead - /*public static string GetString(byte[] aBytes, int aIndex, int aCount) { - if (aBytes.Length == 0) { - return string.Empty; - } else { - return new string(Encoding.ASCII.GetChars(aBytes, aIndex, aCount)); - /*var xChars = new char[aBytes.Length]; - for (int i = 0; i < aBytes.Length; i++) { - xChars[i] = (char)aBytes[i]; - } - return new string(xChars); - } - }*/ - } -} diff --git a/source/Cosmos.HAL2/DebugTextScreen.cs b/source/Cosmos.HAL2/DebugTextScreen.cs index 336750d92..619faa774 100644 --- a/source/Cosmos.HAL2/DebugTextScreen.cs +++ b/source/Cosmos.HAL2/DebugTextScreen.cs @@ -62,7 +62,7 @@ namespace Cosmos.HAL private int mCurrentY = 1; - public override char this[int x, int y] + public override byte this[int x, int y] { get { @@ -79,7 +79,7 @@ namespace Cosmos.HAL }); mCurrentY = y; } - SendChar(new []{value}); + SendChar(new []{(char)value}); } } diff --git a/source/Cosmos.HAL2/TextScreen.cs b/source/Cosmos.HAL2/TextScreen.cs index 52d26109b..dca9b8296 100644 --- a/source/Cosmos.HAL2/TextScreen.cs +++ b/source/Cosmos.HAL2/TextScreen.cs @@ -61,17 +61,17 @@ namespace Cosmos.HAL IO.Memory.Fill(mScrollSize, mRow2Addr, mBackgroundClearCellValue); } - public override char this[int aX, int aY] + public override byte this[int aX, int aY] { get { var xScreenOffset = (UInt32)((aX + aY * Cols) * 2); - return (char)mRAM[xScreenOffset]; + return (byte)mRAM[xScreenOffset]; } set { var xScreenOffset = (UInt32)((aX + aY * Cols) * 2); - mRAM[xScreenOffset] = (byte)value; + mRAM[xScreenOffset] = value; mRAM[xScreenOffset + 1] = Color; } } diff --git a/source/Cosmos.HAL2/TextScreenBase.cs b/source/Cosmos.HAL2/TextScreenBase.cs index bba090979..efad679b6 100644 --- a/source/Cosmos.HAL2/TextScreenBase.cs +++ b/source/Cosmos.HAL2/TextScreenBase.cs @@ -39,7 +39,7 @@ namespace Cosmos.HAL public abstract void ScrollUp(); - public abstract char this[int x, int y] + public abstract byte this[int x, int y] { get; set; @@ -52,4 +52,4 @@ namespace Cosmos.HAL public abstract void SetCursorVisible(bool value); } -} \ No newline at end of file +} diff --git a/source/Cosmos.System2/Console.cs b/source/Cosmos.System2/Console.cs index 4c47c77b6..f8267d284 100644 --- a/source/Cosmos.System2/Console.cs +++ b/source/Cosmos.System2/Console.cs @@ -1,11 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using Cosmos.HAL; namespace Cosmos.System { public class Console { + private const byte LineFeed = (byte)'\n'; + private const byte CarriageReturn = (byte)'\r'; + private const byte Tab = (byte)'\t'; + private const byte Space = (byte)' '; + protected int mX = 0; public int X { get { return mX; } @@ -58,7 +64,7 @@ namespace Cosmos.System { mText.SetCursorPos(mX, mY); } - public void NewLine() { + private void DoLineFeed() { mY++; mX = 0; if (mY == mText.Rows) { @@ -68,555 +74,61 @@ namespace Cosmos.System { UpdateCursor(); } - public void WriteChar(char aChar) { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DoCarriageReturn() { + mX = 0; + UpdateCursor(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void DoTab() + { + Write(Space); + Write(Space); + Write(Space); + Write(Space); + } + + public void Write(byte aChar) + { mText[mX, mY] = aChar; mX++; - if (mX == mText.Cols) { - NewLine(); + if (mX == mText.Cols) + { + DoLineFeed(); } UpdateCursor(); } - public void WriteLine(string aText) { - Write(aText); - NewLine(); - } - //TODO: Optimize this - public void Write(string aText) { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Write(byte[] aText) + { if (aText == null) { return; } - for (int i = 0; i < aText.Length; i++) { - if (aText[i] == '\n') { - NewLine(); - } else if (aText[i] == '\r') { - mX = 0; - UpdateCursor(); - } else if (aText[i] == '\t') { - //Write(" "); - WriteChar(' '); - WriteChar(' '); - WriteChar(' '); - WriteChar(' '); - } - //Extended ASCII Support - else if (aText[i] == 'Ç') - { - WriteChar((char)128); - } - else if (aText[i] == 'ü') - { - WriteChar((char)129); - } - else if (aText[i] == 'é') - { - WriteChar((char)130); - } - else if (aText[i] == 'â') - { - WriteChar((char)131); - } - else if (aText[i] == 'ä') - { - WriteChar((char)132); - } - else if (aText[i] == 'à') - { - WriteChar((char)133); - } - else if (aText[i] == 'å') - { - WriteChar((char)134); - } - else if (aText[i] == 'ç') - { - WriteChar((char)135); - } - else if (aText[i] == 'ê') - { - WriteChar((char)136); - } - else if (aText[i] == 'ë') - { - WriteChar((char)137); - } - else if (aText[i] == 'è') - { - WriteChar((char)138); - } - else if (aText[i] == 'ï') - { - WriteChar((char)139); - } - else if (aText[i] == 'î') - { - WriteChar((char)140); - } - else if (aText[i] == 'ì') - { - WriteChar((char)141); - } - else if (aText[i] == 'Ä') - { - WriteChar((char)142); - } - else if (aText[i] == 'Å') - { - WriteChar((char)143); - } - else if (aText[i] == 'É') - { - WriteChar((char)144); - } - else if (aText[i] == 'æ') - { - WriteChar((char)145); - } - else if (aText[i] == 'Æ') - { - WriteChar((char)146); - } - else if (aText[i] == 'ô') - { - WriteChar((char)147); - } - else if (aText[i] == 'ö') - { - WriteChar((char)148); - } - else if (aText[i] == 'ò') - { - WriteChar((char)149); - } - else if (aText[i] == 'û') - { - WriteChar((char)150); - } - else if (aText[i] == 'ù') - { - WriteChar((char)151); - } - else if (aText[i] == 'ÿ') - { - WriteChar((char)152); - } - else if (aText[i] == 'Ö') - { - WriteChar((char)153); - } - else if (aText[i] == 'Ü') - { - WriteChar((char)154); - } - else if (aText[i] == 'ø') - { - WriteChar((char)155); - } - else if (aText[i] == '£') - { - WriteChar((char)156); - } - else if (aText[i] == 'Ø') - { - WriteChar((char)157); - } - else if (aText[i] == '×') - { - WriteChar((char)158); - } - else if (aText[i] == 'ƒ') - { - WriteChar((char)159); - } - else if (aText[i] == 'á') - { - WriteChar((char)160); - } - else if (aText[i] == 'í') - { - WriteChar((char)161); - } - else if (aText[i] == 'ó') - { - WriteChar((char)162); - } - else if (aText[i] == 'ú') - { - WriteChar((char)163); - } - else if (aText[i] == 'ñ') - { - WriteChar((char)164); - } - else if (aText[i] == 'Ñ') - { - WriteChar((char)165); - } - else if (aText[i] == 'ª') - { - WriteChar((char)166); - } - else if (aText[i] == 'º') - { - WriteChar((char)167); - } - else if (aText[i] == '¿') - { - WriteChar((char)168); - } - else if (aText[i] == '®') - { - WriteChar((char)169); - } - else if (aText[i] == '¬') - { - WriteChar((char)170); - } - else if (aText[i] == '½') - { - WriteChar((char)171); - } - else if (aText[i] == '¼') - { - WriteChar((char)172); - } - else if (aText[i] == '¡') - { - WriteChar((char)173); - } - else if (aText[i] == '«') - { - WriteChar((char)174); - } - else if (aText[i] == '»') - { - WriteChar((char)175); - } - else if (aText[i] == '░') - { - WriteChar((char)176); - } - else if (aText[i] == '▒') - { - WriteChar((char)177); - } - else if (aText[i] == '▓') - { - WriteChar((char)178); - } - else if (aText[i] == '│') - { - WriteChar((char)179); - } - else if (aText[i] == '┤') - { - WriteChar((char)180); - } - else if (aText[i] == 'Á') - { - WriteChar((char)181); - } - else if (aText[i] == 'Â') - { - WriteChar((char)182); - } - else if (aText[i] == 'À') - { - WriteChar((char)183); - } - else if (aText[i] == '©') - { - WriteChar((char)184); - } - else if (aText[i] == '╣') - { - WriteChar((char)185); - } - else if (aText[i] == '║') - { - WriteChar((char)186); - } - else if (aText[i] == '╗') - { - WriteChar((char)187); - } - else if (aText[i] == '╝') - { - WriteChar((char)188); - } - else if (aText[i] == '¢') - { - WriteChar((char)189); - } - else if (aText[i] == '¥') - { - WriteChar((char)190); - } - else if (aText[i] == '┐') - { - WriteChar((char)191); - } - else if (aText[i] == '└') - { - WriteChar((char)192); - } - else if (aText[i] == '┴') - { - WriteChar((char)193); - } - else if (aText[i] == '┬') - { - WriteChar((char)194); - } - else if (aText[i] == '├') - { - WriteChar((char)195); - } - else if (aText[i] == '─') - { - WriteChar((char)196); - } - else if (aText[i] == '┼') - { - WriteChar((char)197); - } - else if (aText[i] == 'ã') - { - WriteChar((char)198); - } - else if (aText[i] == 'Ã') - { - WriteChar((char)199); - } - else if (aText[i] == '╚') - { - WriteChar((char)200); - } - else if (aText[i] == '╔') - { - WriteChar((char)201); - } - else if (aText[i] == '╩') - { - WriteChar((char)202); - } - else if (aText[i] == '╦') - { - WriteChar((char)203); - } - else if (aText[i] == '╠') - { - WriteChar((char)204); - } - else if (aText[i] == '═') - { - WriteChar((char)205); - } - else if (aText[i] == '╬') - { - WriteChar((char)206); - } - else if (aText[i] == '¤') - { - WriteChar((char)207); - } - else if (aText[i] == 'ð') - { - WriteChar((char)208); - } - else if (aText[i] == 'Ð') - { - WriteChar((char)209); - } - else if (aText[i] == 'Ê') - { - WriteChar((char)210); - } - else if (aText[i] == 'Ë') - { - WriteChar((char)211); - } - else if (aText[i] == 'È') - { - WriteChar((char)212); - } - else if (aText[i] == 'ı') - { - WriteChar((char)213); - } - else if (aText[i] == 'Í') - { - WriteChar((char)214); - } - else if (aText[i] == 'Î') - { - WriteChar((char)215); - } - else if (aText[i] == 'Ï') - { - WriteChar((char)216); - } - else if (aText[i] == '┘') - { - WriteChar((char)217); - } - else if (aText[i] == '┌') - { - WriteChar((char)218); - } - else if (aText[i] == '█') - { - WriteChar((char)219); - } - else if (aText[i] == '▄') - { - WriteChar((char)220); - } - else if (aText[i] == '¦') - { - WriteChar((char)221); - } - else if (aText[i] == 'Ì') - { - WriteChar((char)222); - } - else if (aText[i] == '▀') - { - WriteChar((char)223); - } - else if (aText[i] == 'Ó') - { - WriteChar((char)224); - } - else if (aText[i] == 'ß') - { - WriteChar((char)225); - } - else if (aText[i] == 'Ô') - { - WriteChar((char)226); - } - else if (aText[i] == 'Ò') - { - WriteChar((char)227); - } - else if (aText[i] == 'õ') - { - WriteChar((char)228); - } - else if (aText[i] == 'Õ') - { - WriteChar((char)229); - } - else if (aText[i] == 'µ') - { - WriteChar((char)230); - } - else if (aText[i] == 'þ') - { - WriteChar((char)231); - } - else if (aText[i] == 'Þ') - { - WriteChar((char)232); - } - else if (aText[i] == 'Ú') - { - WriteChar((char)233); - } - else if (aText[i] == 'Û') - { - WriteChar((char)234); - } - else if (aText[i] == 'Ù') - { - WriteChar((char)235); - } - else if (aText[i] == 'ý') - { - WriteChar((char)236); - } - else if (aText[i] == 'Ý') - { - WriteChar((char)237); - } - else if (aText[i] == '¯') - { - WriteChar((char)238); - } - else if (aText[i] == '´') - { - WriteChar((char)239); - } - else if (aText[i] == '≡') - { - WriteChar((char)240); - } - else if (aText[i] == '±') - { - WriteChar((char)241); - } - else if (aText[i] == '‗') - { - WriteChar((char)242); - } - else if (aText[i] == '¾') - { - WriteChar((char)243); - } - else if (aText[i] == '¶') - { - WriteChar((char)244); - } - else if (aText[i] == '§') - { - WriteChar((char)245); - } - else if (aText[i] == '÷') - { - WriteChar((char)246); - } - else if (aText[i] == '¸') - { - WriteChar((char)247); - } - else if (aText[i] == '°') - { - WriteChar((char)248); - } - else if (aText[i] == '¨') - { - WriteChar((char)249); - } - else if (aText[i] == '·') - { - WriteChar((char)250); - } - else if (aText[i] == '¹') - { - WriteChar((char)251); - } - else if (aText[i] == '³') - { - WriteChar((char)252); - } - else if (aText[i] == '²') - { - WriteChar((char)253); - } - else if (aText[i] == '■') - { - WriteChar((char)254); - } - else if (aText[i] == ' ') - { - WriteChar((char)255); - } - else { - WriteChar(aText[i]); + for (int i = 0; i < aText.Length; i++) + { + switch (aText[i]) + { + case LineFeed: + DoLineFeed(); + break; + + case CarriageReturn: + DoCarriageReturn(); + break; + + case Tab: + DoTab(); + break; + + /* Normal characters, simply write them */ + default: + Write(aText[i]); + break; } } } diff --git a/source/Cosmos.System2/Keyboard/KeyboardManager.cs b/source/Cosmos.System2/Keyboard/KeyboardManager.cs index 6bf3fa843..8965bbb71 100644 --- a/source/Cosmos.System2/Keyboard/KeyboardManager.cs +++ b/source/Cosmos.System2/Keyboard/KeyboardManager.cs @@ -8,6 +8,8 @@ using Cosmos.Debug.Kernel; using Cosmos.HAL; using Cosmos.System.ScanMaps; +using MyConsole = System.Console; + namespace Cosmos.System { public static class KeyboardManager @@ -113,7 +115,8 @@ public static List Keyboards = new List(); { if (ControlPressed && AltPressed && _scanMap.ScanCodeMatchesKey(key, ConsoleKeyEx.Delete)) { - Global.Console.WriteLine("Detected Ctrl-Alt-Delete! Rebooting System..."); + //Global.Console.WriteLine("Detected Ctrl-Alt-Delete! Rebooting System..."); + MyConsole.WriteLine("Detected Ctrl-Alt-Delete! Rebooting System..."); Power.Reboot(); } diff --git a/source/Cosmos.System2/Text/CP437Encoding.cs b/source/Cosmos.System2/Text/CP437Encoding.cs index 3f88d0df5..56888343d 100644 --- a/source/Cosmos.System2/Text/CP437Encoding.cs +++ b/source/Cosmos.System2/Text/CP437Encoding.cs @@ -12,23 +12,15 @@ namespace Cosmos.System.ExtendedASCII myDebugger.SendInternal("CP437Enconding Setting CodePageTable only one time..."); CodePageTable = new char[] { - 'Ç', 'ü', 'é', 'â', 'ä', 'à', 'å', 'ç', - 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å', - 'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', - 'ÿ', 'Ö', 'Ü', '¢', '£', '¥', '₧', 'ƒ', - 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', - '¿', '⌐', '¬', '½', '¼', '¡', '«', '»', - '░', '▒', '▓', '│', '┤', '╡', '╢', '╖', - '╕', '╣', '║', '╗', '╝', '╜', '╛', '┐', - '└', '┴', '┬', '├', '─', '┼', '╞', '╟', - '╚', '╔', '╩', '╦','╠', '═', '╬', '╧', - '╨', '╤', '╥', '╙', '╘', '╒', '╓','╫', - '╪', '┘', '┌', '█', '▄', '▌', '▐', '▀', - 'α', 'ß', 'Γ', 'π', 'Σ', 'σ', 'µ', 'τ', - 'Φ', 'Θ', 'Ω', 'δ', '∞', 'φ', 'ε', '∩', - '≡', '±', '≥', '≤', '⌠', '⌡', '÷', '≈', - '°', '∙', '·', '√', 'ⁿ', '²', '■', '\x00A0' - }; + 'Ç' , 'ü' , 'é' , 'â' , 'ä' , 'à' , 'å' , 'ç' , 'ê' , 'ë' , 'è' , 'ï' , 'î' , 'ì' , 'Ä' , 'Å' , + 'É' , 'æ' , 'Æ' , 'ô' , 'ö' , 'ò' , 'û' , 'ù' , 'ÿ' , 'Ö' , 'Ü' , '¢' , '£' , '¥' , '₧' , 'ƒ' , + 'á' , 'í' , 'ó' , 'ú' , 'ñ' , 'Ñ' , 'ª' , 'º' , '¿' , '⌐' , '¬' , '½' , '¼' , '¡' , '«' , '»' , + '░' , '▒' , '▓' , '│' , '┤' , '╡' , '╢' , '╖' , '╕' , '╣' , '║' , '╗' , '╝' , '╜' , '╛' , '┐' , + '└' , '┴' , '┬' , '├' , '─' , '┼' , '╞' , '╟' , '╚' , '╔' , '╩' , '╦' , '╠' , '═' , '╬' , '╧' , + '╨' , '╤' , '╥' , '╙' , '╘' , '╒' , '╓' , '╫' , '╪' , '┘' , '┌' , '█' , '▄' , '▌' , '▐' , '▀' , + 'α' , 'ß' , 'Γ' , 'π' , 'Σ' , 'σ' , 'µ' , 'τ' , 'Φ' , 'Θ' , 'Ω' , 'δ' , '∞' , 'φ' , 'ε' , '∩' , + '≡' , '±' , '≥' , '≤' , '⌠' , '⌡' , '÷' , '≈' , '°' , '∙' , '·' , '√' , 'ⁿ' , '²' , '■' , '\x00A0' + }; } public override string BodyName => "IBM437"; diff --git a/source/Cosmos.System2/Text/SingleByteEncoding.cs b/source/Cosmos.System2/Text/SingleByteEncoding.cs index 1a800d457..3aee1b031 100644 --- a/source/Cosmos.System2/Text/SingleByteEncoding.cs +++ b/source/Cosmos.System2/Text/SingleByteEncoding.cs @@ -61,8 +61,6 @@ namespace Cosmos.System.ExtendedASCII private byte GetByte(char ch) { - //mDebugger.SendInternal($"Converting to CodePageTable ch {ch} (codepoint) {(int)ch}"); - /* ch is in reality an ASCII character? */ if (ch < 127) { @@ -70,7 +68,6 @@ namespace Cosmos.System.ExtendedASCII return (byte)ch; } - mDebugger.SendInternal($"ch {ch} could be Extended Ascii"); int idx = GetCodePageIdxFromChr(ch); if (idx == -1) { @@ -129,9 +126,8 @@ namespace Cosmos.System.ExtendedASCII private char GetChar(byte b) { mDebugger.SendInternal($"Converting to UTF16: {b}..."); - /* Ascii? Simply cast it then... */ - if (b >= 0 && b < 127) + if (b < 127) { mDebugger.SendInternal($"b {b} is ASCII"); return (char)b; @@ -171,8 +167,7 @@ namespace Cosmos.System.ExtendedASCII public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount), - "negative number"); + throw new ArgumentOutOfRangeException(nameof(charCount), "negative number"); // Characters would be # of characters + 1 in case high surrogate is ? * max fallback return charCount + 1; diff --git a/source/Cosmos.System2_Plugs/System/ConsoleImpl.cs b/source/Cosmos.System2_Plugs/System/ConsoleImpl.cs index fa67b36f5..24bb02da2 100644 --- a/source/Cosmos.System2_Plugs/System/ConsoleImpl.cs +++ b/source/Cosmos.System2_Plugs/System/ConsoleImpl.cs @@ -12,6 +12,8 @@ namespace Cosmos.System_Plugs.System { private static ConsoleColor mForeground = ConsoleColor.White; private static ConsoleColor mBackground = ConsoleColor.Black; + private static Encoding ConsoleInputEncoding = Encoding.ASCII; + private static Encoding ConsoleOutputEncoding = Encoding.ASCII; private static readonly Cosmos.System.Console mFallbackConsole = new Cosmos.System.Console(null); @@ -188,13 +190,23 @@ namespace Cosmos.System_Plugs.System public static Encoding get_InputEncoding() { - WriteLine("Not implemented: get_InputEncoding"); - return null; + return ConsoleInputEncoding; } public static void set_InputEncoding(Encoding value) { - WriteLine("Not implemented: set_InputEncoding"); + ConsoleInputEncoding = value; + } + + public static Encoding get_OutputEncoding() + { + return ConsoleOutputEncoding; + } + + + public static void set_OutputEncoding(Encoding value) + { + ConsoleOutputEncoding = value; } public static bool get_KeyAvailable() @@ -224,17 +236,6 @@ namespace Cosmos.System_Plugs.System // return null; //} - public static Encoding get_OutputEncoding() - { - WriteLine("Not implemented: get_OutputEncoding"); - return null; - } - - public static void set_OutputEncoding(Encoding value) - { - WriteLine("Not implemented: set_OutputEncoding"); - } - public static string get_Title() { WriteLine("Not implemented: get_Title"); @@ -568,53 +569,28 @@ namespace Cosmos.System_Plugs.System Write(aBool.ToString()); } - public static void Write(char aChar) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - GetConsole().WriteChar(aChar); - } + /* + * A .Net character can be effectevily more can one byte so calling the low level Console.Write() will be wrong as + * it accepts only bytes, we need to convert it using the specified OutputEncoding but to do this we have to convert + * it ToString first + */ + public static void Write(char aChar) => Write(aChar.ToString()); - public static void Write(char[] aBuffer) - { - Write(aBuffer, 0, aBuffer.Length); - } + public static void Write(char[] aBuffer) => Write(aBuffer, 0, aBuffer.Length); - //public static void Write(decimal aBuffer) { - // Write("No Decimal.ToString()"); - //} + /* Decimal type is not working yet... */ + //public static void Write(decimal aDecimal) => Write(aDecimal.ToString()); - public static void Write(double aDouble) - { - Write(aDouble.ToString()); - } + public static void Write(double aDouble) => Write(aDouble.ToString()); - public static void Write(float aFloat) - { - Write(aFloat.ToString()); - } + public static void Write(float aFloat) => Write(aFloat.ToString()); - public static void Write(int aInt) - { - Write(aInt.ToString()); - } + public static void Write(int aInt) => Write(aInt.ToString()); - public static void Write(long aLong) - { - Write(aLong.ToString()); - } + public static void Write(long aLong) => Write(aLong.ToString()); - public static void Write(object value) - { - if (value != null) - { - Write(value.ToString()); - } - } + /* Correct behaviour printing null should not throw NRE or do nothing but should print an empty string */ + public static void Write(object value) => Write((value ?? String.Empty)); public static void Write(string aText) { @@ -624,28 +600,24 @@ namespace Cosmos.System_Plugs.System // for now: return; } - GetConsole().Write(aText); + + byte[] aTextEncoded = ConsoleOutputEncoding.GetBytes(aText); + GetConsole().Write(aTextEncoded); } - public static void Write(uint aInt) - { - Write(aInt.ToString()); - } + public static void Write(uint aInt) => Write(aInt.ToString()); - public static void Write(ulong aLong) - { - Write(aLong.ToString()); - } + public static void Write(ulong aLong) => Write(aLong.ToString()); - public static void Write(string format, object arg0) - { - WriteLine("Not implemented: Write"); - } + public static void Write(string format, object arg0) => Write(String.Format(format, arg0)); - public static void Write(string format, params object[] arg) - { - WriteLine("Not implemented: Write"); - } + public static void Write(string format, object arg0, object arg1) => Write(String.Format(format, arg0, arg1)); + + public static void Write(string format, object arg0, object arg1, object arg2) => Write(String.Format(format, arg0, arg1, arg2)); + + public static void Write(string format, object arg0, object arg1, object arg2, object arg3) => Write(String.Format(format, arg0, arg1, arg2, arg3)); + + public static void Write(string format, params object[] arg) => Write(String.Format(format, arg)); public static void Write(char[] aBuffer, int aIndex, int aCount) { @@ -671,188 +643,60 @@ namespace Cosmos.System_Plugs.System } } - public static void Write(string format, object arg0, object arg1) - { - WriteLine("Not implemented: Write"); - } - - public static void Write(string format, object arg0, object arg1, object arg2) - { - WriteLine("Not implemented: Write"); - } - - public static void Write(string format, object arg0, object arg1, object arg2, object arg3) - { - WriteLine("Not implemented: Write"); - } - //You'd expect this to be on System.Console wouldn't you? Well, it ain't so we just rely on Write(object value) //public static void Write(byte aByte) { // Write(aByte.ToString()); //} - #endregion +#endregion - #region WriteLine +#region WriteLine - public static void WriteLine() - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - GetConsole().NewLine(); - } + public static void WriteLine() => Write(Environment.NewLine); - public static void WriteLine(bool aBool) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(aBool.ToString()); - GetConsole().NewLine(); - } + public static void WriteLine(bool aBool) => WriteLine(aBool.ToString()); - public static void WriteLine(char aChar) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(aChar); - GetConsole().NewLine(); - } + public static void WriteLine(char aChar) => WriteLine(aChar.ToString()); - public static void WriteLine(char[] aBuffer) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(aBuffer, 0, aBuffer.Length); - GetConsole().NewLine(); - } + public static void WriteLine(char[] aBuffer) => WriteLine(new String(aBuffer)); - //public static void WriteLine(decimal aDecimal) { - // Write(aDecimal); - // Global.Console.NewLine(); - //} + /* Decimal type is not working yet... */ + //public static void WriteLine(decimal aDecimal) => WriteLine(aDecimal.ToString()); - public static void WriteLine(double aDouble) - { - Write(aDouble.ToString()); - GetConsole().NewLine(); - } + public static void WriteLine(double aDouble) => WriteLine(aDouble.ToString()); - public static void WriteLine(float aFloat) - { - Write(aFloat.ToString()); - GetConsole().NewLine(); - } + public static void WriteLine(float aFloat) => WriteLine(aFloat.ToString()); - public static void WriteLine(int aInt) - { - Write(aInt.ToString()); - GetConsole().NewLine(); - } + public static void WriteLine(int aInt) => WriteLine(aInt.ToString()); - public static void WriteLine(long aLong) - { - Write(aLong.ToString()); - GetConsole().NewLine(); - } + public static void WriteLine(long aLong) => WriteLine(aLong.ToString()); - public static void WriteLine(object value) - { - if (value != null) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(value.ToString()); - xConsole.NewLine(); - } - } + /* Correct behaviour printing null should not throw NRE or do nothing but should print an empty line */ + public static void WriteLine(object value) => Write((value ?? String.Empty) + Environment.NewLine); - public static void WriteLine(string aText) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - xConsole.Write(aText); - xConsole.NewLine(); - } + public static void WriteLine(string aText) => Write(aText + Environment.NewLine); - public static void WriteLine(uint aInt) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(aInt.ToString()); - xConsole.NewLine(); - } + public static void WriteLine(uint aInt) => WriteLine(aInt.ToString()); - public static void WriteLine(ulong aLong) - { - var xConsole = GetConsole(); - if (xConsole == null) - { - // for now: - return; - } - Write(aLong.ToString()); - xConsole.NewLine(); - } + public static void WriteLine(ulong aLong) => WriteLine(aLong.ToString()); - public static void WriteLine(string format, object arg0) - { - WriteLine("Not implemented: WriteLine"); - } + public static void WriteLine(string format, object arg0) => WriteLine(String.Format(format, arg0)); - public static void WriteLine(string format, params object[] arg) - { - WriteLine("Not implemented: WriteLine"); - } + public static void WriteLine(string format, object arg0, object arg1) => WriteLine(String.Format(format, arg0, arg1)); + + public static void WriteLine(string format, object arg0, object arg1, object arg2) => WriteLine(String.Format(format, arg0, arg1, arg2)); + + public static void WriteLine(string format, object arg0, object arg1, object arg2, object arg3) => WriteLine(String.Format(format, arg0, arg1, arg2, arg3)); + + public static void WriteLine(string format, params object[] arg) => WriteLine(String.Format(format, arg)); public static void WriteLine(char[] aBuffer, int aIndex, int aCount) { Write(aBuffer, aIndex, aCount); - GetConsole().NewLine(); + WriteLine(); } - public static void WriteLine(string format, object arg0, object arg1) - { - WriteLine("Not implemented: WriteLine"); - } +#endregion - public static void WriteLine(string format, object arg0, object arg1, object arg2) - { - WriteLine("Not implemented: WriteLine"); - } - - public static void WriteLine(string format, object arg0, object arg1, object arg2, object arg3) - { - WriteLine("Not implemented: WriteLine"); - } - - #endregion } } diff --git a/source/Cosmos.System2_Plugs/System/Text/EncodingImpl.cs b/source/Cosmos.System2_Plugs/System/Text/EncodingImpl.cs index e6a35dba5..3ba1deb99 100644 --- a/source/Cosmos.System2_Plugs/System/Text/EncodingImpl.cs +++ b/source/Cosmos.System2_Plugs/System/Text/EncodingImpl.cs @@ -1,10 +1,10 @@ -#define COSMOSDEBUG +//#define COSMOSDEBUG using System.Text; using Cosmos.Debug.Kernel; using Cosmos.System2_Plugs.System.Text; using IL2CPU.API.Attribs; - +/* This plug is needed only because Cosmos does not support Hashtable :-( */ namespace Cosmos.System2_Plugs.System.Text { [Plug(Target = typeof(global::System.Text.Encoding))] diff --git a/source/Cosmos.System2_Plugs/System/ValueTypeImpl.cs b/source/Cosmos.System2_Plugs/System/ValueTypeImpl.cs index d1d327413..37a64765b 100644 --- a/source/Cosmos.System2_Plugs/System/ValueTypeImpl.cs +++ b/source/Cosmos.System2_Plugs/System/ValueTypeImpl.cs @@ -24,24 +24,6 @@ namespace Cosmos.System_Plugs.System throw new NotImplementedException("ValueType.GetHashCodeOfPtr()"); } - public static bool CanCompareBits(object obj) - { - return true; - } - - public static bool FastEqualsCheck(object a, object b) - { - long aAsLong = (long) a; - long bAsLong = (long) b; - - return (a == b); - } - - public static bool Equals(ValueType aThis, object obj) - { - throw new NotImplementedException("ValueType.Equals()"); - } - //public static string ToString(ValueType aThis) //{ // return "";