2015-08-12 04:45:37 -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-12 04:45:37 -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
|
|
|
#include "Tests.hpp"
|
2015-08-12 04:45:37 -07:00
|
|
|
#include <TGUI/Widgets/ChatBox.hpp>
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
TEST_CASE("[ChatBox]")
|
|
|
|
{
|
2016-09-14 11:11:20 -07:00
|
|
|
tgui::ChatBox::Ptr chatBox = tgui::ChatBox::create();
|
2017-02-09 15:35:24 -08:00
|
|
|
chatBox->getRenderer()->setFont("resources/DejaVuSans.ttf");
|
2015-08-12 04:45:37 -07:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("WidgetType")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
REQUIRE(chatBox->getWidgetType() == "ChatBox");
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Position and Size")
|
|
|
|
{
|
|
|
|
chatBox->setPosition(40, 30);
|
|
|
|
chatBox->setSize(150, 100);
|
|
|
|
chatBox->getRenderer()->setBorders(2);
|
|
|
|
|
|
|
|
REQUIRE(chatBox->getPosition() == sf::Vector2f(40, 30));
|
|
|
|
REQUIRE(chatBox->getSize() == sf::Vector2f(150, 100));
|
|
|
|
REQUIRE(chatBox->getFullSize() == chatBox->getSize());
|
|
|
|
REQUIRE(chatBox->getWidgetOffset() == sf::Vector2f(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Adding lines")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
chatBox->setTextColor(sf::Color::Black);
|
2015-08-12 04:45:37 -07:00
|
|
|
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 0);
|
|
|
|
chatBox->addLine("Line 1");
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 1);
|
2018-01-14 05:16:15 -08:00
|
|
|
chatBox->addLine("Line 2", sf::Color::Green);
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 2);
|
2015-08-12 04:45:37 -07:00
|
|
|
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 1");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 2");
|
2016-09-14 11:11:20 -07:00
|
|
|
|
2015-12-05 10:46:44 -08:00
|
|
|
REQUIRE(chatBox->getLineColor(0) == sf::Color::Black);
|
2018-01-14 05:16:15 -08:00
|
|
|
REQUIRE(chatBox->getLineColor(1) == sf::Color::Green);
|
2015-12-05 10:46:44 -08:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Removing lines")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
REQUIRE(!chatBox->removeLine(0));
|
|
|
|
chatBox->addLine("Line 1");
|
|
|
|
chatBox->addLine("Line 2");
|
|
|
|
chatBox->addLine("Line 3");
|
2016-01-29 06:06:54 -08:00
|
|
|
|
2015-12-05 10:46:44 -08:00
|
|
|
REQUIRE(!chatBox->removeLine(5));
|
2016-01-29 06:06:54 -08:00
|
|
|
REQUIRE(chatBox->getLineAmount() == 3);
|
2015-12-05 10:46:44 -08:00
|
|
|
|
|
|
|
REQUIRE(chatBox->removeLine(1));
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 2);
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 1");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 3");
|
|
|
|
|
|
|
|
chatBox->removeAllLines();
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 0);
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Line limit")
|
|
|
|
{
|
2016-01-29 06:06:54 -08:00
|
|
|
REQUIRE(chatBox->getLineLimit() == 0);
|
2015-12-05 10:46:44 -08:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Oldest on top")
|
|
|
|
{
|
2016-01-29 06:06:54 -08:00
|
|
|
chatBox->addLine("Line 1");
|
|
|
|
chatBox->addLine("Line 2");
|
|
|
|
chatBox->addLine("Line 3");
|
|
|
|
|
|
|
|
chatBox->setLineLimit(2);
|
|
|
|
REQUIRE(chatBox->getLineLimit() == 2);
|
|
|
|
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 2);
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 2");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 3");
|
2015-12-05 10:46:44 -08:00
|
|
|
|
2016-01-29 06:06:54 -08:00
|
|
|
chatBox->addLine("Line 4");
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 3");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 4");
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Oldest at the bottom")
|
|
|
|
{
|
2016-01-29 06:06:54 -08:00
|
|
|
chatBox->setNewLinesBelowOthers(false);
|
|
|
|
|
|
|
|
chatBox->addLine("Line 1");
|
|
|
|
chatBox->addLine("Line 2");
|
|
|
|
chatBox->addLine("Line 3");
|
|
|
|
|
|
|
|
chatBox->setLineLimit(2);
|
|
|
|
REQUIRE(chatBox->getLineLimit() == 2);
|
|
|
|
|
|
|
|
REQUIRE(chatBox->getLineAmount() == 2);
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 3");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 2");
|
|
|
|
|
|
|
|
chatBox->addLine("Line 4");
|
|
|
|
REQUIRE(chatBox->getLine(0) == "Line 4");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "Line 3");
|
|
|
|
}
|
2015-12-05 10:46:44 -08:00
|
|
|
}
|
|
|
|
|
2018-01-14 05:16:15 -08:00
|
|
|
SECTION("Text size")
|
2016-08-30 05:55:23 -07:00
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
chatBox->setTextSize(30);
|
|
|
|
REQUIRE(chatBox->getTextSize() == 30);
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Default text color")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
chatBox->setTextColor(sf::Color::Red);
|
|
|
|
REQUIRE(chatBox->getTextColor() == sf::Color::Red);
|
|
|
|
|
|
|
|
chatBox->addLine("Text");
|
|
|
|
REQUIRE(chatBox->getLineColor(0) == sf::Color::Red);
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Get unexisting line")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
chatBox->setTextColor(sf::Color::Yellow);
|
|
|
|
|
2018-01-14 05:16:15 -08:00
|
|
|
chatBox->addLine("Text", sf::Color::Blue);
|
2015-12-05 10:46:44 -08:00
|
|
|
REQUIRE(chatBox->getLine(1) == "");
|
2018-01-14 05:16:15 -08:00
|
|
|
REQUIRE(chatBox->getLineColor(1) == sf::Color::Yellow);
|
2015-12-05 10:46:44 -08:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Lines start from top or bottom")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
REQUIRE(!chatBox->getLinesStartFromTop());
|
|
|
|
chatBox->setLinesStartFromTop(true);
|
|
|
|
REQUIRE(chatBox->getLinesStartFromTop());
|
|
|
|
chatBox->setLinesStartFromTop(false);
|
|
|
|
REQUIRE(!chatBox->getLinesStartFromTop());
|
|
|
|
}
|
2015-08-12 04:45:37 -07:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Events / Signals")
|
|
|
|
{
|
|
|
|
SECTION("Widget")
|
|
|
|
{
|
|
|
|
testWidgetSignals(chatBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
testWidgetRenderer(chatBox->getRenderer());
|
|
|
|
SECTION("Renderer")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
auto renderer = chatBox->getRenderer();
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("colored")
|
|
|
|
{
|
2016-09-11 16:09:13 -07:00
|
|
|
tgui::ScrollbarRenderer scrollbarRenderer;
|
|
|
|
scrollbarRenderer.setTrackColor(sf::Color::Red);
|
|
|
|
scrollbarRenderer.setThumbColor(sf::Color::Blue);
|
2016-08-30 05:55:23 -07:00
|
|
|
|
|
|
|
SECTION("set serialized property")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BackgroundColor", "rgb(10, 20, 30)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BorderColor", "rgb(40, 50, 60)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Borders", "(1, 2, 3, 4)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Padding", "(5, 6, 7, 8)"));
|
2016-08-30 05:55:23 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Scrollbar", "{ TrackColor = Red; ThumbColor = Blue; }"));
|
2018-05-14 13:56:09 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("ScrollbarWidth", "15"));
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
2016-09-14 11:11:20 -07:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("set object property")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BackgroundColor", sf::Color{10, 20, 30}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BorderColor", sf::Color{40, 50, 60}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Borders", tgui::Borders{1, 2, 3, 4}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Padding", tgui::Borders{5, 6, 7, 8}));
|
2016-09-11 16:09:13 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Scrollbar", scrollbarRenderer.getData()));
|
2018-05-14 13:56:09 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("ScrollbarWidth", 15));
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("functions")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
renderer->setBackgroundColor({10, 20, 30});
|
|
|
|
renderer->setBorderColor({40, 50, 60});
|
|
|
|
renderer->setBorders({1, 2, 3, 4});
|
|
|
|
renderer->setPadding({5, 6, 7, 8});
|
2016-09-11 16:09:13 -07:00
|
|
|
renderer->setScrollbar(scrollbarRenderer.getData());
|
2018-05-14 13:56:09 -07:00
|
|
|
renderer->setScrollbarWidth(15);
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
REQUIRE(renderer->getProperty("BackgroundColor").getColor() == sf::Color(10, 20, 30));
|
|
|
|
REQUIRE(renderer->getProperty("BorderColor").getColor() == sf::Color(40, 50, 60));
|
2016-06-30 07:12:43 -07:00
|
|
|
REQUIRE(renderer->getProperty("Borders").getOutline() == tgui::Borders(1, 2, 3, 4));
|
|
|
|
REQUIRE(renderer->getProperty("Padding").getOutline() == tgui::Borders(5, 6, 7, 8));
|
2018-05-14 13:56:09 -07:00
|
|
|
REQUIRE(renderer->getProperty("ScrollbarWidth").getNumber() == 15);
|
2016-08-30 05:55:23 -07:00
|
|
|
|
2016-09-11 16:09:13 -07:00
|
|
|
REQUIRE(renderer->getScrollbar()->propertyValuePairs.size() == 2);
|
|
|
|
REQUIRE(renderer->getScrollbar()->propertyValuePairs["trackcolor"].getColor() == sf::Color::Red);
|
|
|
|
REQUIRE(renderer->getScrollbar()->propertyValuePairs["thumbcolor"].getColor() == sf::Color::Blue);
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("textured")
|
|
|
|
{
|
2015-08-12 04:45:37 -07:00
|
|
|
tgui::Texture textureBackground("resources/Black.png", {0, 154, 48, 48}, {16, 16, 16, 16});
|
|
|
|
|
|
|
|
SECTION("set serialized property") {
|
2016-08-30 05:55:23 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextureBackground", tgui::Serializer::serialize(textureBackground)));
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("set object property") {
|
2016-08-30 05:55:23 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextureBackground", textureBackground));
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("functions") {
|
2016-08-30 05:55:23 -07:00
|
|
|
renderer->setTextureBackground(textureBackground);
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
|
2016-10-16 09:09:36 -07:00
|
|
|
REQUIRE(renderer->getProperty("TextureBackground").getTexture().getData() != nullptr);
|
2015-08-12 04:45:37 -07:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
REQUIRE(renderer->getTextureBackground().getData() == textureBackground.getData());
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
SECTION("Saving and loading from file")
|
|
|
|
{
|
2015-12-05 10:46:44 -08:00
|
|
|
chatBox->setTextColor(sf::Color::White);
|
|
|
|
chatBox->setTextSize(34);
|
2016-01-29 06:06:54 -08:00
|
|
|
chatBox->setLineLimit(5);
|
2016-01-29 04:39:47 -08:00
|
|
|
chatBox->setLinesStartFromTop(true);
|
|
|
|
chatBox->setNewLinesBelowOthers(false);
|
|
|
|
chatBox->addLine("L2");
|
2018-01-14 05:16:15 -08:00
|
|
|
chatBox->addLine("L4", sf::Color::Magenta);
|
|
|
|
chatBox->addLine("L3");
|
|
|
|
chatBox->addLine("L1", sf::Color::Cyan);
|
2015-12-05 10:46:44 -08:00
|
|
|
|
2016-08-30 05:55:23 -07:00
|
|
|
testSavingWidget("ChatBox", chatBox);
|
2015-12-05 10:46:44 -08:00
|
|
|
|
|
|
|
// Make sure that the lines are still in the correct order
|
2016-01-29 04:39:47 -08:00
|
|
|
REQUIRE(chatBox->getLine(0) == "L1");
|
|
|
|
REQUIRE(chatBox->getLine(1) == "L3");
|
|
|
|
REQUIRE(chatBox->getLine(2) == "L4");
|
|
|
|
REQUIRE(chatBox->getLine(3) == "L2");
|
2015-12-05 10:46:44 -08:00
|
|
|
}
|
2015-08-12 04:45:37 -07:00
|
|
|
}
|