X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FTest%2FSystem.ComponentModel.Design.Serialization%2FInstanceDescriptorTest.cs;fp=mcs%2Fclass%2FSystem%2FTest%2FSystem.ComponentModel.Design.Serialization%2FInstanceDescriptorTest.cs;h=7fe4c29dbf31c7a481226a7250c810356e389cba;hb=5993c313005b7e8cec11869730b3f0526001734b;hp=9792ab641652ef3ff32f6e9a58e61f2235a446dd;hpb=29389a715706be264255869cf52355498567d9e3;p=mono.git diff --git a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/InstanceDescriptorTest.cs b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/InstanceDescriptorTest.cs index 9792ab64165..7fe4c29dbf3 100644 --- a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/InstanceDescriptorTest.cs +++ b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/InstanceDescriptorTest.cs @@ -34,6 +34,7 @@ using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; +using System.Threading; namespace MonoTests.System.ComponentModel.Design.Serialization { @@ -50,20 +51,40 @@ namespace MonoTests.System.ComponentModel.Design.Serialization { } [Test] - public void Constructor_Null_ICollection () + public void Constructor0_Arguments_Mismatch () { - InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }); - Assert.AreEqual (0, id.Arguments.Count, "Arguments"); - Assert.IsTrue (id.IsComplete, "IsComplete"); - Assert.IsNull (id.MemberInfo, "MemberInfo"); + try { + new InstanceDescriptor (ci, null); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + // Length mismatch + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2"); + Assert.IsNull (ex.InnerException, "#B3"); + Assert.IsNotNull (ex.Message, "#B4"); + Assert.IsNull (ex.ParamName, "#B5"); + } } [Test] - [ExpectedException (typeof (ArgumentException))] - public void Constructor_MemberInfo_Null () + public void Constructor0_MemberInfo_Type () { - new InstanceDescriptor (ci, null); - // mismatch for required parameters + Type type = typeof (Uri); + InstanceDescriptor id = new InstanceDescriptor (type, + new object [] { url }); + Assert.AreEqual (1, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.AreSame (type, id.MemberInfo, "#3"); + Assert.IsNull (id.Invoke (), "#4"); + } + + [Test] + public void Constructor_Null_ICollection () + { + InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }); + Assert.AreEqual (0, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.IsNull (id.MemberInfo, "#3"); + Assert.IsNull (id.Invoke (), "#4"); } [Test] @@ -81,9 +102,10 @@ namespace MonoTests.System.ComponentModel.Design.Serialization { public void Constructor_Null_ICollection_Boolean () { InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }, true); - Assert.AreEqual (0, id.Arguments.Count, "Arguments"); - Assert.IsTrue (id.IsComplete, "IsComplete"); - Assert.IsNull (id.MemberInfo, "MemberInfo"); + Assert.AreEqual (0, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.IsNull (id.MemberInfo, "#3"); + Assert.IsNull (id.Invoke (), "#4"); } [Test] @@ -104,5 +126,152 @@ namespace MonoTests.System.ComponentModel.Design.Serialization { Uri uri = (Uri) id.Invoke (); Assert.AreEqual (url, uri.AbsoluteUri, "Invoke"); } + + [Test] + public void Field_Arguments_Empty () + { + FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter"); + + InstanceDescriptor id = new InstanceDescriptor (fi, new object [0]); + Assert.AreEqual (0, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.AreSame (fi, id.MemberInfo, "#3"); + Assert.IsNotNull (id.Invoke (), "#4"); + } + + [Test] + public void Field_Arguments_Mismatch () + { + FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter"); + + try { + new InstanceDescriptor (fi, new object [] { url }); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + // Parameter must be static + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2"); + Assert.IsNull (ex.InnerException, "#3"); + Assert.IsNotNull (ex.Message, "#4"); + Assert.IsNull (ex.ParamName, "#5"); + } + } + + [Test] + public void Field_Arguments_Null () + { + FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter"); + + InstanceDescriptor id = new InstanceDescriptor (fi, null); + Assert.AreEqual (0, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.AreSame (fi, id.MemberInfo, "#3"); + Assert.IsNotNull (id.Invoke (), "#4"); + } + + [Test] + public void Field_MemberInfo_NonStatic () + { + FieldInfo fi = typeof (InstanceField).GetField ("Name"); + + try { + new InstanceDescriptor (fi, null); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + // Parameter must be static + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2"); + Assert.IsNull (ex.InnerException, "#3"); + Assert.IsNotNull (ex.Message, "#4"); + Assert.IsNull (ex.ParamName, "#5"); + } + } + + [Test] + public void Property_Arguments_Mismatch () + { + PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal"); + + InstanceDescriptor id = new InstanceDescriptor (pi, new object [] { url }); + Assert.AreEqual (1, id.Arguments.Count, "#1"); + object [] arguments = new object [id.Arguments.Count]; + id.Arguments.CopyTo (arguments, 0); + Assert.AreSame (url, arguments [0], "#2"); + Assert.IsTrue (id.IsComplete, "#3"); + Assert.AreSame (pi, id.MemberInfo, "#4"); + try { + id.Invoke (); + Assert.Fail ("#5"); + } catch (TargetParameterCountException) { + } + } + + [Test] + public void Property_Arguments_Null () + { + PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal"); + + InstanceDescriptor id = new InstanceDescriptor (pi, null); + Assert.AreEqual (0, id.Arguments.Count, "#1"); + Assert.IsTrue (id.IsComplete, "#2"); + Assert.AreSame (pi, id.MemberInfo, "#3"); + Assert.IsNotNull (id.Invoke (), "#4"); + } + + [Test] + public void Property_MemberInfo_NonStatic () + { + PropertyInfo pi = typeof (Uri).GetProperty ("Host"); + + try { + new InstanceDescriptor (pi, null); + Assert.Fail ("#A1"); + } catch (ArgumentException ex) { + // Parameter must be static + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2"); + Assert.IsNull (ex.InnerException, "#A3"); + Assert.IsNotNull (ex.Message, "#A4"); + Assert.IsNull (ex.ParamName, "#A5"); + } + + try { + new InstanceDescriptor (pi, null, false); + Assert.Fail ("#B1"); + } catch (ArgumentException ex) { + // Parameter must be static + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2"); + Assert.IsNull (ex.InnerException, "#B3"); + Assert.IsNotNull (ex.Message, "#B4"); + Assert.IsNull (ex.ParamName, "#B5"); + } + } + + [Test] + public void Property_MemberInfo_WriteOnly () + { + PropertyInfo pi = typeof (WriteOnlyProperty).GetProperty ("Name"); + + try { + new InstanceDescriptor (pi, null); + Assert.Fail ("#1"); + } catch (ArgumentException ex) { + // Parameter must be readable + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2"); + Assert.IsNull (ex.InnerException, "#3"); + Assert.IsNotNull (ex.Message, "#4"); + Assert.IsNull (ex.ParamName, "#5"); + } + } + + class WriteOnlyProperty + { + public static string Name { + set { + } + } + } + + class InstanceField + { + public string Name; + } } }