1 /* 2 * "GEDKeeper", the personal genealogical database editor. 3 * Copyright (C) 2009-2019 by Sergey V. Zhdanovskih. 4 * 5 * This file is part of "GEDKeeper". 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #if !MONO 22 23 using System; 24 using System.Windows.Forms; 25 using NUnit.Extensions.Forms; 26 using GKTests.ControlTesters; 27 28 namespace GKTests 29 { 30 /// <summary> 31 /// 32 /// </summary> 33 public abstract class CustomWindowTest : NUnitFormTest 34 { 35 public override bool UseHidden 36 { 37 get { return true; } 38 } 39 GetActiveForm(string formName)40 public static Form GetActiveForm(string formName) 41 { 42 var tester = new FormTester(formName); 43 return (tester == null) ? null : (Form)tester.TheObject; 44 } 45 46 #region Control Actions 47 ClickButton(string name, Form form)48 public static void ClickButton(string name, Form form) 49 { 50 var tsBtn = new ButtonTester(name, form); 51 if (tsBtn.Count > 1) { 52 // FIXME: Find out why sometimes the search returns 53 // two components where there is only one (MediaViewerWinTests) 54 tsBtn[0].FireEvent("Click"); 55 } else { 56 tsBtn.FireEvent("Click"); 57 } 58 } 59 ClickButton(string name, string form)60 public static void ClickButton(string name, string form) 61 { 62 var tsBtn = new ButtonTester(name, form); 63 if (tsBtn.Count > 1) { 64 // FIXME: Find out why sometimes the search returns 65 // two components where there is only one (MediaViewerWinTests) 66 tsBtn[0].FireEvent("Click"); 67 } else { 68 tsBtn.FireEvent("Click"); 69 } 70 } 71 ClickToolStripButton(string name, Form form)72 public static void ClickToolStripButton(string name, Form form) 73 { 74 var tsBtn = new ToolStripButtonTester(name, form); 75 if (tsBtn.Count > 1) { 76 // FIXME: Find out why sometimes the search returns 77 // two components where there is only one (MediaViewerWinTests) 78 tsBtn[0].FireEvent("Click"); 79 } else { 80 tsBtn.FireEvent("Click"); 81 } 82 } 83 ClickToolStripMenuItem(string name, Form form)84 public static void ClickToolStripMenuItem(string name, Form form) 85 { 86 var tsMenuItem = new ToolStripMenuItemTester(name, form); 87 tsMenuItem.Click(); 88 } 89 ClickRadioButton(string name, Form form)90 public static void ClickRadioButton(string name, Form form) 91 { 92 var radBtn = new RadioButtonTester(name, form); 93 radBtn.Click(); 94 } 95 SelectTab(string name, Form form, int value)96 public static void SelectTab(string name, Form form, int value) 97 { 98 var tabCtl = new TabControlTester(name, form); 99 tabCtl.SelectTab(value); 100 } 101 SelectCombo(string name, Form form, int value)102 public static void SelectCombo(string name, Form form, int value) 103 { 104 var combo = new ComboBoxTester(name, form); 105 combo.Select(value); 106 } 107 EnterCombo(string name, Form form, string value)108 public static void EnterCombo(string name, Form form, string value) 109 { 110 var combo = new ComboBoxTester(name, form); 111 combo.Enter(value); 112 } 113 EnterText(string name, Form form, string value)114 public static void EnterText(string name, Form form, string value) 115 { 116 var textBox = new TextBoxTester(name, form); 117 textBox.Enter(value); 118 } 119 EnterMaskedText(string name, Form form, string value)120 public static void EnterMaskedText(string name, Form form, string value) 121 { 122 var textBox = new MaskedTextBoxTester(name, form); 123 textBox.Enter(value); 124 } 125 SelectSheetListItem(string name, Form form, int value)126 public static void SelectSheetListItem(string name, Form form, int value) 127 { 128 var sheetTester = new GKSheetListTester(name, form); 129 sheetTester.Properties.SelectItem(value); 130 } 131 EnterNumeric(string name, Form form, int value)132 public static void EnterNumeric(string name, Form form, int value) 133 { 134 var nud = new NumericUpDownTester(name, form); 135 nud.EnterValue(value); 136 } 137 CheckBox(string name, Form form, bool value)138 public static void CheckBox(string name, Form form, bool value) 139 { 140 var chk = new CheckBoxTester(name, form); 141 chk.Properties.Checked = value; 142 } 143 KeyDownForm(string formName, Keys keyData)144 public static void KeyDownForm(string formName, Keys keyData) 145 { 146 var formTester = new FormTester(formName); 147 formTester.FireEvent("KeyDown", new KeyEventArgs(keyData)); 148 } 149 150 #endregion 151 152 #region Dialogs Handlers 153 MessageBox_YesHandler(string name, IntPtr ptr, Form form)154 public static void MessageBox_YesHandler(string name, IntPtr ptr, Form form) 155 { 156 MessageBoxTester messageBox = new MessageBoxTester(ptr); 157 messageBox.SendCommand(MessageBoxTester.Command.Yes); 158 } 159 MessageBox_NoHandler(string name, IntPtr ptr, Form form)160 public static void MessageBox_NoHandler(string name, IntPtr ptr, Form form) 161 { 162 MessageBoxTester messageBox = new MessageBoxTester(ptr); 163 messageBox.SendCommand(MessageBoxTester.Command.No); 164 } 165 MessageBox_OkHandler(string name, IntPtr ptr, Form form)166 public static void MessageBox_OkHandler(string name, IntPtr ptr, Form form) 167 { 168 MessageBoxTester messageBox = new MessageBoxTester(ptr); 169 messageBox.SendCommand(MessageBoxTester.Command.OK); 170 } 171 MessageBox_CancelHandler(string name, IntPtr ptr, Form form)172 public static void MessageBox_CancelHandler(string name, IntPtr ptr, Form form) 173 { 174 MessageBoxTester messageBox = new MessageBoxTester(ptr); 175 messageBox.SendCommand(MessageBoxTester.Command.Cancel); 176 } 177 PrintDialog_Handler(string name, IntPtr ptr, Form form)178 public static void PrintDialog_Handler(string name, IntPtr ptr, Form form) 179 { 180 form.Close(); 181 } 182 PrintPreviewDialog_Handler(string name, IntPtr ptr, Form form)183 public static void PrintPreviewDialog_Handler(string name, IntPtr ptr, Form form) 184 { 185 form.Refresh(); 186 form.Close(); 187 } 188 OpenFile_Cancel_Handler(string name, IntPtr hWnd, Form form)189 public static void OpenFile_Cancel_Handler(string name, IntPtr hWnd, Form form) 190 { 191 var openDlg = new OpenFileDialogTester(hWnd); 192 openDlg.ClickCancel(); 193 } 194 SaveFile_Cancel_Handler(string name, IntPtr hWnd, Form form)195 public static void SaveFile_Cancel_Handler(string name, IntPtr hWnd, Form form) 196 { 197 var saveDlg = new SaveFileDialogTester(hWnd); 198 saveDlg.ClickCancel(); 199 } 200 PrepareFileSave(string fileName, IntPtr hWnd)201 public static void PrepareFileSave(string fileName, IntPtr hWnd) 202 { 203 fileName = TestUtils.GetTempFilePath(fileName); 204 205 var saveDlg = new SaveFileDialogTester(hWnd); 206 saveDlg.SaveFile(fileName); 207 saveDlg.SaveFile(); 208 } 209 Dialog_Cancel_Handler(string name, IntPtr ptr, Form form)210 public static void Dialog_Cancel_Handler(string name, IntPtr ptr, Form form) 211 { 212 ClickButton("btnCancel", form); 213 } 214 215 #endregion 216 217 #region InputBox Handlers 218 InputBox_Add_Handler(string name, IntPtr ptr, Form form)219 public static void InputBox_Add_Handler(string name, IntPtr ptr, Form form) 220 { 221 EnterText("txtValue", form, "sample add"); 222 ClickButton("btnAccept", form); 223 } 224 InputBox_Edit_Handler(string name, IntPtr ptr, Form form)225 public static void InputBox_Edit_Handler(string name, IntPtr ptr, Form form) 226 { 227 EnterText("txtValue", form, "sample edit"); 228 ClickButton("btnAccept", form); 229 } 230 231 #endregion 232 233 #region FileSave Handlers 234 SaveFileGED_Handler(string name, IntPtr hWnd, Form form)235 public static void SaveFileGED_Handler(string name, IntPtr hWnd, Form form) 236 { 237 PrepareFileSave("test.ged", hWnd); 238 } 239 SaveFileJPG_Handler(string name, IntPtr hWnd, Form form)240 public static void SaveFileJPG_Handler(string name, IntPtr hWnd, Form form) 241 { 242 PrepareFileSave("test.jpg", hWnd); 243 } 244 SaveFileEMF_Handler(string name, IntPtr hWnd, Form form)245 public static void SaveFileEMF_Handler(string name, IntPtr hWnd, Form form) 246 { 247 PrepareFileSave("test.emf", hWnd); 248 } 249 SaveFileSVG_Handler(string name, IntPtr hWnd, Form form)250 public static void SaveFileSVG_Handler(string name, IntPtr hWnd, Form form) 251 { 252 PrepareFileSave("test.svg", hWnd); 253 } 254 SaveFileXLS_Handler(string name, IntPtr hWnd, Form form)255 public static void SaveFileXLS_Handler(string name, IntPtr hWnd, Form form) 256 { 257 PrepareFileSave("test.xls", hWnd); 258 } 259 SaveFilePDF_Handler(string name, IntPtr hWnd, Form form)260 public static void SaveFilePDF_Handler(string name, IntPtr hWnd, Form form) 261 { 262 PrepareFileSave("test.pdf", hWnd); 263 } 264 SaveFileHTML_Handler(string name, IntPtr hWnd, Form form)265 public static void SaveFileHTML_Handler(string name, IntPtr hWnd, Form form) 266 { 267 PrepareFileSave("test.html", hWnd); 268 } 269 SaveFileRTF_Handler(string name, IntPtr hWnd, Form form)270 public static void SaveFileRTF_Handler(string name, IntPtr hWnd, Form form) 271 { 272 PrepareFileSave("test.rtf", hWnd); 273 } 274 275 #endregion 276 277 protected static NUnitFormTest fFormTest; 278 SetModalFormHandler(NUnitFormTest formTest, ModalFormHandler modalFormHandler)279 public static void SetModalFormHandler(NUnitFormTest formTest, ModalFormHandler modalFormHandler) 280 { 281 fFormTest = formTest; 282 fFormTest.ModalFormHandler = modalFormHandler; 283 } 284 } 285 } 286 287 #endif 288