示例#1
0
		public void BinDumpBinaryStreams_TestUIntWrites()
		{
			uint[] values = new uint[] { 0, 1, 0x7F, 10, 0x7E, 32767, 32768, uint.MinValue, uint.MaxValue };

			using (MemoryStream ms_orig = new MemoryStream())
			{
				UndisposableStream ms = new UndisposableStream(ms_orig);

				using (BinDumpBinaryWriter bdbw = new BinDumpBinaryWriter(ms, Encoding.UTF8))
				{
					for (int i = 0; i < values.Length; i++)
					{
						bdbw.Write(values[i]);
					}
				}

				ms.Seek(0, SeekOrigin.Begin);

				using (BinDumpBinaryReader bdbr = new BinDumpBinaryReader(ms, Encoding.UTF8))
				{
					for (int i = 0; i < values.Length; i++)
					{
						uint v = bdbr.ReadUInt32();
						Assert.AreEqual(values[i], v, "i = " + i.ToString());
					}
				}
			}
		}
示例#2
0
		public void BinDumpBinaryStreams_TestStringWrites()
		{
			string[] values = new string[] { "hello", "you", "fool", "hello", "I", "love", "you" };

			using (MemoryStream ms_orig = new MemoryStream())
			{
				UndisposableStream ms = new UndisposableStream(ms_orig);

				using (BinDumpBinaryWriter bdbw = new BinDumpBinaryWriter(ms, Encoding.UTF8))
				{
					for (int i = 0; i < values.Length; i++)
					{
						bdbw.Write(values[i]);
					}
				}

				ms.Seek(0, SeekOrigin.Begin);

				using (BinDumpBinaryReader bdbr = new BinDumpBinaryReader(ms, Encoding.UTF8))
				{
					for (int i = 0; i < values.Length; i++)
					{
						string v = bdbr.ReadString();
						Assert.AreEqual(values[i], v, "i = " + i.ToString());
					}
				}
			}
		}