[Mono-list] "Implement me" Exception

Martin Baulig martin@gnome.org
19 Jul 2002 01:14:03 +0200


--=-=-=

Hi Eduardo,

your test case contains a few syntax errors:

1.) You defined SetUp() twice (I guess you wanted to call one of them ShutDown).

2.) In TestCtor2, you tried to pass a class `Encoding' as an argument
    to the constructor.  MCS will now correctly report a syntax error
    when you attempt to do this rather than crashing.

    The correct way to do it is

	BinaryReader r = new BinaryReader((Stream)null,Encoding.Unicode);

    This'll pass an instance of this class (ie. an object) to the
    constructor, not the class itself.

3.) I don't know what you wanted to do with

	byte[] b = new byte[30];
	BinaryReader r = new BinaryReader(m,(Encoding)b[2]);

    You cannot convert a single byte into an object.  Changing this to

	BinaryReader r = new BinaryReader(m,(Encoding)null);

    like you did a few lines earlier should do it.

4.) I think you must link against NUnitCore_mono.dll, not
    NUnitCore.dll, but not sure.

Here's your corrected test case:


--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BinaryReaderTest.cs

// BinaryReaderTest.cs - NUnit Test Cases for the SystemIO.BinaryReader class
//
// Eduardo Garcia Cebollero (kiwnix@yahoo.es)
//
// (C) Eduardo Garcia Cebollero.
// (C) Ximian, Inc.  http://www.ximian.com
// 

using NUnit.Framework;
using System;
using System.IO;
using System.Text;

namespace MonoTests.System.IO
{
	
	public class BinaryReaderTest : TestCase
	{
		public BinaryReaderTest() : 
			base ("MonoTests.System.IO.BinaryReaderTest testsuite") {}
		public BinaryReaderTest(string name) : base(name) {}
			
		protected override void SetUp() 
		{
		}
		
		public static ITest Suite {
		get { 
			return new TestSuite(typeof(BinaryReaderTest)); 
		}
		}
		
		private string _codeFileName = "resources" + Path.DirectorySeparatorChar + "AFile.txt";
			
		public void TestCtor1() 
		{
			{
				bool errorThrown = false;
				try {
					BinaryReader r = new BinaryReader((Stream)null);
				} catch (ArgumentNullException) {
					errorThrown = true;
				}
				Assert("#01 null string error not thrown", errorThrown);
			}
			{
				bool errorThrown = false;
				FileStream f = new FileStream(_codeFileName, FileMode.Open, FileAccess.Write);
				try {
					BinaryReader r = new BinaryReader(f);
					r.Close();
				} catch (ArgumentException) {
					errorThrown = true;
				}
				f.Close();
				Assert("#02 no read error not thrown", errorThrown);
			}
			{
				FileStream f = new FileStream(_codeFileName, 
								FileMode.Open, 
								FileAccess.Read);
				BinaryReader r = new BinaryReader(f);
				AssertNotNull("#03 no binary reader created", r);
				r.Close();
				f.Close();
			}
				
		}
		public void TestCtor2() 
		{
			{
				bool errorThrown = false;
				try {
					BinaryReader r = new BinaryReader((Stream)null,Encoding.ASCII);
				} catch (ArgumentNullException) {
					errorThrown = true;
				} catch (Exception e) {
					Fail ("#04 Incorrect exception thrown: " + e.ToString());
				}
				Assert("#05 null stream error not thrown", errorThrown);
			}
			{
				bool errorThrown = false;
				try {
					BinaryReader r = new BinaryReader((Stream)null,Encoding.Unicode);
				} catch (ArgumentNullException) {
					errorThrown = true;
				} catch (Exception e) {
					Fail ("#06 Incorrect exception thrown: " + e.ToString());
				}
				Assert("#07 null stream error not thrown", errorThrown);
			}
			{
				bool errorThrown = false;
				try {
					BinaryReader r = new BinaryReader((Stream)null,Encoding.UTF7);
				} catch (ArgumentNullException) {
					errorThrown = true;
				} catch (Exception e) {
					Fail ("#08 Incorrect exception thrown: " + e.ToString());
				}
				Assert("#09 null stream error not thrown", errorThrown);
			}
			{
				bool errorThrown = false;
				try {
					BinaryReader r = new BinaryReader((Stream)null,Encoding.UTF8);
				} catch (ArgumentNullException) {
					errorThrown = true;
				} catch (Exception e) {
					Fail ("#0A Incorrect exception thrown: " + e.ToString());
				}
				Assert("#0B null stream error not thrown", errorThrown);
			}
		}
		public void TestCtor3()
		{
			{
				bool errorThrown = false;
				byte[] b = new byte[30];
				MemoryStream m = new MemoryStream(b);
				try {
					BinaryReader r = new BinaryReader(m,(Encoding)null);
				}
				catch(ArgumentNullException) {
					errorThrown = true;
				} 
				catch(Exception e) {
					Fail("#0C Incorrect Exception thrown: " + e.ToString());
				}
				Assert("#0D No exception trown: ", errorThrown);
			}
			{
				bool errorThrown = false;
				byte[] b = new byte[30];
				MemoryStream m = new MemoryStream(b);
				try {
					BinaryReader r = new BinaryReader(m,(Encoding)null);
				}
				catch(ArgumentException) {
					errorThrown = true;
				}
				catch(Exception e) {
					Fail("#0E Incorrect Exception thrown: " + e.ToString());
				}
				Assert("#0F No exception trown: ", errorThrown);
			}
		}
		//TODO: (TestCtor*) Verify the Use of a wrong Stream
		/*public void TestCorrectEncoding1()
		{
			{
				try {
					Byte[] b = {};
					MemoryStream m = new MemoryStream(b);
					BinaryReader r = new BinaryReader(m,UTF7Encoding);
					AssertEquals("wrong encoding", Encoding.UTF8, r.CurrentEncoding);
				} catch (Exception e) {
					Fail ("#10 Unexpected exception thrown: " + e.ToString());
				}
			}
		}*/
		//TODO: (TestClose*) Verify the Close Method
		//TODO: (TestRead*) Verify Read Method
		public void TestReadBoolean()
		{
			{
				try
				{
					bool[] a = {true,true,false};
					byte[] arr_a = new byte[3];
					int i = 0;
					foreach(bool a1 in a)
					{
							  arr_a[i] = Convert.ToByte(a1);
							  i++;
					}
							  
					bool b;
					MemoryStream m = new MemoryStream(arr_a);
					BinaryReader r = new BinaryReader(m);
					b = r.ReadBoolean();
					AssertEquals("#11 No well readed boolean",a[0],b);
				} catch (Exception e) {
					Fail ("#12 Unexpected exception thrown: " + e.ToString());
				}
			}
		}
					
		
		//-TODO: (TestRead[Type]*) Verify the ReadBoolean, ReadByte ....
		// ReadBoolean Done
		
		//TODO: (TestDispose*) Verify the Dispose Method
		//TODO: (TestFillBuffer*) Verify the FillBuffer Method
		public void TestPeekChar()
		{
			{
				try 
				{
					char char1,char2;
					char[] b = {'A','B','C'};
					byte[] arr_b = new byte[3];
					int i = 0;
					foreach (char b1 in b)
					{
							  arr_b[i] = Convert.ToByte(b1);
							  i++;
					}
					  
					MemoryStream m = new MemoryStream(arr_b);
					BinaryReader r = new BinaryReader(m);
					char1 = (char)r.PeekChar();
					char2 = (char)r.PeekChar();
					AssertEquals("#13 the stream pointer have been altered in peek", char1,char2);
				} catch (Exception e) {
					Fail ("#14 Unexpected exception thrown: " + e.ToString());
				}
			}
		//-TODO: (TestPeekChar*) Verify the PeekChar Method
		}
	}
}



--=-=-=


Btw. you should update your runtime, class libraries and mcs first - I
committed some larger changes to it today.

Martin

Eduardo Garcia Cebollero <kiwnix@yahoo.es> writes:

> I'm doing the System.IO.BinaryReader NUnit test, when i try to compile
> it, i get the following error from mcs:
> 
> $ mcs BinaryReaderTest.cs -r /usr/lib/NUnitCore.dll -target:library 
> 
> ** (process:11847): WARNING **: unhandled exception System.Exception:
> "Implement me"
> in <0x0007c> (runtime invoke wrapper) Mono.CSharp.Driver:Main
> (object,intptr,intptr)
> 
> It occours while compiling the atachment, It's my first NUnit test, i
> don't know if it's my fail or not.
> 
> I tryed to isolate the error and it only appear if the TestCtor2()
> method is present, i think the error occour while trying to compile the 
> try{....}catch(...){....} when a null reference is passed by parameter
> to BinaryReader constructor with encoding.
> 
> I wish the information is usefull.
> 
> and I would like to have advice or tips about the test :)
> 
> Thanks for the time and excuseme for my poor english.
> 
> -- 
> Eduardo Garcia Cebollero <kiwnix@yahoo.es>
> 

-- 
Martin Baulig
martin@gnome.org

--=-=-=--