diff --git a/bazaar/GoogleTestUIExample/AppWindow.cpp b/bazaar/GoogleTestUIExample/AppWindow.cpp new file mode 100644 index 000000000..e0c7ded84 --- /dev/null +++ b/bazaar/GoogleTestUIExample/AppWindow.cpp @@ -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 << [=] { OnClick(); }; + Add(button.HSizePos(25, 25).VSizePos(50, 50)); +} + +void AppWindow::OnClick() +{ + if(PromptYesNo("Button was clicked. Do you want to quit?")) { + Break(); + } +} diff --git a/bazaar/GoogleTestUIExample/AppWindow.h b/bazaar/GoogleTestUIExample/AppWindow.h new file mode 100644 index 000000000..c9ff4788f --- /dev/null +++ b/bazaar/GoogleTestUIExample/AppWindow.h @@ -0,0 +1,21 @@ +#ifndef _Test_AppWindow_h_ +#define _Test_AppWindow_h_ + +#include + +namespace Upp +{ + class AppWindow final : public TopWindow + { + public: + AppWindow(); + + private: + void OnClick(); + + private: + Button button; + }; +} + +#endif diff --git a/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp b/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp new file mode 100644 index 000000000..f89f8627d --- /dev/null +++ b/bazaar/GoogleTestUIExample/GoogleTestUIExample.upp @@ -0,0 +1,17 @@ +uses + CtrlLib; + +uses(TESTING_TEST) plugin/gtest; + +file + AppWindow.h, + AppWindow.cpp, + main.cpp, + Tests readonly separator, + TestAppWindow.cpp, + TestMain.cpp; + +mainconfig + "" = "GUI", + "" = "GUI TESTING_TEST"; + diff --git a/bazaar/GoogleTestUIExample/TestAppWindow.cpp b/bazaar/GoogleTestUIExample/TestAppWindow.cpp new file mode 100644 index 000000000..2430c277c --- /dev/null +++ b/bazaar/GoogleTestUIExample/TestAppWindow.cpp @@ -0,0 +1,54 @@ +#ifdef flagTESTING_TEST + +#include "AppWindow.h" + +#include +#include + +using namespace Upp; + +class AppWindowTest : public testing::Test +{ +public: + AppWindowTest() + : windowRect(0, 0, 200, 200) + {} + + virtual void SetUp() override + { + window = MakeOne(); + } + +public: + One 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"; + EXPECT_TRUE(false); + } else { + auto img = StreamRaster::LoadFileAny(fileName); + EXPECT_EQ(img, id); + } +} + +#endif diff --git a/bazaar/GoogleTestUIExample/TestMain.cpp b/bazaar/GoogleTestUIExample/TestMain.cpp new file mode 100644 index 000000000..6e72601e8 --- /dev/null +++ b/bazaar/GoogleTestUIExample/TestMain.cpp @@ -0,0 +1,8 @@ +#ifdef flagTESTING_TEST + +#include +#include + +TEST_GUI_APP_MAIN {} + +#endif diff --git a/bazaar/GoogleTestUIExample/main.cpp b/bazaar/GoogleTestUIExample/main.cpp new file mode 100644 index 000000000..8e331f818 --- /dev/null +++ b/bazaar/GoogleTestUIExample/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "AppWindow.h" + +using namespace Upp; + +#ifndef flagTESTING_TEST + GUI_APP_MAIN + { + AppWindow().Run(); + } +#endif