GenerateControlStyleTest.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // This code generates the ControlStylesTest.cs test
  3. //
  4. // Author: Peter Dennis Bartok ([email protected])
  5. //
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8. using System;
  9. using System.Reflection;
  10. using System.IO;
  11. using System.Text;
  12. namespace TestApp {
  13. class MainForm {
  14. static Array style_values = Enum.GetValues(typeof(ControlStyles));
  15. static string[] style_names = Enum.GetNames(typeof(ControlStyles));
  16. static string TestHeader = "//\n" +
  17. "// ControlStyleTest.cs (Auto-generated by GenerateControlStyleTest.cs).\n" +
  18. "//\n" +
  19. "// Author: \n" +
  20. "// Peter Dennis Bartok ([email protected])\n" +
  21. "//\n" +
  22. "// (C) 2005 Novell, Inc. (http://www.novell.com)\n" +
  23. "//\n" +
  24. "using System;\n" +
  25. "using System.Windows.Forms;\n" +
  26. "using System.Drawing;\n" +
  27. "using System.Reflection;\n" +
  28. "using NUnit.Framework;\n\n" +
  29. "namespace MonoTests.System.Windows.Forms {\n" +
  30. "\t[TestFixture]\n" +
  31. "\tpublic class TestControlStyle {\n\n" +
  32. "\t\tstatic Array style_values = Enum.GetValues(typeof(ControlStyles));\n" +
  33. "\t\tstatic string[] style_names = Enum.GetNames(typeof(ControlStyles));\n\n" +
  34. " public static string[] GetStyles(Control control) {\n" +
  35. " string[] result;\n\n" +
  36. " result = new string[style_names.Length];\n\n" +
  37. " for (int i = 0; i < style_values.Length; i++) {\n" +
  38. " result[i] = style_names[i] + \"=\" + control.GetType().GetMethod(\"GetStyle\", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(control, new object[1] {(ControlStyles)style_values.GetValue(i)});\n" +
  39. " }\n\n" +
  40. " return result;\n" +
  41. " }\n";
  42. static string TestFooter = "\t}\n}\n";
  43. public static string[] GetStyles(Control control) {
  44. string[] result;
  45. result = new string[style_names.Length];
  46. for (int i = 0; i < style_values.Length; i++) {
  47. result[i] = style_names[i] + "=" + control.GetType().GetMethod("GetStyle", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(control, new object[1] {(ControlStyles)style_values.GetValue(i)});
  48. }
  49. return result;
  50. }
  51. public static void TestStyles(StreamWriter file, Control control, string name) {
  52. string[] results;
  53. results = GetStyles(control);
  54. file.WriteLine("\t\t[Test]");
  55. file.WriteLine("\t\tpublic void {0}StyleTest ()", name);
  56. file.WriteLine("\t\t{");
  57. file.WriteLine("\t\t\tstring[] {0}_want = {{", name);
  58. for (int i=0; i < results.Length; i++) {
  59. if ((i+1) != results.Length) {
  60. file.WriteLine("\t\t\t\t\"{0}\",", results[i]);
  61. } else {
  62. file.WriteLine("\t\t\t\t\"{0}\"", results[i]);
  63. }
  64. }
  65. file.WriteLine("\t\t\t};\n");
  66. file.WriteLine("\t\t\tAssert.AreEqual({0}_want, GetStyles(new {0}()), \"{0}Styles\");", name);
  67. file.WriteLine("\t\t}\n\n");
  68. }
  69. public static void Main(string[] args) {
  70. using (StreamWriter file = new StreamWriter("c:\\ControlStyleTest.cs", false, Encoding.ASCII, 1024)) {
  71. file.WriteLine(TestHeader);
  72. TestStyles(file, new Control(), "Control");
  73. TestStyles(file, new Button(), "Button");
  74. TestStyles(file, new CheckBox(), "CheckBox");
  75. TestStyles(file, new RadioButton(), "RadioButton");
  76. TestStyles(file, new DataGrid(), "DataGrid");
  77. TestStyles(file, new DateTimePicker(), "DateTimePicker");
  78. TestStyles(file, new GroupBox(), "GroupBox");
  79. TestStyles(file, new Label(), "Label");
  80. TestStyles(file, new LinkLabel(), "LinkLabel");
  81. TestStyles(file, new ComboBox(), "ComboBox");
  82. TestStyles(file, new ListBox(), "ListBox");
  83. TestStyles(file, new CheckedListBox(), "CheckedListBox");
  84. TestStyles(file, new ListView(), "ListView");
  85. TestStyles(file, new MdiClient(), "MdiClient");
  86. TestStyles(file, new MonthCalendar(), "MonthCalendar");
  87. TestStyles(file, new PictureBox(), "PictureBox");
  88. // Mono doesn't support yet
  89. //TestStyles(file, new PrintPreviewControl(), "PrintPreviewControl");
  90. TestStyles(file, new ProgressBar(), "ProgressBar");
  91. TestStyles(file, new ScrollableControl(), "ScrollableControl");
  92. TestStyles(file, new ContainerControl(), "ContainerControl");
  93. Form f = new Form ();
  94. f.ShowInTaskbar = false;
  95. TestStyles(file, f, "Form");
  96. f.Dispose ();
  97. TestStyles(file, new PropertyGrid(), "PropertyGrid");
  98. TestStyles(file, new DomainUpDown(), "DomainUpDown");
  99. TestStyles(file, new NumericUpDown(), "NumericUpDown");
  100. TestStyles(file, new UserControl(), "UserControl");
  101. TestStyles(file, new Panel(), "Panel");
  102. TestStyles(file, new TabPage(), "TabPage");
  103. TestStyles(file, new HScrollBar(), "HScrollBar");
  104. TestStyles(file, new VScrollBar(), "VScrollBar");
  105. TestStyles(file, new Splitter(), "Splitter");
  106. TestStyles(file, new StatusBar(), "StatusBar");
  107. TestStyles(file, new TabControl(), "TabControl");
  108. TestStyles(file, new RichTextBox(), "RichTextBox");
  109. TestStyles(file, new TextBox(), "TextBox");
  110. TestStyles(file, new DataGridTextBox(), "DataGridTextBox");
  111. TestStyles(file, new ToolBar(), "ToolBar");
  112. TestStyles(file, new TrackBar(), "TrackBar");
  113. TestStyles(file, new TreeView(), "TreeView");
  114. file.WriteLine(TestFooter);
  115. }
  116. }
  117. }
  118. }