From e39620c940fbb6a45076ee7a155063edcf07b5ce Mon Sep 17 00:00:00 2001 From: klugier Date: Sat, 5 Sep 2020 23:56:21 +0000 Subject: [PATCH] Bazaar: GoogleTestUIExample now shows how to simulate click and mock action. git-svn-id: svn://ultimatepp.org/upp/trunk@14992 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/GoogleTestUIExample/AppWindow.cpp | 4 +-- bazaar/GoogleTestUIExample/AppWindow.h | 12 ++++---- .../GoogleTestUIExample.upp | 2 +- bazaar/GoogleTestUIExample/TestAppWindow.cpp | 30 +++++++++++++++---- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/bazaar/GoogleTestUIExample/AppWindow.cpp b/bazaar/GoogleTestUIExample/AppWindow.cpp index e0c7ded84..85f61e4c2 100644 --- a/bazaar/GoogleTestUIExample/AppWindow.cpp +++ b/bazaar/GoogleTestUIExample/AppWindow.cpp @@ -7,11 +7,11 @@ AppWindow::AppWindow() Title("App Window"); SetRect(0, 0, 200, 200); button.SetLabel("Hello world!"); - button << [=] { OnClick(); }; + button << [=] { OnButtonClick(); }; Add(button.HSizePos(25, 25).VSizePos(50, 50)); } -void AppWindow::OnClick() +void AppWindow::OnButtonClick() { if(PromptYesNo("Button was clicked. Do you want to quit?")) { Break(); diff --git a/bazaar/GoogleTestUIExample/AppWindow.h b/bazaar/GoogleTestUIExample/AppWindow.h index c9ff4788f..462f1e068 100644 --- a/bazaar/GoogleTestUIExample/AppWindow.h +++ b/bazaar/GoogleTestUIExample/AppWindow.h @@ -5,16 +5,16 @@ namespace Upp { - class AppWindow final : public TopWindow + class AppWindow : public TopWindow { + public: + Button button; + public: AppWindow(); - - private: - void OnClick(); - private: - Button button; + protected: + virtual void OnButtonClick(); }; } diff --git a/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp b/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp index b954be1fa..9293d6fe3 100644 --- a/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp +++ b/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp @@ -3,7 +3,7 @@ description "Automate UI testing with Google Test\377"; uses CtrlLib; -uses(TESTING_GOOGLE_TEST_UI_EXAMPLE) plugin/gtest; +uses(TESTING_GOOGLE_TEST_UI_EXAMPLE) plugin/gmock; file AppWindow.h, diff --git a/bazaar/GoogleTestUIExample/TestAppWindow.cpp b/bazaar/GoogleTestUIExample/TestAppWindow.cpp index 2f3012a36..d55ec0127 100644 --- a/bazaar/GoogleTestUIExample/TestAppWindow.cpp +++ b/bazaar/GoogleTestUIExample/TestAppWindow.cpp @@ -2,25 +2,38 @@ #include "AppWindow.h" -#include +#include #include using namespace Upp; +class AppWindowMock final : public AppWindow { +public: + MOCK_METHOD(void, OnButtonClick, (), (override)); +}; + class AppWindowTest : public testing::Test { -public: +protected: AppWindowTest() : windowRect(0, 0, 200, 200) {} - virtual void SetUp() override + void SetUp() override { - window = MakeOne(); + window = MakeOne(); } -public: - One window; + void clickButton() + { + EXPECT_CALL(*window.Get(), OnButtonClick()); + + window->button.LeftDown(Point(), 0); + window->button.LeftUp(Point(), 0); + } + +protected: + One window; const Rect windowRect; }; @@ -52,4 +65,9 @@ TEST_F(AppWindowTest, ApperanceTest) EXPECT_EQ(img, id); } +TEST_F(AppWindowTest, ButtonCanBeClick) +{ + clickButton(); +} + #endif