[Mono-list] Microsoft.VisualBasic.Collection Exception problems
Chris J. Breisch
cjbreisch@altavista.net
Sat, 11 May 2002 11:04:10 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_0008_01C1F8DB.948699E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Would help if I attached the "attached file", wouldn't it?
Chris J. Breisch, MCSD, MCDBA
-----Original Message-----
From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com] On
Behalf Of Chris J. Breisch
Sent: Saturday, May 11, 2002 10:55 AM
To: mono-list@ximian.com
Subject: [Mono-list] Microsoft.VisualBasic.Collection Exception problems
FYI,
Visual Basic Language reference states that for class
Microsoft.VisualBasic.Collection:
ReadOnly Public Default Overloads Property Item( _
ByVal Index As {=A0Integer=A0| Object=A0} _
)=A0As Object
should throw an IndexOutOfRangeException when "Index doesn't match an
existing member of the collection."
It properly does so, if Index is an invalid Integer, but throws
ArgumentException if Index is an invalid Object.
Further, the Collection class implements IENumerable (by way of IList),
and the on-line documentation for the IENumerable interface states:
object Current {get;}
should throw an InvalidOperationException when "The enumerator is
positioned before the first element of the collection or after the last
element."
Instead, the Collection class throws an IndexOutOfRangeException.
Further, the on-line documentation for IENumerable also states:
bool MoveNext();
and
void Reset();
should throw an InvalidOperationException when "The collection was
modified after the enumerator was created."
Instead, no exception is thrown at all.
These are amply demonstrated by the attached file (ripped from my
TestCollection.cs Nunit Test)
Will be adding these to mcs/class/doc/API-notes when I can.
-chris
Chris J. Breisch, MCSD, MCDBA
_______________________________________________
Mono-list maillist - Mono-list@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
------=_NextPart_000_0008_01C1F8DB.948699E0
Content-Type: text/plain;
name="CollectionTesterrs.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="CollectionTesterrs.cs"
// Collection.cs - NUnit Test Cases for Microsoft.VisualBasic.Collection
//
// Author:
// Chris J. Breisch (cjbreisch@altavista.net)
//
// (C) Chris J. Breisch
//=20
using NUnit.Framework;
using System;
using Microsoft.VisualBasic;
using System.Collections;
namespace MonoTests.Microsoft.VisualBasic
{
public class CollectionTest : TestCase=20
{
=09
public CollectionTest() : base ("Microsoft.VisualBasic.Collection") {}
public CollectionTest(string name) : base(name) {}
protected override void SetUp() {}
protected override void TearDown() {}
public static ITest Suite=20
{
get=20
{=20
return new TestSuite(typeof(CollectionTest));=20
}
}
// Test all the Exceptions we're supposed to throw
public void TestException ()
{
Collection c;
bool CaughtException;
c =3D new Collection();
c.Add("Baseball", "Base", null, null);
c.Add("Football", "Foot", null, null);
c.Add("Basketball", "Basket", null, null);
c.Add("Volleyball", "Volley", null, null);
CaughtException =3D false;
=09
try=20
{
// no member with Key =3D=3D "Kick"
object o =3D c["Kick"];
}
catch (Exception e)
{
// VB Language Reference says IndexOutOfRangeException here, but MS =
throws ArgumentException
// AssertEquals("#E07", typeof(IndexOutOfRangeException), =
e.GetType());
AssertEquals("#E07", typeof(ArgumentException), e.GetType());
CaughtException =3D true;
}
AssertEquals("#E08", true, CaughtException);
=20
CaughtException =3D false;
=09
try=20
{
IEnumerator e =3D c.GetEnumerator();
=09
// Must MoveNext before Current
object item =3D e.Current;
}
catch (Exception e)
{
// On-line help says InvalidOperationException here, but MS throws =
IndexOutOfRangeException
// AssertEquals("#E25", typeof(InvalidOperationException), =
e.GetType());
AssertEquals("#E25", typeof(IndexOutOfRangeException), e.GetType());
CaughtException =3D true;
}
AssertEquals("#E26", true, CaughtException);
=20
CaughtException =3D false;
=09
try=20
{
IEnumerator e =3D c.GetEnumerator();
e.MoveNext();
c.Add("Paintball", "Paint", null, null);
// Can't MoveNext if Collection has been modified
e.MoveNext();
}
catch (Exception e)
{
// On-line help says this should throw an error. MS doesn't.
AssertEquals("#E27", typeof(InvalidOperationException), =
e.GetType());
CaughtException =3D true;
}
// What to do about this? MS doesn't throw an error
// AssertEquals("#E28", true, CaughtException);
AssertEquals("#E28", false, CaughtException);
=20
CaughtException =3D false;
=09
try=20
{
IEnumerator e =3D c.GetEnumerator();
e.MoveNext();
c.Add("Racketball", "Racket", null, null);
// Can't Reset if Collection has been modified
e.Reset();
}
catch (Exception e)
{
// On-line help says this should throw an error. MS doesn't.
AssertEquals("#E29", typeof(InvalidOperationException), =
e.GetType());
CaughtException =3D true;
}
// What to do about this? MS doesn't throw an error
// AssertEquals("#E30", true, CaughtException);
AssertEquals("#E30", false, CaughtException);
CaughtException =3D false;
}
}
}
------=_NextPart_000_0008_01C1F8DB.948699E0--