mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 13:28:41 +00:00
Trying to plug StreamWriter(), but Flush() has only a buffer filled all with 0x0000 not with the text to Write()!
This commit is contained in:
parent
f83aef39b0
commit
4071e75a47
11 changed files with 201 additions and 12 deletions
2
Test.sln
2
Test.sln
|
|
@ -1,6 +1,6 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
VisualStudioVersion = 15.0.26730.3
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DAEF99B5-22F0-4885-B45B-9B600B857E1C}"
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -35,17 +35,21 @@ namespace Cosmos.Kernel.Tests.Fat
|
|||
{
|
||||
mDebugger.Send("Run");
|
||||
|
||||
#if false
|
||||
PathTest.Execute(mDebugger);
|
||||
DirectoryTest.Execute(mDebugger);
|
||||
FileTest.Execute(mDebugger);
|
||||
#endif
|
||||
//FileTest.Execute(mDebugger);
|
||||
#if false
|
||||
FileStreamTest.Execute(mDebugger);
|
||||
DirectoryInfoTest.Execute(mDebugger);
|
||||
|
||||
//StreamWriterTest.Execute(mDebugger);
|
||||
#endif
|
||||
StreamWriterTest.Execute(mDebugger);
|
||||
//StreamReaderTest.Execute(mDebugger);
|
||||
//BinaryWriterTest.Execute(mDebugger);
|
||||
//BinaryReaderTest.Execute(mDebugger);
|
||||
|
||||
|
||||
TestController.Completed();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.IO;
|
||||
using Cosmos.TestRunner;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using System;
|
||||
|
||||
namespace Cosmos.Kernel.Tests.Fat.System.IO
|
||||
{
|
||||
|
|
@ -16,23 +17,26 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
|
|||
|
||||
using (var xSW = new StreamWriter(@"0:\test.txt"))
|
||||
{
|
||||
|
||||
if (xSW != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
mDebugger.Send("Start writing");
|
||||
|
||||
xSW.Write("A line of text for testing\nSecond line");
|
||||
xSW.Write("0123");
|
||||
//xSW.Write("A line of text for testing\nSecond line");
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.IsTrue(false, @"Couldn't write to file 0:\test.txt using StreamWriter");
|
||||
Assert.IsTrue(false, $"Couldn't write to file 0:\test.txt using StreamWriter {e.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(false, @"Failed to create StreamWriter for file 0:\test.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mDebugger.Send("END TEST");
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ namespace Cosmos.TestRunner.Core
|
|||
engine.DebugIL2CPU = false;
|
||||
engine.TraceAssembliesLevel = TraceAssemblies.User;
|
||||
//engine.EnableStackCorruptionChecks = false;
|
||||
engine.KernelPkg = "X86";
|
||||
//engine.KernelPkg = "X86G3";
|
||||
|
||||
engine.EnableStackCorruptionChecks = true;
|
||||
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
|
||||
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.MethodFooters;
|
||||
//engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.MethodFooters;
|
||||
|
||||
//engine.RunWithGDB = true;
|
||||
//engine.StartBochsDebugGui = true;
|
||||
|
|
|
|||
|
|
@ -8,25 +8,32 @@ namespace Cosmos.TestRunner.Core
|
|||
// Kernel types to run: the ones that will run in test runners that use the default engine configuration.
|
||||
public static IEnumerable<Type> GetKernelTypesToRun()
|
||||
{
|
||||
yield return typeof(KernelGen3.Boot);
|
||||
//return GetStableKernelTypes();
|
||||
//yield return typeof(KernelGen3.Boot);
|
||||
return GetStableKernelTypes();
|
||||
}
|
||||
|
||||
// Stable kernel types: the ones that are stable and will run in AppVeyor
|
||||
public static IEnumerable<Type> GetStableKernelTypes()
|
||||
{
|
||||
|
||||
//yield return typeof(BoxingTests.Kernel);
|
||||
#if false
|
||||
yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
|
||||
|
||||
//yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel);
|
||||
yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
|
||||
#endif
|
||||
/* Let's test only this for now */
|
||||
yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
|
||||
yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);
|
||||
//yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);
|
||||
#if false
|
||||
yield return typeof(SimpleStructsAndArraysTest.Kernel);
|
||||
yield return typeof(VGACompilerCrash.Kernel);
|
||||
#endif
|
||||
|
||||
//yield return typeof(FrotzKernel.Kernel);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,4 +22,8 @@
|
|||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="System\Threading\TaskImpl.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -11,5 +11,10 @@ namespace Cosmos.Core_Plugs.System.Text
|
|||
{
|
||||
return new object();
|
||||
}
|
||||
|
||||
public static EncoderFallbackBuffer CreateFallbackBuffer(EncoderFallback aThis)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
using Cosmos.IL2CPU.API.Attribs;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Core_Plugs.System.Text
|
||||
{
|
||||
[Plug(TargetName = "System.Text.InternalEncoderBestFitFallback")]
|
||||
public static class InternalEncoderBestFitFallbackImpl
|
||||
{
|
||||
public static EncoderFallbackBuffer CreateFallbackBuffer(object aThis)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
source/Cosmos.System2/Encoding/CosmosEncoding.cs
Normal file
13
source/Cosmos.System2/Encoding/CosmosEncoding.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.System2.Encoding
|
||||
{
|
||||
public abstract class CosmosEncoding
|
||||
{
|
||||
public abstract Byte[] GetBytes(String s);
|
||||
public abstract String GetString(Byte[] bytes);
|
||||
public abstract int GetMaxByteCount(int ByteCount);
|
||||
}
|
||||
}
|
||||
39
source/Cosmos.System2/Encoding/CosmosUTF8Encoding.cs
Normal file
39
source/Cosmos.System2/Encoding/CosmosUTF8Encoding.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#define COSMOSDEBUG
|
||||
using Cosmos.System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.System2.Encoding
|
||||
{
|
||||
public class CosmosUTF8Encoding : CosmosEncoding
|
||||
{
|
||||
public override byte[] GetBytes(string s)
|
||||
{
|
||||
Global.mFileSystemDebugger.SendInternal($"Encoding string {s}");
|
||||
|
||||
//byte[] xResult = new byte[GetMaxByteCount(s.Length)];
|
||||
List <byte> xResult = new List<byte>();
|
||||
/* Only Ascii for now */
|
||||
foreach (var aChar in s)
|
||||
{
|
||||
Global.mFileSystemDebugger.SendInternal($"Encoding char {aChar}");
|
||||
if (aChar > 0 || aChar < 127)
|
||||
xResult.Add((byte)aChar);
|
||||
else
|
||||
throw new ArgumentOutOfRangeException("Input string contains invalid characters for UTF-8");
|
||||
}
|
||||
|
||||
return xResult.ToArray();
|
||||
//throw new NotImplementedException("GetBytes()");
|
||||
}
|
||||
|
||||
/* Some UFT-8 char can occupy 3 bytes */
|
||||
public override int GetMaxByteCount(int ByteCount) => 3 * ByteCount;
|
||||
|
||||
public override string GetString(byte[] bytes)
|
||||
{
|
||||
throw new NotImplementedException("GetString()");
|
||||
}
|
||||
}
|
||||
}
|
||||
98
source/Cosmos.System2_Plugs/System/IO/StreamWriterImpl.cs
Normal file
98
source/Cosmos.System2_Plugs/System/IO/StreamWriterImpl.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#define COSMOSDEBUG
|
||||
using System;
|
||||
using System.IO;
|
||||
using Cosmos.System;
|
||||
using Cosmos.IL2CPU.API.Attribs;
|
||||
using Cosmos.System2.Encoding;
|
||||
|
||||
namespace Cosmos.System_Plugs.System.IO
|
||||
{
|
||||
|
||||
[Plug(Target = typeof(StreamWriter))]
|
||||
public static class StreamWriterImpl
|
||||
{
|
||||
|
||||
#if false
|
||||
public static void Ctor(StreamWriter aThis, string path)
|
||||
{
|
||||
throw new NotImplementedException("StreamWriter Ctor(String path)");
|
||||
}
|
||||
#endif
|
||||
private static CosmosEncoding FileEncoding;
|
||||
//private static Stream InnerStream;
|
||||
|
||||
#if false
|
||||
private static void Init(Stream stream, CosmosEncoding encoding)
|
||||
{
|
||||
//InnerStream = stream;
|
||||
FileEncoding = encoding;
|
||||
}
|
||||
#endif
|
||||
private static void Init(CosmosEncoding encoding, ref char[] charBuffer, int bufferSize, ref byte[] byteBuffer, bool shouldLeaveOpen)
|
||||
{
|
||||
FileEncoding = encoding;
|
||||
charBuffer = new char[bufferSize];
|
||||
byteBuffer = new byte[bufferSize * FileEncoding.GetMaxByteCount(bufferSize)];
|
||||
}
|
||||
|
||||
public static void Ctor(StreamWriter aThis, string path,
|
||||
[FieldAccess(Name = "System.IO.Stream System.IO.StreamWriter._stream")] ref Stream _stream,
|
||||
[FieldAccess(Name = "System.Int32 System.IO.StreamWriter._charPos")] ref int _charPos,
|
||||
[FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref char[] _charBuffer,
|
||||
[FieldAccess(Name = "System.Byte[] System.IO.StreamWriter._byteBuffer")] ref byte[] _byteBuffer
|
||||
)
|
||||
{
|
||||
Global.mFileSystemDebugger.SendInternal($"StreamWriter.Ctor() with path {path}");
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
if (path.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Empty path");
|
||||
}
|
||||
|
||||
_stream = new FileStream(path, FileMode.Create);
|
||||
Init(new CosmosUTF8Encoding(), ref _charBuffer, 128, ref _byteBuffer, false);
|
||||
}
|
||||
|
||||
public static void Flush(StreamWriter aThis, bool flushStream, bool flushEncoder,
|
||||
[FieldAccess(Name = "System.IO.Stream System.IO.StreamWriter._stream")] ref Stream _stream,
|
||||
[FieldAccess(Name = "System.Int32 System.IO.StreamWriter._charPos")] ref int _charPos,
|
||||
[FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref char[] _charBuffer,
|
||||
[FieldAccess(Name = "System.Byte[] System.IO.StreamWriter._byteBuffer")] ref byte[] _byteBuffer
|
||||
)
|
||||
{
|
||||
Global.mFileSystemDebugger.SendInternal($"_charPos is {_charPos}");
|
||||
// Debug code why is not working?
|
||||
if (_charBuffer == null)
|
||||
Global.mFileSystemDebugger.SendInternal("_charBuffer is NULL!");
|
||||
else if (_charBuffer.Length == 0)
|
||||
Global.mFileSystemDebugger.SendInternal("_charBuffer is Empty!");
|
||||
/* First 4 chars should be '0', '1', '2' and '3' */
|
||||
else
|
||||
{
|
||||
Global.mFileSystemDebugger.SendInternal("Printing first 4 chars of _charBuffer: ");
|
||||
Global.mFileSystemDebugger.SendInternal(_charBuffer[0]);
|
||||
Global.mFileSystemDebugger.SendInternal(_charBuffer[1]);
|
||||
Global.mFileSystemDebugger.SendInternal(_charBuffer[2]);
|
||||
Global.mFileSystemDebugger.SendInternal(_charBuffer[3]);
|
||||
}
|
||||
|
||||
|
||||
#if false
|
||||
Global.mFileSystemDebugger.SendInternal($"StreamWriter.Flush() with _charPos {_charPos} and _charBuffer{new String(_charBuffer)}");
|
||||
|
||||
FileEncoding.GetBytes(new string(_charBuffer));
|
||||
_stream.Write(_byteBuffer, 0, _byteBuffer.Length);
|
||||
_stream.Flush();
|
||||
#endif
|
||||
throw new NotImplementedException("Flush()");
|
||||
}
|
||||
|
||||
public static void Cctor()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue