X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FTest%2FMicrosoft.CSharp%2FCodeGeneratorFromTypeTest.cs;h=42a42146a3e47507d1320ecd1a3e4d159db4df51;hb=4239ddd9f18d778e03cc979c9d15135e47fb0e28;hp=c73a2e029bef95968669c54e5131f761301c8070;hpb=04d1b4116331e3813b8f75304f714a5d61ba1214;p=mono.git diff --git a/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs b/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs index c73a2e029be..42a42146a3e 100644 --- a/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs +++ b/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs @@ -12,6 +12,7 @@ using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Globalization; +using System.IO; using Microsoft.CSharp; @@ -109,11 +110,7 @@ namespace MonoTests.Microsoft.CSharp { string code = GenerateDerivedType (Options); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, -#if NET_2_0 "internal abstract class Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#else - "abstract class Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#endif "}}{0}", NewLine), code); } @@ -159,11 +156,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal event int Click;{0}" + -#else - " /*FamANDAssem*/ internal event int Click;{0}" + -#endif "}}{0}", NewLine), code); } @@ -233,6 +226,34 @@ namespace MonoTests.Microsoft.CSharp "}}{0}", NewLine), code); } + [Test] + public void AbstractPropertyTest () + { + string code = GenerateAbstractProperty (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public abstract class Test1 {{{0}" + + " {0}" + + " public abstract string Name {{{0}" + + " get;{0}" + + " set;{0}" + + " }}{0}" + + "}}{0}", NewLine), code); + } + + [Test] + public void StaticPropertyTest () + { + string code = GenerateStaticProperty (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public class Test1 {{{0}" + + " {0}" + + " public static string Name {{{0}" + + " set {{{0}" + + " }}{0}" + + " }}{0}" + + "}}{0}", NewLine), code); + } + [Test] public override void PropertyMembersTypeTest1 () { @@ -302,11 +323,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Name {{{0}" + -#else - " internal int Name {{{0}" + -#endif " set {{{0}" + " }}{0}" + " }}{0}" + @@ -375,11 +392,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Name {{{0}" + -#else - " internal int Name {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -635,11 +648,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Execute() {{{0}" + -#else - " internal int Execute() {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -651,11 +660,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Execute() {{{0}" + -#else - " internal int Execute() {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -726,6 +731,18 @@ namespace MonoTests.Microsoft.CSharp "}}{0}", NewLine), code); } + [Test] + public override void MethodParamArrayAttribute () + { + string code = GenerateMethodParamArrayAttribute (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public class Test1 {{{0}" + + " {0}" + + " public virtual int Something([A()] [B()] params out object value, [C()] ref int ) {{{0}" + + " }}{0}" + + "}}{0}", NewLine), code); + } + [Test] public override void MethodReturnTypeAttributes () { @@ -735,8 +752,10 @@ namespace MonoTests.Microsoft.CSharp " {0}" + " [A()]{0}" + " [B()]{0}" + + " params{0}" + " [return: C(A1=false, A2=true)]{0}" + " [return: D()]{0}" + + " return: params{0}" + " public virtual int Execute() {{{0}" + " }}{0}" + "}}{0}", NewLine), code); @@ -872,10 +891,8 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " [B()]{0}" + -#endif " static Test1() {{{0}" + " }}{0}" + "}}{0}", NewLine), code); @@ -892,10 +909,8 @@ namespace MonoTests.Microsoft.CSharp "public class Test1{0}" + "{{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " [B()]{0}" + -#endif " static Test1(){0}" + " {{{0}" + " }}{0}" + @@ -909,18 +924,54 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public class Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " public static int Main() {{{0}" + -#else - " public static void Main() {{{0}" + -#endif " Test.InnerType x;{0}" + " }}{0}" + "}}{0}", NewLine), code); } #endregion Override implementation of CodeGeneratorFromTypeTestBase + + [Test] + public void EscapePropertyName () + { + CodeNamespace cns = new CodeNamespace (); + CodeTypeDeclaration ctd = new CodeTypeDeclaration ("TestType"); + CodeMemberProperty f = new CodeMemberProperty (); + f.Type = new CodeTypeReference (typeof (string)); + f.Name = "default"; + f.GetStatements.Add (new CodeMethodReturnStatement ( + new CodePrimitiveExpression (null))); + ctd.Members.Add (f); + cns.Types.Add (ctd); + CSharpCodeProvider p = new CSharpCodeProvider (); + StringWriter sw = new StringWriter (); + p.CreateGenerator ().GenerateCodeFromNamespace (cns, sw, null); + Assert.IsTrue (sw.ToString ().IndexOf ("@default") > 0); + } + + [Test] + public void GenericCodeTypeReferencesTest () + { + string code = GenerateGenericCodeTypeReferences (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public class Test {{{0}" + + " {0}" + + " private System.Nullable Foo;{0}" + + " {0}" + + " private System.Nullable<> Bar;{0}" + + "}}{0}", NewLine), code); + } + + [Test] + public override void PartialTypeTest () + { + string code = GeneratePartialType (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public partial class Test1 {{{0}" + + "}}{0}", NewLine), code); + } } [TestFixture] @@ -1309,6 +1360,14 @@ namespace MonoTests.Microsoft.CSharp "public delegate void Test1();{0}{0}", NewLine), code); } + [Test] + public override void MethodParamArrayAttribute () + { + string code = GenerateMethodParamArrayAttribute (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public delegate void Test1();{0}{0}", NewLine), code); + } + [Test] public override void MethodReturnTypeAttributes () { @@ -1395,16 +1454,21 @@ namespace MonoTests.Microsoft.CSharp string code = GenerateEntryPointMethod (Options); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public delegate void Test1();{0}{0}" + -#if NET_2_0 "[A()]{0}" + "public static int Main() {{{0}" + -#else - "public static void Main() {{{0}" + -#endif " Test.InnerType x;{0}" + "}}{0}", NewLine), code); } + [Test] + public override void PartialTypeTest () + { + string code = GeneratePartialType (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public delegate void Test1();{0}" + , NewLine), code); + } + #endregion Override implementation of CodeGeneratorFromTypeTestBase } @@ -1497,11 +1561,7 @@ namespace MonoTests.Microsoft.CSharp { string code = GenerateDerivedType (Options); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, -#if NET_2_0 "internal interface Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#else - "interface Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#endif "}}{0}", NewLine), code); } @@ -1547,11 +1607,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public interface Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal event int Click;{0}" + -#else - " /*FamANDAssem*/ internal event int Click;{0}" + -#endif "}}{0}", NewLine), code); } @@ -2005,6 +2061,17 @@ namespace MonoTests.Microsoft.CSharp "}}{0}", NewLine), code); } + [Test] + public override void MethodParamArrayAttribute () + { + string code = GenerateMethodParamArrayAttribute (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public interface Test1 {{{0}" + + " {0}" + + " int Something([A()] [B()] params out object value, [C()] ref int );{0}" + + "}}{0}", NewLine), code); + } + [Test] public override void MethodReturnTypeAttributes () { @@ -2014,8 +2081,10 @@ namespace MonoTests.Microsoft.CSharp " {0}" + " [A()]{0}" + " [B()]{0}" + + " params{0}" + " [return: C(A1=false, A2=true)]{0}" + " [return: D()]{0}" + + " return: params{0}" + " int Execute();{0}" + "}}{0}", NewLine), code); } @@ -2146,17 +2215,21 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public interface Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " public static int Main() {{{0}" + -#else - " public static void Main() {{{0}" + -#endif " Test.InnerType x;{0}" + " }}{0}" + "}}{0}", NewLine), code); } + [Test] + public override void PartialTypeTest () + { + string code = GeneratePartialType (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public partial interface Test1 {{{0}" + + "}}{0}", NewLine), code); + } #endregion Override implementation of CodeGeneratorFromTypeTestBase } @@ -2249,11 +2322,7 @@ namespace MonoTests.Microsoft.CSharp { string code = GenerateDerivedType (Options); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, -#if NET_2_0 "internal struct Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#else - "struct Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#endif "}}{0}", NewLine), code); } @@ -2299,11 +2368,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal event int Click;{0}" + -#else - " /*FamANDAssem*/ internal event int Click;{0}" + -#endif "}}{0}", NewLine), code); } @@ -2415,11 +2480,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Name {{{0}" + -#else - " internal int Name {{{0}" + -#endif " set {{{0}" + " }}{0}" + " }}{0}" + @@ -2488,11 +2549,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Name {{{0}" + -#else - " internal int Name {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -2724,11 +2781,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Execute() {{{0}" + -#else - " internal int Execute() {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -2740,11 +2793,7 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " internal virtual int Execute() {{{0}" + -#else - " internal int Execute() {{{0}" + -#endif " }}{0}" + "}}{0}", NewLine), code); } @@ -2803,6 +2852,18 @@ namespace MonoTests.Microsoft.CSharp "}}{0}", NewLine), code); } + [Test] + public override void MethodParamArrayAttribute () + { + string code = GenerateMethodParamArrayAttribute (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public struct Test1 {{{0}" + + " {0}" + + " public virtual int Something([A()] [B()] params out object value, [C()] ref int ) {{{0}" + + " }}{0}" + + "}}{0}", NewLine), code); + } + [Test] public override void MethodReturnTypeAttributes () { @@ -2812,8 +2873,10 @@ namespace MonoTests.Microsoft.CSharp " {0}" + " [A()]{0}" + " [B()]{0}" + + " params{0}" + " [return: C(A1=false, A2=true)]{0}" + " [return: D()]{0}" + + " return: params{0}" + " public virtual int Execute() {{{0}" + " }}{0}" + "}}{0}", NewLine), code); @@ -2949,10 +3012,8 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " [B()]{0}" + -#endif " static Test1() {{{0}" + " }}{0}" + "}}{0}", NewLine), code, "#1"); @@ -2969,10 +3030,8 @@ namespace MonoTests.Microsoft.CSharp "public struct Test1{0}" + "{{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " [B()]{0}" + -#endif " static Test1(){0}" + " {{{0}" + " }}{0}" + @@ -2986,17 +3045,21 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public struct Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " public static int Main() {{{0}" + -#else - " public static void Main() {{{0}" + -#endif " Test.InnerType x;{0}" + " }}{0}" + "}}{0}", NewLine), code); } + [Test] + public override void PartialTypeTest () + { + string code = GeneratePartialType (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public partial struct Test1 {{{0}" + + "}}{0}", NewLine), code); + } #endregion Override implementation of CodeGeneratorFromTypeTestBase } @@ -3089,11 +3152,7 @@ namespace MonoTests.Microsoft.CSharp { string code = GenerateDerivedType (Options); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, -#if NET_2_0 "internal enum Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#else - "enum Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" + -#endif "}}{0}", NewLine), code); } @@ -3514,6 +3573,16 @@ namespace MonoTests.Microsoft.CSharp "}}{0}", NewLine), code); } + [Test] + public override void MethodParamArrayAttribute () + { + string code = GenerateMethodParamArrayAttribute (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public enum Test1 {{{0}" + + " {0}" + + "}}{0}", NewLine), code); + } + [Test] public override void MethodReturnTypeAttributes () { @@ -3639,17 +3708,22 @@ namespace MonoTests.Microsoft.CSharp Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "public enum Test1 {{{0}" + " {0}" + -#if NET_2_0 " [A()]{0}" + " public static int Main() {{{0}" + -#else - " public static void Main() {{{0}" + -#endif " Test.InnerType x;{0}" + " }}{0}" + "}}{0}", NewLine), code); } + [Test] + public override void PartialTypeTest () + { + string code = GeneratePartialType (Options); + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "public enum Test1 {{{0}" + + "}}{0}", NewLine), code); + } + #endregion Override implementation of CodeGeneratorFromTypeTestBase } }