Bazzar: Google test example packages naming simplification.

git-svn-id: svn://ultimatepp.org/upp/trunk@14993 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
klugier 2020-09-06 11:32:01 +00:00
parent e39620c940
commit eee1bd4e46
13 changed files with 27 additions and 28 deletions

View file

@ -0,0 +1,19 @@
#include "AppWindow.h"
using namespace Upp;
AppWindow::AppWindow()
{
Title("App Window");
SetRect(0, 0, 200, 200);
button.SetLabel("Hello world!");
button << [=] { OnButtonClick(); };
Add(button.HSizePos(25, 25).VSizePos(50, 50));
}
void AppWindow::OnButtonClick()
{
if(PromptYesNo("Button was clicked. Do you want to quit?")) {
Break();
}
}

View file

@ -0,0 +1,21 @@
#ifndef _Test_AppWindow_h_
#define _Test_AppWindow_h_
#include <CtrlLib/CtrlLib.h>
namespace Upp
{
class AppWindow : public TopWindow
{
public:
Button button;
public:
AppWindow();
private:
virtual void OnButtonClick();
};
}
#endif

View file

@ -0,0 +1,19 @@
description "Automate UI testing with Google Test and Google Mock\377";
uses
CtrlLib;
uses(TESTING_GTEST_UI_EXAMPLE) plugin/gmock;
file
AppWindow.h,
AppWindow.cpp,
main.cpp,
Tests readonly separator,
TestAppWindow.cpp,
TestMain.cpp;
mainconfig
"" = "GUI",
"" = "GUI TESTING_GTEST_UI_EXAMPLE";

View file

@ -0,0 +1,72 @@
#ifdef flagTESTING_GTEST_UI_EXAMPLE
#include "AppWindow.h"
#include <plugin/gmock/gmock.h>
using namespace Upp;
class AppWindowMock final : public AppWindow {
public:
MOCK_METHOD(void, OnButtonClick, (), (override));
};
class AppWindowTest : public testing::Test
{
protected:
AppWindowTest()
: windowRect(0, 0, 200, 200)
{}
void SetUp() override
{
window = MakeOne<AppWindowMock>();
}
void clickButton()
{
EXPECT_CALL(*window.Get(), OnButtonClick());
window->button.LeftDown(Point(), 0);
window->button.LeftUp(Point(), 0);
}
protected:
One<AppWindowMock> window;
const Rect windowRect;
};
TEST_F(AppWindowTest, Initialization)
{
EXPECT_STREQ(L"App Window", window->GetTitle().ToStd().c_str());
EXPECT_FALSE(window->IsMaximized());
EXPECT_FALSE(window->IsMinimized());
EXPECT_EQ(windowRect, window->GetRect());
}
TEST_F(AppWindowTest, ApperanceTest)
{
const String fileName = "MyAppWindow.png";
ImageDraw id(window->GetRect().Size());
window->DrawCtrl(id);
PNGEncoder encoder;
if (!FileExists(fileName)) {
encoder.SaveFile(fileName, id);
Cout() << "Non referal window image. Creating and failing test..\n";
ASSERT_TRUE(false);
return;
}
auto img = StreamRaster::LoadFileAny(fileName);
EXPECT_EQ(img, id);
}
TEST_F(AppWindowTest, ButtonCanBeClick)
{
clickButton();
}
#endif

View file

@ -0,0 +1,8 @@
#ifdef flagTESTING_GTEST_UI_EXAMPLE
#include <CtrlLib/CtrlLib.h>
#include <plugin/gtest/gtest.h>
TEST_GUI_APP_MAIN {}
#endif

View file

@ -0,0 +1,12 @@
#include <CtrlLib/CtrlLib.h>
#include "AppWindow.h"
using namespace Upp;
#ifndef flagTESTING_GTEST_UI_EXAMPLE
GUI_APP_MAIN
{
AppWindow().Run();
}
#endif