2 // CommonDialogsTest.cs: Tests for common dialogs.
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
26 // Alexander Olk <alex.olk@googlemail.com>
30 using System.Collections;
32 using System.Drawing.Printing;
33 using System.Windows.Forms;
35 using System.ComponentModel;
36 using NUnit.Framework;
38 namespace MonoTests.System.Windows.Forms
41 public class CommonDialogsTest
46 FolderBrowserDialog fbd;
50 public void ColorDialogTest ()
52 cd = new ColorDialog ();
54 Assert.AreEqual (Color.Black, cd.Color, "#1");
55 Assert.IsTrue (cd.AllowFullOpen, "#2");
56 Assert.IsFalse (cd.AnyColor, "#3");
57 Assert.IsFalse (cd.FullOpen, "#4");
58 Assert.IsNotNull (cd.CustomColors, "#5");
59 Assert.IsFalse (cd.ShowHelp, "#6");
60 Assert.IsFalse (cd.SolidColorOnly, "#7");
61 Assert.AreEqual ("System.Windows.Forms.ColorDialog, Color: Color [Black]", cd.ToString (), "#8");
64 Assert.AreEqual (Color.Red, cd.Color, "#9");
66 cd.AllowFullOpen = false;
68 Assert.IsTrue (cd.FullOpen, "#10");
70 int[] custom_colors = new int[] {Color.Yellow.ToArgb (), Color.Red.ToArgb ()};
71 cd.CustomColors = custom_colors;
72 Assert.IsNotNull (cd.CustomColors, "#10a");
73 Assert.AreEqual (16, cd.CustomColors.Length, "#10aa");
74 Assert.AreEqual (Color.Red.ToArgb (), cd.CustomColors[1], "#10ab");
75 Assert.AreEqual (Color.FromArgb(0, 255, 255, 255).ToArgb (), cd.CustomColors[15], "#10ac");
77 cd.CustomColors = null;
78 Assert.IsNotNull (cd.CustomColors, "#10b");
79 Assert.AreEqual (16, cd.CustomColors.Length, "#10bb");
80 Assert.AreEqual (Color.FromArgb(0, 255, 255, 255).ToArgb (), cd.CustomColors[0], "#10bc");
82 cd.AllowFullOpen = true;
83 cd.CustomColors = custom_colors;
84 Assert.IsNotNull (cd.CustomColors, "#10c");
85 Assert.AreEqual (16, cd.CustomColors.Length, "#10cc");
89 public void OpenFileDialogTest ()
91 ofd = new OpenFileDialog ();
93 Assert.IsTrue (ofd.AddExtension, "#11");
94 Assert.IsTrue (ofd.CheckFileExists, "#12");
95 Assert.IsTrue (ofd.CheckPathExists, "#13");
96 Assert.AreEqual ("", ofd.DefaultExt, "#14");
97 Assert.IsTrue (ofd.DereferenceLinks, "#15");
98 Assert.AreEqual ("", ofd.FileName, "#16");
99 Assert.IsNotNull (ofd.FileNames, "#17");
100 Assert.AreEqual (0, ofd.FileNames.Length, "#17a");
101 Assert.AreEqual ("", ofd.Filter, "#18");
102 Assert.AreEqual (1, ofd.FilterIndex, "#19");
103 Assert.AreEqual ("", ofd.InitialDirectory, "#20");
104 Assert.IsFalse (ofd.Multiselect, "#21");
105 Assert.IsFalse (ofd.ReadOnlyChecked, "#22");
106 Assert.IsFalse (ofd.RestoreDirectory, "#23");
107 Assert.IsFalse (ofd.ShowHelp, "#24");
108 Assert.IsFalse (ofd.ShowReadOnly, "#25");
109 Assert.AreEqual ("", ofd.Title, "#26");
110 Assert.IsTrue (ofd.ValidateNames, "#27");
111 Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#28");
113 ofd.DefaultExt = ".TXT";
114 Assert.AreEqual ("TXT", ofd.DefaultExt, "#29");
117 Assert.AreEqual ("", ofd.Filter, "#30");
119 ofd.Filter = "Text (*.txt)|*.txt|All (*.*)|*.*";
123 } catch (Exception) {
126 Assert.AreEqual ("Text (*.txt)|*.txt|All (*.*)|*.*", ofd.Filter, "#30a");
128 ofd.FilterIndex = 10;
129 Assert.AreEqual (10, ofd.FilterIndex, "#30aa");
132 Assert.AreEqual ("", ofd.Filter, "#30b");
133 Assert.AreEqual (10, ofd.FilterIndex, "#30ba");
135 string current_path = Environment.CurrentDirectory;
136 string current_file = Path.Combine(current_path, "test_file");
137 if (!File.Exists (current_file))
138 File.Create (current_file);
140 ofd.FileName = current_file;
142 Assert.AreEqual (current_file, ofd.FileName, "#31");
144 string[] file_names = ofd.FileNames;
145 Assert.AreEqual (current_file, file_names [0], "#32");
148 Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: Test, FileName: " + current_file, ofd.ToString (), "#33");
151 Assert.AreEqual ("", ofd.FileName, "#33a");
152 Assert.IsNotNull (ofd.FileNames, "#33b");
153 Assert.AreEqual (0, ofd.FileNames.Length, "#33c");
158 Assert.IsTrue (ofd.AddExtension, "#34");
159 Assert.IsTrue (ofd.CheckFileExists, "#35");
160 Assert.IsTrue (ofd.CheckPathExists, "#36");
161 Assert.AreEqual ("", ofd.DefaultExt, "#37");
162 Assert.IsTrue (ofd.DereferenceLinks, "#38");
163 Assert.AreEqual ("", ofd.FileName, "#39");
164 Assert.IsNotNull (ofd.FileNames, "#40");
165 Assert.AreEqual ("", ofd.Filter, "#41");
166 Assert.AreEqual (1, ofd.FilterIndex, "#42");
167 Assert.AreEqual ("", ofd.InitialDirectory, "#43");
168 Assert.IsFalse (ofd.Multiselect, "#44");
169 Assert.IsFalse (ofd.ReadOnlyChecked, "#45");
170 Assert.IsFalse (ofd.RestoreDirectory, "#46");
171 Assert.IsFalse (ofd.ShowHelp, "#47");
172 Assert.IsFalse (ofd.ShowReadOnly, "#48");
173 Assert.AreEqual ("", ofd.Title, "#49");
174 Assert.IsTrue (ofd.ValidateNames, "#50");
175 Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#60");
179 [ExpectedException(typeof(ArgumentException))]
180 public void FileDialogFilterArgumentException () {
182 ofd = new OpenFileDialog ();
184 ofd.Filter = "xyafj";
188 public void SaveFileDialogTest ()
190 // most of the OpenFileDialogTest are also valid for SaveFileDialg
191 sfd = new SaveFileDialog ();
193 Assert.IsFalse (sfd.CreatePrompt, "#61");
195 Assert.IsTrue (sfd.OverwritePrompt, "#62");
199 public void FontDialogTest ()
201 fd = new FontDialog ();
203 Assert.IsTrue (fd.AllowScriptChange, "#63");
204 Assert.IsTrue (fd.AllowSimulations, "#64");
205 Assert.IsTrue (fd.AllowVectorFonts, "#65");
206 Assert.IsTrue (fd.AllowVerticalFonts, "#66");
208 Assert.AreEqual (Color.Black, fd.Color, "#67");
209 Assert.IsFalse (fd.FixedPitchOnly, "#68");
211 //Assert.AreEqual ("[Font: Name=Microsoft Sans Serif, Size=8,25, Units=3, GdiCharSet=0, GdiVerticalFont=False]", fd.Font.ToString (), "#69");
213 Assert.IsFalse (fd.FontMustExist, "#70");
215 Assert.AreEqual (0, fd.MaxSize, "#71");
216 Assert.AreEqual (0, fd.MinSize, "#72");
218 Assert.IsFalse (fd.ScriptsOnly, "#73");
220 Assert.IsFalse (fd.ShowApply, "#74");
222 Assert.IsFalse (fd.ShowColor, "#75");
224 Assert.IsTrue (fd.ShowEffects, "#76");
226 Assert.IsFalse (fd.ShowHelp, "#77");
228 //Assert.AreEqual ("System.Windows.Forms.FontDialog, Font: [Font: Name=Microsoft Sans Serif, Size=8,25, Units=3, GdiCharSet=0, GdiVerticalFont=False]", fd.ToString (), "#78");
231 Assert.AreEqual (0, fd.MaxSize, "#79");
234 Assert.AreEqual (0, fd.MinSize, "#80");
238 Assert.AreEqual (10, fd.MinSize, "#81");
241 Assert.AreEqual (48, fd.MaxSize, "#82");
245 public void FolderBrowserDialogTest ()
247 fbd = new FolderBrowserDialog ();
249 Assert.AreEqual ("", fbd.Description, "#83");
251 Assert.AreEqual (Environment.SpecialFolder.Desktop, fbd.RootFolder, "#84");
253 Assert.AreEqual ("", fbd.SelectedPath, "#85");
255 Assert.IsTrue (fbd.ShowNewFolderButton, "#86");
257 Assert.AreEqual ("System.Windows.Forms.FolderBrowserDialog", fbd.ToString (), "#87");
259 string current_path = Environment.CurrentDirectory;
260 fbd.SelectedPath = current_path;
262 Assert.AreEqual (current_path, fbd.SelectedPath, "#89");
266 [ExpectedException(typeof(InvalidEnumArgumentException))]
267 public void FolderBrowserDialogInvalidEnumArgumentExceptionTest () {
269 fbd = new FolderBrowserDialog ();
271 fbd.RootFolder = (Environment.SpecialFolder)12;