2015-08-07 05:03:22 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2016-07-10 15:01:18 -07:00
|
|
|
// TGUI - Texus' Graphical User Interface
|
2018-03-22 11:57:45 -07:00
|
|
|
// Copyright (C) 2012-2018 Bruno Van de Velde (vdv_b@tgui.eu)
|
2015-08-07 05:03:22 -07:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
// subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented;
|
|
|
|
// you must not claim that you wrote the original software.
|
|
|
|
// If you use this software in a product, an acknowledgment
|
|
|
|
// in the product documentation would be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such,
|
|
|
|
// and must not be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-11-01 05:19:47 -07:00
|
|
|
|
|
|
|
#ifndef TGUI_TESTS_HPP
|
|
|
|
#define TGUI_TESTS_HPP
|
|
|
|
|
2017-11-01 09:10:50 -07:00
|
|
|
#include <SFML/Config.hpp>
|
|
|
|
|
|
|
|
#ifdef SFML_SYSTEM_WINDOWS
|
|
|
|
#define NOMB
|
|
|
|
#define NOMINMAX
|
|
|
|
#define VC_EXTRALEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2015-08-07 05:03:22 -07:00
|
|
|
#include "catch.hpp"
|
2017-02-09 15:35:24 -08:00
|
|
|
#include <SFML/Graphics/RenderTexture.hpp>
|
|
|
|
#include <TGUI/Gui.hpp>
|
2015-08-07 05:03:22 -07:00
|
|
|
#include <TGUI/Container.hpp>
|
2016-06-30 07:12:43 -07:00
|
|
|
#include <TGUI/Widgets/ClickableWidget.hpp>
|
2015-08-07 05:03:22 -07:00
|
|
|
#include <TGUI/Loading/Theme.hpp>
|
|
|
|
#include <TGUI/Loading/Serializer.hpp>
|
2017-11-01 05:19:47 -07:00
|
|
|
#include <TGUI/SignalImpl.hpp>
|
2015-08-07 05:03:22 -07:00
|
|
|
|
2017-02-09 15:35:24 -08:00
|
|
|
#define TEST_DRAW_INIT(width, height, widget) \
|
|
|
|
sf::RenderTexture target; \
|
|
|
|
target.create(width, height); \
|
|
|
|
tgui::Gui gui{target}; \
|
|
|
|
gui.add(widget);
|
|
|
|
|
2017-02-09 17:14:28 -08:00
|
|
|
#ifdef TGUI_SKIP_DRAW_TESTS
|
|
|
|
#define TEST_DRAW(filename) \
|
|
|
|
target.clear({25, 130, 10}); \
|
|
|
|
gui.draw(); \
|
|
|
|
target.display(); \
|
|
|
|
target.getTexture().copyToImage().saveToFile(filename);
|
|
|
|
#else
|
|
|
|
#define TEST_DRAW(filename) \
|
|
|
|
target.clear({25, 130, 10}); \
|
|
|
|
gui.draw(); \
|
|
|
|
target.display(); \
|
|
|
|
target.getTexture().copyToImage().saveToFile(filename); \
|
|
|
|
REQUIRE(compareFiles(filename, "expected/" filename));
|
|
|
|
#endif
|
2017-02-09 15:35:24 -08:00
|
|
|
|
2016-06-30 07:12:43 -07:00
|
|
|
static const sf::Time DOUBLE_CLICK_TIMEOUT = sf::milliseconds(500);
|
2016-03-10 11:42:19 -08:00
|
|
|
|
2015-08-07 05:03:22 -07:00
|
|
|
bool compareFiles(const std::string& leftFileName, const std::string& rightFileName);
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-06-30 07:12:43 -07:00
|
|
|
void mouseCallback(unsigned int& count, sf::Vector2f pos);
|
|
|
|
void genericCallback(unsigned int& count);
|
|
|
|
|
|
|
|
void testWidgetSignals(tgui::Widget::Ptr widget);
|
|
|
|
void testClickableWidgetSignals(tgui::ClickableWidget::Ptr widget);
|
|
|
|
|
2016-07-17 10:33:14 -07:00
|
|
|
void testWidgetRenderer(tgui::WidgetRenderer* renderer);
|
|
|
|
|
2016-03-09 23:14:37 -08:00
|
|
|
template <typename WidgetType>
|
2016-07-28 07:06:13 -07:00
|
|
|
void testSavingWidget(std::string name, std::shared_ptr<WidgetType> widget, bool loadFromTheme = true)
|
2016-03-09 23:14:37 -08:00
|
|
|
{
|
2016-07-28 07:06:13 -07:00
|
|
|
if (loadFromTheme)
|
|
|
|
{
|
|
|
|
tgui::Theme theme{"resources/Black.txt"};
|
|
|
|
widget->setRenderer(theme.getRenderer(name));
|
2017-02-09 15:35:24 -08:00
|
|
|
widget->getRenderer()->setFont("resources/DejaVuSans.ttf");
|
2016-07-28 07:06:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
auto parent = std::make_shared<tgui::GuiContainer>();
|
|
|
|
parent->add(widget);
|
|
|
|
|
|
|
|
REQUIRE_NOTHROW(parent->saveWidgetsToFile(name + "WidgetFile1.txt"));
|
2016-03-10 11:42:19 -08:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Copying widget before saving")
|
2016-07-28 07:06:13 -07:00
|
|
|
{
|
|
|
|
// Copy constructor
|
|
|
|
WidgetType temp1(*widget);
|
|
|
|
|
|
|
|
// Assignment operator
|
|
|
|
WidgetType temp2;
|
|
|
|
temp2 = temp1;
|
2016-08-30 05:55:23 -07:00
|
|
|
temp2 = temp2;
|
2016-07-28 07:06:13 -07:00
|
|
|
|
|
|
|
// Move constructor
|
|
|
|
WidgetType temp3 = std::move(temp2);
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
// Move assignment operator
|
|
|
|
WidgetType temp4;
|
|
|
|
temp4 = std::move(temp3);
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
// copy function
|
|
|
|
std::shared_ptr<WidgetType> temp5 = std::make_shared<WidgetType>(temp4);
|
|
|
|
tgui::Widget::Ptr temp6 = WidgetType::copy(temp5);
|
|
|
|
REQUIRE(temp6 != nullptr);
|
|
|
|
REQUIRE(WidgetType::copy(nullptr) == nullptr);
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
// clone function
|
|
|
|
tgui::Widget::Ptr temp7 = temp6->clone();
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
parent = std::make_shared<tgui::GuiContainer>();
|
|
|
|
parent->add(temp7);
|
2016-03-09 23:14:37 -08:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
REQUIRE_NOTHROW(parent->saveWidgetsToFile(name + "WidgetFile2.txt"));
|
|
|
|
REQUIRE(compareFiles(name + "WidgetFile1.txt", name + "WidgetFile2.txt"));
|
|
|
|
}
|
2016-09-01 16:47:03 -07:00
|
|
|
|
|
|
|
SECTION("Saving again after loading")
|
|
|
|
{
|
|
|
|
parent = std::make_shared<tgui::GuiContainer>();
|
|
|
|
REQUIRE_NOTHROW(parent->loadWidgetsFromFile(name + "WidgetFile1.txt"));
|
|
|
|
|
2017-07-25 09:54:59 -07:00
|
|
|
REQUIRE_NOTHROW(parent->saveWidgetsToFile(name + "WidgetFile3.txt"));
|
|
|
|
REQUIRE(compareFiles(name + "WidgetFile1.txt", name + "WidgetFile3.txt"));
|
2016-09-01 16:47:03 -07:00
|
|
|
}
|
2016-03-09 23:14:37 -08:00
|
|
|
}
|
2017-11-01 05:19:47 -07:00
|
|
|
|
|
|
|
#endif // TGUI_TESTS_HPP
|