public void TestEnable()
 {
     NativeButton button = new NativeButton(testDlg.IdentifyFromDialogId(1000));
     Assert.IsTrue(button.Enabled);
     NativeMethods.EnableWindow(button.Handle, false);
     Assert.IsFalse(button.Enabled);
 }
 public void TestVisible()
 {
     NativeButton button = new NativeButton(testDlg.IdentifyFromDialogId(1000));
     Assert.IsTrue(button.Visible);
     NativeMethods.ShowWindow(button.Handle, 0);
     Assert.IsFalse(button.Visible);
 }
 public void TestClickEvent()
 {
     //同期実行。BN_CLICKEDが発生していることを確認。
     NativeButton button = new NativeButton(testDlg.IdentifyFromDialogId(1000));
     Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
         delegate { button.EmulateClick(); },
         new CodeInfo(1000, NativeMethods.WM_COMMAND, BN_CLICKED)));
 }
 public void SetUp()
 {
     app = new WindowsAppFriend(Process.Start(TargetPath.NativeControls));
     EventChecker.Initialize(app);
     WindowControl main = WindowControl.FromZTop(app);
     NativeButton buttonTest = new NativeButton(main.IdentifyFromDialogId(1030));
     buttonTest.EmulateClick(new Async());
     testDlg = main.WaitForNextModal();
 }
 public void TestConstructor()
 {
     //WindowControlから作成。
     {
         NativeButton checkButton = new NativeButton(testDlg.IdentifyFromDialogId(1004));
         checkButton.EmulateCheck(CheckState.Checked);
         Assert.AreEqual(CheckState.Checked, checkButton.CheckState);
     }
     //ハンドルから作成。
     {
         NativeButton checkButton = new NativeButton(app, testDlg.IdentifyFromDialogId(1004).Handle);
         checkButton.EmulateCheck(CheckState.Unchecked);
         Assert.AreEqual(CheckState.Unchecked, checkButton.CheckState);
     }
 }
        static void OpenFile(WindowControl fileDialog, string path)
        {
            //ボタン取得
            var buttonOpen = new NativeButton(fileDialog.IdentifyFromWindowText("開く(&O)"));

            //コンボボックスは二つある場合がある。
            //下の方を採用。
            var comboBoxPathSrc = fileDialog.GetFromWindowClass("ComboBoxEx32").OrderBy(e =>
            {
                RECT rc;
                GetWindowRect(e.Handle, out rc);
                return rc.Top;
            }).Last();
            var comboBoxPath = new NativeComboBox(comboBoxPathSrc);

            //パスを設定
            comboBoxPath.EmulateChangeEditText(path);

            //開くボタンを押す
            buttonOpen.EmulateClick();
        }
コード例 #7
0
        public void Win32()
        {
            var app = new WindowsAppFriend(Process.Start(Path.GetFullPath("../../../MFCDlg.exe")));
            var dlg = WindowControl.IdentifyFromWindowText(app, "MFCDlg");

            //ダイアログID
            const int IDOK = 1;
            const int IDCANCEL = 2;
            const int IDC_EDIT_SAMPLE = 1000;
            var buttonOK = new NativeButton(dlg.IdentifyFromDialogId(IDOK));
            var buttonCancel = new NativeButton(dlg.IdentifyFromDialogId(IDCANCEL));
            var editSample = new NativeEdit(dlg.IdentifyFromDialogId(IDC_EDIT_SAMPLE));
            editSample.EmulateChangeText("abc");

            //WindowText
            buttonOK = new NativeButton(dlg.IdentifyFromWindowText("OK"));

            //Windowクラス
            editSample = new NativeEdit(dlg.IdentifyFromWindowClass("Edit"));

            Process.GetProcessById(app.ProcessId).Kill();
        }
 public void TestClickEventAsync()
 {
     NativeButton button = new NativeButton(testDlg.IdentifyFromDialogId(1001));
     Async async = new Async();
     button.EmulateClick(async);
     Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
 }
 public void TestCheckException()
 {
     //イベントのテストではないのでメッセージボックスが出ないようにする。
     app[typeof(EventChecker), "ClearAsyncMsgBox"](testDlg.Handle);
     try
     {
         NativeButton radio = new NativeButton(testDlg.IdentifyFromDialogId(1044));
         radio.EmulateCheck(CheckState.Unchecked);
         Assert.Fail();
     }
     catch (FriendlyOperationException e)
     {
         Assert.IsTrue(e.Message.IndexOf("指定のチェック状態はサポートされていません。" + Environment.NewLine +
                     "ラジオボタンの場合、チェックをOFFにすることはできません。" + Environment.NewLine +
                     "他のラジオボタンのチェックをONにすることで指定のラジオボタンをOFFにしてください。") != -1);
     }
     try
     {
         NativeButton checkButton = new NativeButton(testDlg.IdentifyFromDialogId(1005));
         checkButton.EmulateCheck(CheckState.Indeterminate);
         Assert.Fail();
     }
     catch (FriendlyOperationException e)
     {
         Assert.IsTrue(e.Message.IndexOf("指定のチェック状態はサポートされていません。" + Environment.NewLine +
                     "ラジオボタンの場合、チェックをOFFにすることはできません。" + Environment.NewLine +
                     "他のラジオボタンのチェックをONにすることで指定のラジオボタンをOFFにしてください。") != -1);
     }
 }
 public void TestRadioCheck()
 {
     NativeButton radio1 = new NativeButton(testDlg.IdentifyFromDialogId(1044));
     NativeButton radio2 = new NativeButton(testDlg.IdentifyFromDialogId(1045));
     radio1.EmulateCheck(CheckState.Checked);
     Assert.AreEqual(CheckState.Unchecked, radio2.CheckState);
     radio2.EmulateCheck(CheckState.Checked);
     Assert.AreEqual(CheckState.Unchecked, radio1.CheckState);
 }
 public void TestCheckEventAsync()
 {
     NativeButton checkButton = new NativeButton(testDlg.IdentifyFromDialogId(1005));
     Async async = new Async();
     checkButton.EmulateCheck(CheckState.Checked, async);
     Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
 }
        public void TestCheckEvent()
        {
            NativeButton checkButton = new NativeButton(testDlg.IdentifyFromDialogId(1004));

            //同期実行。BN_CLICKEDが発生していることを確認。
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { checkButton.EmulateCheck(CheckState.Checked); },
                new CodeInfo(1004, NativeMethods.WM_COMMAND, BN_CLICKED)));

            //同じ状態であれば、BN_CLICKEDが発生しないことを確認。
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
               delegate { checkButton.EmulateCheck(CheckState.Checked); }));
        }
        public void TestCheckStateValue()
        {
            //同期で実行
            NativeButton checkButton = new NativeButton(testDlg.IdentifyFromDialogId(1004));
            checkButton.EmulateCheck(CheckState.Checked);
            Assert.AreEqual(CheckState.Checked, checkButton.CheckState);
            checkButton.EmulateCheck(CheckState.Unchecked);
            Assert.AreEqual(CheckState.Unchecked, checkButton.CheckState);
            checkButton.EmulateCheck(CheckState.Indeterminate);
            Assert.AreEqual(CheckState.Indeterminate, checkButton.CheckState);

            //非同期メソッドでも同様の効果があることを確認。(内部的に間違ったメソッド呼び出しになっていないことの確認。)
            Async async = new Async();
            checkButton.EmulateCheck(CheckState.Unchecked, async);
            while (!async.IsCompleted)
            {
                Thread.Sleep(10);
            }
            Assert.AreEqual(CheckState.Unchecked, checkButton.CheckState);
        }