public void TestConstructor()
 {
     //WindowControlから作成。
     {
         NativeEdit edit = new NativeEdit(testDlg.IdentifyFromDialogId(1020));
         edit.EmulateChangeText("a");
         Assert.AreEqual("a", edit.Text);
     }
     //ハンドルから作成。
     {
         NativeEdit edit = new NativeEdit(app, testDlg.IdentifyFromDialogId(1020).Handle);
         edit.EmulateChangeText("b");
         Assert.AreEqual("b", edit.Text);
     }
 }
コード例 #2
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 TestEmulateChangeSelectionEventAsync()
        {
            //文字列設定 テスト対象ではないがここでもメッセージボックスが表示される。
            NativeEdit rich = new NativeEdit(testDlg.IdentifyFromDialogId(1040));
            Async async = new Async();
            rich.EmulateChangeText("abcdef", async);
            Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));

            //EmulateChangeSelectionの非同期確認。
            async = new Async();
            rich.EmulateChangeSelection(1, 1, async);
            Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
        }
        public void TestEmulateChangeTextEventAsync()
        {
            NativeEdit edit = new NativeEdit(testDlg.IdentifyFromDialogId(1022));
            NativeEdit rich = new NativeEdit(testDlg.IdentifyFromDialogId(1040));

            Async async = new Async();
            edit.EmulateChangeText("abcdef", async);
            Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));

            async = new Async();
            rich.EmulateChangeText("abcdef", async);
            Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
        }
        public void TestEmulateChangeSelectionEvent()
        {
            //Edit 何もイベントは発生しない。
            NativeEdit edit = new NativeEdit(testDlg.IdentifyFromDialogId(1020));
            edit.EmulateChangeText("123");
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { edit.EmulateChangeSelection(1, 2); }));

            //RitchEdit EN_SELCHANGEが発生することを確認。
            NativeEdit rich = new NativeEdit(testDlg.IdentifyFromDialogId(1038));
            rich.EmulateChangeText("123");
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { rich.EmulateChangeSelection(1, 2); },
                //無視
                new CodeInfo[] {new CodeInfo(1038, NativeMethods.WM_COMMAND, EN_UPDATE)},
                //期待値
                new CodeInfo(1038, NativeMethods.WM_NOTIFY, EN_SELCHANGE)
                ));
        }
        public void TestEmulateChangeTextEvent()
        {
            //Edit。
            NativeEdit edit = new NativeEdit(testDlg.IdentifyFromDialogId(1020));
            edit.EmulateChangeText(string.Empty);
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { edit.EmulateChangeText("a"); },
                new CodeInfo(1020, NativeMethods.WM_COMMAND, EN_UPDATE),
                new CodeInfo(1020, NativeMethods.WM_COMMAND, EN_CHANGE)
                ));

            //RitchEdit イベント発生の順番がEditと異なる。
            NativeEdit rich = new NativeEdit(testDlg.IdentifyFromDialogId(1038));
            rich.EmulateChangeText(string.Empty);
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { rich.EmulateChangeText("a"); },
                new CodeInfo(1038, NativeMethods.WM_COMMAND, EN_CHANGE),
                new CodeInfo(1038, NativeMethods.WM_COMMAND, EN_UPDATE)
                ));
        }