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