# Patch created by Tum # Date: Mon May 12 21:40:09 NZST 2003 # Repository: pnetlib # Comments: # Test cases for MemoryStream #### End of Preamble #### #### Patch data follows #### Index: ChangeLog =================================================================== RCS file: /cvsroot/dotgnu-pnet/pnetlib/ChangeLog,v retrieving revision 1.900 diff -c -r1.900 ChangeLog *** ChangeLog 11 May 2003 19:11:26 -0000 1.900 --- ChangeLog 12 May 2003 09:34:34 -0000 *************** *** 1,3 **** --- 1,15 ---- + 2003-05-12 Thong Nguyen <tum@veridicus.com> + * tests/runtime/System/IO/SuiteIO.cs + tests/runtime/System/IO/TestMemoryStream.cs + Added test cases for MemoryStream. + + 2003-05-12 Thong Nguyen <tum@veridicus.com> + + * runtime/System/IO/MemoryStream.cs: Fixed bug that prevented + streams from growing larger than the default capacity of 16. + Changed the default capacity to 0 to align with Mono and MS. + The capacity jumps to 1024 on first write (just like Mono and + MS). 2003-05-12 Gopal.V <gopalv82@symonds.net> Index: tests/runtime/System/IO/SuiteIO.cs =================================================================== *** /dev/null Mon May 12 21:40:13 2003 --- tests/runtime/System/IO/SuiteIO.cs Mon May 12 21:28:06 2003 *************** *** 0 **** --- 1,34 ---- + /* + * SuiteText.cs - Tests for the "System.Text" namespace. + * + * Copyright (C) 2002 Southern Storm Software, Pty Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + using CSUnit; + using System; + + public class SuiteIO + { + + public static TestSuite Suite() + { + TestSuite suite = new TestSuite("IO Tests"); + suite.AddTests(typeof(TestMemoryStream)); + return suite; + } + + }; // class SuiteText Index: tests/runtime/System/IO/TestMemoryStream.cs =================================================================== *** /dev/null Mon May 12 21:40:13 2003 --- tests/runtime/System/IO/TestMemoryStream.cs Mon May 12 21:37:58 2003 *************** *** 0 **** --- 1,80 ---- + /* + * TestMemoryStream.cs - Test class for "System.IO.MemoryStream" + * + * Copyright (C) 2002 Southern Storm Software, Pty Ltd. + * Copyright (C) 2002 FSF. + * + * Authors : Thong Nguyen (tum@veridicus.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + using CSUnit; + using System; + using System.IO; + + public class TestMemoryStream : TestCase + { + // Constructor. + public TestMemoryStream(String name) : base(name) + { + // Nothing to do here. + } + + // Set up for the tests. + protected override void Setup() + { + // Nothing to do here. + } + + // Clean up after the tests. + protected override void Cleanup() + { + // Nothing to do here. + } + + public void TestMemoryGrows() + { + int x; + byte[] buffer; + MemoryStream ms = new MemoryStream(); + + x = ms.Capacity; + + buffer = new byte[Math.Max(x, 1024)]; + + Assert("ms.Length == 0", ms.Length == 0); + + ms.Write(buffer, 0, buffer.Length); + + Assert("ms.Capacity > buffer.Length", + ms.Capacity >= buffer.Length); + + Assert("ms.Length == buffer.Length", + ms.Length == buffer.Length); + + for (int i = 0; i < 9; i++) + { + ms.Write(buffer, 0, buffer.Length); + } + + Assert("ms.Capacity >= buffer.Length * 10", + ms.Capacity >= buffer.Length * 10); + + Assert("ms.Length == buffer.Length * 10", + ms.Length == buffer.Length * 10); + } + + } #### End of Patch data ####