From d46799b1c9cb0f6976de1a23c8ed10ae7cb4153d Mon Sep 17 00:00:00 2001 From: John Luke Date: Mon, 26 Dec 2005 18:21:47 +0000 Subject: [PATCH] 2005-12-26 John Luke * ContentDisposition.cs: Size is -1 by default throw ArgumentNullException and ArgumentException for set_DispositionType * ContentType.cs: throw ArgumentNullException, ArgumentException, and FormatException for set_MediaType don't print Boundary,Name in ToString() if they are "" svn path=/trunk/mcs/; revision=54852 --- mcs/class/System/System.Net.Mime/ChangeLog | 9 ++++ .../System/System.Net.Mime/ContentDisposition.cs | 12 +++-- mcs/class/System/System.Net.Mime/ContentType.cs | 14 ++++-- mcs/class/System/Test/ChangeLog | 4 ++ .../Test/System.Net.Mime/ContentDispositionTest.cs | 28 ++++++++++++ .../System/Test/System.Net.Mime/ContentTypeTest.cs | 53 ++++++++++++++++++---- 6 files changed, 104 insertions(+), 16 deletions(-) diff --git a/mcs/class/System/System.Net.Mime/ChangeLog b/mcs/class/System/System.Net.Mime/ChangeLog index 29d2b273253..e81f86a56a0 100644 --- a/mcs/class/System/System.Net.Mime/ChangeLog +++ b/mcs/class/System/System.Net.Mime/ChangeLog @@ -1,3 +1,12 @@ +2005-12-26 John Luke + + * ContentDisposition.cs: Size is -1 by default + throw ArgumentNullException and ArgumentException for + set_DispositionType + * ContentType.cs: throw ArgumentNullException, ArgumentException, + and FormatException for set_MediaType + don't print Boundary,Name in ToString() if they are "" + 2005-12-23 John Luke * ContentDisposition.cs: override GetHashCode and diff --git a/mcs/class/System/System.Net.Mime/ContentDisposition.cs b/mcs/class/System/System.Net.Mime/ContentDisposition.cs index f4e44a0ef91..afc172e1c30 100644 --- a/mcs/class/System/System.Net.Mime/ContentDisposition.cs +++ b/mcs/class/System/System.Net.Mime/ContentDisposition.cs @@ -50,7 +50,7 @@ namespace System.Net.Mime { string filename; DateTime modificationDate; DateTime readDate; - long size; + long size = -1; // -1 means the size is unknown StringDictionary parameters = new StringDictionary (); #endregion // Fields @@ -129,7 +129,13 @@ namespace System.Net.Mime { public string DispositionType { get { return dispositionType; } - set { dispositionType = value; } + set { + if (value == null) + throw new ArgumentNullException (); + if (value.Length < 1) + throw new ArgumentException (); + dispositionType = value; + } } public string FileName { @@ -214,7 +220,7 @@ namespace System.Net.Mime { sb.Append ("; filename="); sb.Append (FileName); } - if (Size > 0) { + if (Size > -1) { sb.Append ("; size="); sb.Append (Size.ToString ()); } diff --git a/mcs/class/System/System.Net.Mime/ContentType.cs b/mcs/class/System/System.Net.Mime/ContentType.cs index 18380c95415..34825666840 100644 --- a/mcs/class/System/System.Net.Mime/ContentType.cs +++ b/mcs/class/System/System.Net.Mime/ContentType.cs @@ -125,7 +125,15 @@ namespace System.Net.Mime { public string MediaType { get { return mediaType; } - set { mediaType = value; } + set { + if (value == null) + throw new ArgumentNullException (); + if (value.Length < 1) + throw new ArgumentException (); + if (value.IndexOf (';') != -1) + throw new FormatException (); + mediaType = value; + } } public string Name { @@ -166,11 +174,11 @@ namespace System.Net.Mime { sb.Append ("; charset="); sb.Append (CharSet); } - if (Name != null) { + if (Name != null && Name.Length > 0) { sb.Append ("; name="); sb.Append (Name); } - if (Boundary != null) { + if (Boundary != null && Boundary.Length > 0) { sb.Append ("; boundary="); sb.Append (Boundary); } diff --git a/mcs/class/System/Test/ChangeLog b/mcs/class/System/Test/ChangeLog index ba783379eb2..eef0810e24b 100644 --- a/mcs/class/System/Test/ChangeLog +++ b/mcs/class/System/Test/ChangeLog @@ -1,3 +1,7 @@ +2005-12-25 John Luke + + * System.Net.Mail/*Test.cs: additional tests + 2005-12-24 John Luke * System.Net.Mail/*Test.cs: add tests diff --git a/mcs/class/System/Test/System.Net.Mime/ContentDispositionTest.cs b/mcs/class/System/Test/System.Net.Mime/ContentDispositionTest.cs index 2e73f987cba..221ea9c1b1e 100644 --- a/mcs/class/System/Test/System.Net.Mime/ContentDispositionTest.cs +++ b/mcs/class/System/Test/System.Net.Mime/ContentDispositionTest.cs @@ -35,6 +35,20 @@ namespace MonoTests.System.Net.Mime } [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void DispositionTypeNull () + { + cd.DispositionType = null; + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void DispositionTypeEmpty () + { + cd.DispositionType = ""; + } + + [Test] public void EqualsHashCode () { ContentDisposition dummy1 = new ContentDisposition (); @@ -64,6 +78,12 @@ namespace MonoTests.System.Net.Mime } [Test] + public void Size () + { + Assert.IsTrue (cd.Size == -1); + } + + [Test] [ExpectedException (typeof (ArgumentNullException))] public void ArgumentNullException () { @@ -95,6 +115,14 @@ namespace MonoTests.System.Net.Mime ContentDisposition dummy = new ContentDisposition (); Assert.IsTrue (dummy.ToString () == "attachment"); } + + [Test] + public void ToStringTest3 () + { + ContentDisposition dummy = new ContentDisposition (); + dummy.Size = 0; + Assert.IsTrue (dummy.ToString () == "attachment; size=0"); + } } } #endif diff --git a/mcs/class/System/Test/System.Net.Mime/ContentTypeTest.cs b/mcs/class/System/Test/System.Net.Mime/ContentTypeTest.cs index c6a9c9e5d41..c97dcbf737f 100644 --- a/mcs/class/System/Test/System.Net.Mime/ContentTypeTest.cs +++ b/mcs/class/System/Test/System.Net.Mime/ContentTypeTest.cs @@ -25,6 +25,39 @@ namespace MonoTests.System.Net.Mime } [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void ArgumentNullException () + { + new ContentType (null); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void ArgumentException () + { + new ContentType (""); + } + + /*[Test] + [ExpectedException (typeof (FormatException))] + public void FormatException () + { + new ContentType (";;;"); + }*/ + + [Test] + public void Boundary () + { + Assert.IsNull (ct.Boundary); + } + + [Test] + public void CharSet () + { + Assert.IsNull (ct.CharSet); + } + + [Test] public void MediaType () { Assert.IsTrue (ct.MediaType == "application/octet-stream"); @@ -32,24 +65,24 @@ namespace MonoTests.System.Net.Mime [Test] [ExpectedException (typeof (ArgumentNullException))] - public void ArgumentNullException () + public void MediaTypeNullException () { - new ContentType (null); + ct.MediaType = null; } [Test] [ExpectedException (typeof (ArgumentException))] - public void ArgumentException () + public void MediaTypeEmptyException () { - new ContentType (""); + ct.MediaType = ""; } - //[Test] - //[ExpectedException (typeof (FormatException))] - //public void FormatException () - //{ - // new ContentType ("some unparsable format"); - //} + [Test] + [ExpectedException (typeof (FormatException))] + public void MediaTypeFormatException () + { + ct.MediaType = "application/x-myType;"; + } [Test] public void ToStringTest () -- 2.11.4.GIT