Skip to content

Commit

Permalink
Merge pull request NETMF#198 from mortezag/fixReadline
Browse files Browse the repository at this point in the history
Fix Peek method in StreamReader
  • Loading branch information
mortezag committed Jun 30, 2015
2 parents 11e6037 + 1bff561 commit d0fc72a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Framework/Core/System/IO/StreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public override int Peek()
int nextChar;

// If buffer need refresh take into account max UTF8 bytes if the next character is UTF8 encoded
if ((m_curBufPos == (m_curBufLen-1)) ||
// Note: In some occasions, m_curBufPos may go beyond m_curBufLen-1 (for example, when trying to peek after reading the last character of the buffer), so we need to refresh the buffer in these cases too
if ((m_curBufPos >= (m_curBufLen-1)) ||
((m_buffer[m_curBufPos + 1] & 0x80) != 0 &&
(m_curBufPos + 3 >= m_curBufLen)))
{
Expand Down
46 changes: 46 additions & 0 deletions Test/Platform/Tests/CLR/System/IO/FileStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,51 @@ public MFTestResults FileStreamTest_FileAccessAndFileShare()

return (pass)? MFTestResults.Pass : MFTestResults.Fail;
}

[TestMethod]
public MFTestResults Test_Fix2048()
{
// This test was created for http://netmf.codeplex.com/workitem/2048
const string file = "foo.txt";
MFTestResults result = MFTestResults.Pass;
try
{
const string content = "\"this is param0 HH:MM:SS-YY-mm-dd\", \"this is param1\", \"this is param2\", \"this is param3\",MAXMOISTURE=4.5,MINLEVEL=10,WATERACTIVE=True";

StreamWriter sw = new StreamWriter(file);

for (int i = 0; i < 616; i++)
{
sw.WriteLine(content);
}

sw.Close();

StreamReader sr = new StreamReader(file);
string str = sr.ReadLine();

if(str != content)
{
result = MFTestResults.Fail;
}

sr.Close();
}
catch (Exception ex)
{
result = MFTestResults.Fail;
Log.Exception("Unexpected Exception", ex);
}
finally
{
try
{
File.Delete(file);
}
catch { }
}

return result;
}
}
}

0 comments on commit d0fc72a

Please sign in to comment.