[Mono-bugs] [Bug 33079][Wis] New - MemoryStream Position Incorrect After write

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
30 Oct 2002 23:42:26 -0000


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by danmorg@sc.rr.com.

http://bugzilla.ximian.com/show_bug.cgi?id=33079

--- shadow/33079	Wed Oct 30 18:42:26 2002
+++ shadow/33079.tmp.14452	Wed Oct 30 18:42:26 2002
@@ -0,0 +1,100 @@
+Bug#: 33079
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: danmorg@sc.rr.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: MemoryStream Position Incorrect After write
+
+MemorySteam property Position is incorrect after some writes.
+
+Test case returns this on .NET built using .NET/csc:
+memory.Postion memory position:16
+
+Test case returns this on Mono built using mono/mcs:
+memory.Postion memory position:22
+
+//
+// Mem.cs - tests MemoryStream property Postion being wrong
+//           
+
+using System;
+using System.IO;
+
+namespace Mem
+{
+	public class MemTest {
+		public BinaryWriter _writeStream;
+
+		protected byte		_packetSequence;
+		protected byte		m_LastResult;
+
+		public MemTest() {
+			_packetSequence = 0xff;
+			m_LastResult = 0xff;
+			_writeStream = new BinaryWriter(new MemoryStream
+());
+			_writeStream.Write((int)0);
+		}
+
+		public void DoTest() {
+
+			ClientParam clientParam = 0;
+			clientParam |= ClientParam.CLIENT_FOUND_ROWS;
+			clientParam |= ClientParam.CLIENT_LONG_PASSWORD;
+			_writeStream.Write((short)clientParam);
+
+			string userid = "mysql";
+			string password = "";
+			int headerLength = (userid.Length + 16) + 6 + 4;
+			_writeStream.Write((byte)(headerLength & 0xff));
+			_writeStream.Write((byte)(headerLength >> 8));
+			_writeStream.Write((byte)(headerLength >> 16));
+
+			Write( userid );
+			Write( password );
+
+			MemoryStream memory = ((MemoryStream)
+_writeStream.BaseStream);
+			Console.WriteLine("memory.Postion memory 
+position:" + (memory.Position).ToString());
+		}
+
+		void Write(string v) {
+			_writeStream.Write(v.ToCharArray());
+			_writeStream.Write((byte)0);
+		}
+	}
+
+	internal enum ClientParam : short {
+		CLIENT_LONG_PASSWORD   = 1,  
+		CLIENT_FOUND_ROWS      = 2, 
+		CLIENT_LONG_FLAG	      = 4,  
+		CLIENT_CONNECT_WITH_DB = 8,  	
+		CLIENT_NO_SCHEMA       = 16, 
+		CLIENT_COMPRESS        = 32, 
+		CLIENT_ODBC            = 64, 
+		CLIENT_LOCAL_FILES     = 128,
+		CLIENT_IGNORE_SPACE    = 256, 
+	}
+
+	class MemoryStreamTest
+	{
+		[STAThread]
+		static void Main(string[] args)
+		{
+			MemTest mt = new MemTest();
+			mt.DoTest();
+		}
+	}
+}