Browse files

* ConsoleTest.cs: Modernize to use attributes and Assert class.

svn path=/trunk/mcs/; revision=54723
  • Loading branch information...
1 parent d7aad45 commit 4eb53a487774fd2bb41b3d2b0760a75d320b12b4 @harinath harinath committed Dec 22, 2005
Showing with 85 additions and 51 deletions.
  1. +4 −0 mcs/class/corlib/Test/System/ChangeLog
  2. +81 −51 mcs/class/corlib/Test/System/ConsoleTest.cs
View
4 mcs/class/corlib/Test/System/ChangeLog
@@ -1,3 +1,7 @@
+2005-12-22 Raja R Harinath <rharinath@novell.com>
+
+ * ConsoleTest.cs: Modernize to use attributes and Assert class.
+
2005-12-20 Sebastien Pouliot <sebastien@ximian.com>
* DecimalTest.cs: Fixed test cases to run (without failures) on 2.0.
View
132 mcs/class/corlib/Test/System/ConsoleTest.cs
@@ -12,48 +12,59 @@
namespace MonoTests.System
{
-
-public class ConsoleTest : TestCase
+[TestFixture]
+public class ConsoleTest
{
public ConsoleTest() {}
TextWriter _err;
TextReader _in;
TextWriter _out;
- protected override void SetUp()
+
+ [SetUp]
+ public void SetUp()
{
_err = Console.Error;
_in = Console.In;
_out = Console.Out;
}
- protected override void TearDown()
+ [TearDown]
+ public void TearDown()
{
Console.SetError(_err);
Console.SetIn(_in);
Console.SetOut(_out);
}
- public void TestError() {
- AssertNotNull("No error", Console.Error);
+ [Test]
+ public void TestError()
+ {
+ Assert.IsNotNull (Console.Error, "No error");
}
- public void TestIn() {
- AssertNotNull("No in", Console.In);
+ [Test]
+ public void TestIn()
+ {
+ Assert.IsNotNull (Console.In, "No in");
}
- public void TestOut() {
- AssertNotNull("No out", Console.Out);
+ [Test]
+ public void TestOut()
+ {
+ Assert.IsNotNull (Console.Out, "No out");
}
- public void TestOpenStandardError() {
+ [Test]
+ public void TestOpenStandardError()
+ {
{
- Stream err = Console.OpenStandardError();
- AssertNotNull("Can't open error", err);
+ Stream err = Console.OpenStandardError ();
+ Assert.IsNotNull (err, "Can't open error #1");
}
{
- Stream err = Console.OpenStandardError(512);
- AssertNotNull("Can't open error", err);
+ Stream err = Console.OpenStandardError (512);
+ Assert.IsNotNull (err, "Can't open error #2");
}
// Spec says these are here, MS implementation says no.
//{
@@ -77,31 +88,37 @@ protected override void TearDown()
//}
}
- public void TestOpenStandardInput() {
+ [Test]
+ public void TestOpenStandardInput()
+ {
{
- Stream in1 = Console.OpenStandardInput();
- AssertNotNull("Can't open input", in1);
+ Stream in1 = Console.OpenStandardInput ();
+ Assert.IsNotNull (in1, "Can't open input #1");
}
{
- Stream in1 = Console.OpenStandardInput(512);
- AssertNotNull("Can't open input", in1);
+ Stream in1 = Console.OpenStandardInput (512);
+ Assert.IsNotNull (in1, "Can't open input #2");
}
// see commented-out tests in TestOpenStandardError
}
-
- public void TestOpenStandardOutput() {
+
+ [Test]
+ public void TestOpenStandardOutput()
+ {
{
- Stream out1 = Console.OpenStandardOutput();
- AssertNotNull("Can't open output", out1);
+ Stream out1 = Console.OpenStandardOutput ();
+ Assert.IsNotNull(out1, "Can't open output #1");
}
{
Stream out1 = Console.OpenStandardOutput(512);
- AssertNotNull("Can't open output", out1);
+ Assert.IsNotNull (out1, "Can't open output #2");
}
// see commented-out tests in TestOpenStandardError
}
-
- public void TestRead() {
+
+ [Test]
+ public void TestRead()
+ {
String testStr = "This is a readline test";
Stream s = new MemoryStream();
TextWriter w = new StreamWriter(s);
@@ -111,10 +128,12 @@ protected override void TearDown()
w.WriteLine(testStr);
s.Position = 0;
char val = (char) Console.Read();
- AssertEquals("Wrong read", 'T', val);
+ Assert.AreEqual ('T', val, "Wrong read");
}
- public void TestReadLine() {
+ [Test]
+ public void TestReadLine()
+ {
String testStr = "This is a readline test";
Stream s = new MemoryStream();
TextWriter w = new StreamWriter(s);
@@ -124,18 +143,20 @@ protected override void TearDown()
w.WriteLine(testStr);
s.Position = 0;
String line = Console.ReadLine();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
}
- public void TestSetError() {
+ [Test]
+ public void TestSetError()
+ {
{
bool errorThrown = false;
try {
Console.SetError(null);
} catch (ArgumentNullException) {
errorThrown = true;
}
- Assert("null error error not thrown", errorThrown);
+ Assert.IsTrue (errorThrown, "null error error not thrown");
}
{
String testStr = "This is a stderr test";
@@ -147,19 +168,21 @@ protected override void TearDown()
Console.Error.WriteLine(testStr);
s.Position = 0;
String line = r.ReadLine();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
}
}
- public void TestSetIn() {
+ [Test]
+ public void TestSetIn()
+ {
{
bool errorThrown = false;
try {
Console.SetIn(null);
} catch (ArgumentNullException) {
errorThrown = true;
}
- Assert("null in error not thrown", errorThrown);
+ Assert.IsTrue (errorThrown, "null in error not thrown");
}
{
String testStr = "This is a stdin test";
@@ -171,19 +194,21 @@ protected override void TearDown()
w.WriteLine(testStr);
s.Position = 0;
String line = Console.In.ReadLine();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
}
}
- public void TestSetOut() {
+ [Test]
+ public void TestSetOut()
+ {
{
bool errorThrown = false;
try {
Console.SetOut(null);
} catch (ArgumentNullException) {
errorThrown = true;
}
- Assert("null out error not thrown", errorThrown);
+ Assert.IsTrue (errorThrown, "null out error not thrown");
}
{
String testStr = "This is a stdout test";
@@ -195,11 +220,13 @@ protected override void TearDown()
Console.Out.WriteLine(testStr);
s.Position = 0;
String line = r.ReadLine();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
}
}
- public void TestWrite() {
+ [Test]
+ public void TestWrite()
+ {
Stream s = new MemoryStream();
TextWriter w = new StreamWriter(s);
((StreamWriter)w).AutoFlush = true;
@@ -212,24 +239,24 @@ protected override void TearDown()
Console.Write(testStr);
s.Position = endPos;
String line = r.ReadToEnd();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
endPos = s.Position;
Boolean[] booleans = {true, false};
- foreach (bool b in booleans ) {
+ foreach (bool b in booleans) {
Console.Write(b);
s.Position = endPos;
line = r.ReadToEnd();
- AssertEquals("Wrong boolean", b.ToString(), line);
+ Assert.AreEqual (b.ToString(), line, "Wrong boolean");
endPos = s.Position;
}
Char[] chars = {'a', ';', '?'};
- foreach (Char c in chars ) {
+ foreach (Char c in chars) {
Console.Write(c);
s.Position = endPos;
line = r.ReadToEnd();
- AssertEquals("Wrong char", c.ToString(), line);
+ Assert.AreEqual (c.ToString(), line, "Wrong char");
endPos = s.Position;
}
@@ -240,7 +267,10 @@ protected override void TearDown()
// TODO - Likewise for char[], decimal, double, int, long, object, single, uint32, uint64
// TODO - write with format string
}
- public void TestWriteLine() {
+
+ [Test]
+ public void TestWriteLine()
+ {
Stream s = new MemoryStream();
TextWriter w = new StreamWriter(s);
((StreamWriter)w).AutoFlush = true;
@@ -253,24 +283,24 @@ protected override void TearDown()
Console.WriteLine(testStr);
s.Position = endPos;
String line = r.ReadLine();
- AssertEquals("Wrong line", testStr, line);
+ Assert.AreEqual (testStr, line, "Wrong line");
endPos = s.Position;
Boolean[] booleans = {true, false};
- foreach (bool b in booleans ) {
+ foreach (bool b in booleans) {
Console.WriteLine(b);
s.Position = endPos;
line = r.ReadLine();
- AssertEquals("Wrong boolean", b.ToString(), line);
+ Assert.AreEqual (b.ToString(), line, "Wrong boolean");
endPos = s.Position;
}
Char[] chars = {'a', ';', '?'};
- foreach (Char c in chars ) {
+ foreach (Char c in chars) {
Console.WriteLine(c);
s.Position = endPos;
line = r.ReadLine();
- AssertEquals("Wrong char", c.ToString(), line);
+ Assert.AreEqual (c.ToString(), line, "Wrong char");
endPos = s.Position;
}

0 comments on commit 4eb53a4

Please sign in to comment.