mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-30 14:22:28 -06:00
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
This commit is contained in:
parent
5f3d6509e1
commit
e39620c940
4 changed files with 33 additions and 15 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -2,25 +2,38 @@
|
|||
|
||||
#include "AppWindow.h"
|
||||
|
||||
#include <plugin/gtest/gtest.h>
|
||||
#include <plugin/gmock/gmock.h>
|
||||
#include <memory>
|
||||
|
||||
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<AppWindow>();
|
||||
window = MakeOne<AppWindowMock>();
|
||||
}
|
||||
|
||||
public:
|
||||
One<AppWindow> window;
|
||||
void clickButton()
|
||||
{
|
||||
EXPECT_CALL(*window.Get(), OnButtonClick());
|
||||
|
||||
window->button.LeftDown(Point(), 0);
|
||||
window->button.LeftUp(Point(), 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
One<AppWindowMock> window;
|
||||
const Rect windowRect;
|
||||
};
|
||||
|
||||
|
|
@ -52,4 +65,9 @@ TEST_F(AppWindowTest, ApperanceTest)
|
|||
EXPECT_EQ(img, id);
|
||||
}
|
||||
|
||||
TEST_F(AppWindowTest, ButtonCanBeClick)
|
||||
{
|
||||
clickButton();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue