Added more tests for ChatBox
parent
59ace50319
commit
fd36c951f7
|
@ -35,12 +35,12 @@ TEST_CASE("[ChatBox]") {
|
|||
}
|
||||
|
||||
SECTION("adding lines") {
|
||||
auto font = std::make_shared<sf::Font>();
|
||||
font->loadFromFile("resources/DroidSansArmenian.ttf");
|
||||
std::shared_ptr<sf::Font> font1 = tgui::Font{"resources/DroidSansArmenian.ttf"}.getFont();
|
||||
std::shared_ptr<sf::Font> font2 = tgui::Font{"resources/DroidSansArmenian.ttf"}.getFont();
|
||||
|
||||
auto parent = std::make_shared<tgui::GuiContainer>();
|
||||
parent->setFont("resources/DroidSansArmenian.ttf");
|
||||
parent->add(chatBox);
|
||||
chatBox->setTextColor(sf::Color::Black);
|
||||
chatBox->setTextSize(24);
|
||||
chatBox->setFont(font1);
|
||||
|
||||
REQUIRE(chatBox->getLineAmount() == 0);
|
||||
chatBox->addLine("Line 1");
|
||||
|
@ -48,7 +48,7 @@ TEST_CASE("[ChatBox]") {
|
|||
chatBox->addLine("Line 2", 16);
|
||||
chatBox->addLine("Line 3", sf::Color::Green);
|
||||
chatBox->addLine("Line 4", sf::Color::Yellow, 18);
|
||||
chatBox->addLine("Line 5", sf::Color::Blue, 20, font);
|
||||
chatBox->addLine("Line 5", sf::Color::Blue, 20, font2);
|
||||
REQUIRE(chatBox->getLineAmount() == 5);
|
||||
|
||||
REQUIRE(chatBox->getLine(0) == "Line 1");
|
||||
|
@ -57,14 +57,97 @@ TEST_CASE("[ChatBox]") {
|
|||
REQUIRE(chatBox->getLine(3) == "Line 4");
|
||||
REQUIRE(chatBox->getLine(4) == "Line 5");
|
||||
|
||||
/// TODO: Also check colors, text size and font
|
||||
REQUIRE(chatBox->getLineColor(0) == sf::Color::Black);
|
||||
REQUIRE(chatBox->getLineColor(1) == sf::Color::Black);
|
||||
REQUIRE(chatBox->getLineColor(2) == sf::Color::Green);
|
||||
REQUIRE(chatBox->getLineColor(3) == sf::Color::Yellow);
|
||||
REQUIRE(chatBox->getLineColor(4) == sf::Color::Blue);
|
||||
|
||||
REQUIRE(chatBox->getLineTextSize(0) == 24);
|
||||
REQUIRE(chatBox->getLineTextSize(1) == 16);
|
||||
REQUIRE(chatBox->getLineTextSize(2) == 24);
|
||||
REQUIRE(chatBox->getLineTextSize(3) == 18);
|
||||
REQUIRE(chatBox->getLineTextSize(4) == 20);
|
||||
|
||||
REQUIRE(chatBox->getLineFont(0) == font1);
|
||||
REQUIRE(chatBox->getLineFont(1) == font1);
|
||||
REQUIRE(chatBox->getLineFont(2) == font1);
|
||||
REQUIRE(chatBox->getLineFont(3) == font1);
|
||||
REQUIRE(chatBox->getLineFont(4) == font2);
|
||||
}
|
||||
|
||||
/// TODO: Test other functions
|
||||
SECTION("removing lines") {
|
||||
REQUIRE(!chatBox->removeLine(0));
|
||||
chatBox->addLine("Line 1");
|
||||
chatBox->addLine("Line 2");
|
||||
chatBox->addLine("Line 3");
|
||||
REQUIRE(!chatBox->removeLine(5));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SECTION("line limit") {
|
||||
chatBox->addLine("Line 1");
|
||||
chatBox->addLine("Line 2");
|
||||
chatBox->addLine("Line 3");
|
||||
|
||||
chatBox->setLineLimit(2);
|
||||
REQUIRE(chatBox->getLineAmount() == 2);
|
||||
REQUIRE(chatBox->getLine(0) == "Line 2");
|
||||
REQUIRE(chatBox->getLine(1) == "Line 3");
|
||||
|
||||
chatBox->addLine("Line 4");
|
||||
REQUIRE(chatBox->getLine(0) == "Line 3");
|
||||
REQUIRE(chatBox->getLine(1) == "Line 4");
|
||||
}
|
||||
|
||||
SECTION("default text size") {
|
||||
chatBox->setTextSize(30);
|
||||
REQUIRE(chatBox->getTextSize() == 30);
|
||||
|
||||
chatBox->addLine("Text");
|
||||
REQUIRE(chatBox->getLineTextSize(0) == 30);
|
||||
}
|
||||
|
||||
SECTION("default text color") {
|
||||
chatBox->setTextColor(sf::Color::Red);
|
||||
REQUIRE(chatBox->getTextColor() == sf::Color::Red);
|
||||
|
||||
chatBox->addLine("Text");
|
||||
REQUIRE(chatBox->getLineColor(0) == sf::Color::Red);
|
||||
}
|
||||
|
||||
SECTION("get unexisting line") {
|
||||
std::shared_ptr<sf::Font> font1 = tgui::Font{"resources/DroidSansArmenian.ttf"}.getFont();
|
||||
std::shared_ptr<sf::Font> font2 = tgui::Font{"resources/DroidSansArmenian.ttf"}.getFont();
|
||||
|
||||
chatBox->setTextColor(sf::Color::Yellow);
|
||||
chatBox->setTextSize(26);
|
||||
chatBox->setFont(font1);
|
||||
|
||||
chatBox->addLine("Text", sf::Color::Blue, 20, font2);
|
||||
REQUIRE(chatBox->getLine(1) == "");
|
||||
REQUIRE(chatBox->getLineTextSize(2) == 26);
|
||||
REQUIRE(chatBox->getLineColor(3) == sf::Color::Yellow);
|
||||
REQUIRE(chatBox->getLineFont(4) == font1);
|
||||
}
|
||||
|
||||
SECTION("lines start from top or bottom") {
|
||||
REQUIRE(!chatBox->getLinesStartFromTop());
|
||||
chatBox->setLinesStartFromTop(true);
|
||||
REQUIRE(chatBox->getLinesStartFromTop());
|
||||
chatBox->setLinesStartFromTop(false);
|
||||
REQUIRE(!chatBox->getLinesStartFromTop());
|
||||
}
|
||||
|
||||
SECTION("Scrollbar") {
|
||||
tgui::Scrollbar::Ptr scrollbar = std::make_shared<tgui::Theme>()->load("scrollbar");
|
||||
|
||||
REQUIRE(chatBox->getScrollbar() != nullptr);
|
||||
REQUIRE(chatBox->getScrollbar() != scrollbar);
|
||||
chatBox->setScrollbar(nullptr);
|
||||
|
@ -143,5 +226,47 @@ TEST_CASE("[ChatBox]") {
|
|||
}
|
||||
}
|
||||
|
||||
/// TODO: Saving to and loading from file
|
||||
SECTION("Saving and loading from file") {
|
||||
REQUIRE_NOTHROW(chatBox = std::make_shared<tgui::Theme>()->load("ChatBox"));
|
||||
|
||||
auto theme = std::make_shared<tgui::Theme>("resources/Black.txt");
|
||||
REQUIRE_NOTHROW(chatBox = theme->load("ChatBox"));
|
||||
REQUIRE(chatBox->getPrimaryLoadingParameter() == "resources/Black.txt");
|
||||
REQUIRE(chatBox->getSecondaryLoadingParameter() == "chatbox");
|
||||
|
||||
auto parent = std::make_shared<tgui::GuiContainer>();
|
||||
parent->add(chatBox);
|
||||
|
||||
chatBox->setTextColor(sf::Color::White);
|
||||
chatBox->setTextSize(34);
|
||||
chatBox->addLine("L4");
|
||||
chatBox->addLine("L2", 32);
|
||||
chatBox->addLine("L3", sf::Color::Magenta);
|
||||
chatBox->addLine("L1", sf::Color::Cyan, 36);
|
||||
|
||||
REQUIRE_NOTHROW(parent->saveWidgetsToFile("WidgetFileChatBox1.txt"));
|
||||
|
||||
parent->removeAllWidgets();
|
||||
REQUIRE_NOTHROW(parent->loadWidgetsFromFile("WidgetFileChatBox1.txt"));
|
||||
|
||||
REQUIRE_NOTHROW(parent->saveWidgetsToFile("WidgetFileChatBox2.txt"));
|
||||
REQUIRE(compareFiles("WidgetFileChatBox1.txt", "WidgetFileChatBox2.txt"));
|
||||
|
||||
// Make sure that the lines are still in the correct order
|
||||
REQUIRE(chatBox->getLine(0) == "L4");
|
||||
REQUIRE(chatBox->getLine(1) == "L2");
|
||||
REQUIRE(chatBox->getLine(2) == "L3");
|
||||
REQUIRE(chatBox->getLine(3) == "L1");
|
||||
|
||||
SECTION("Copying widget") {
|
||||
tgui::ChatBox temp;
|
||||
temp = *chatBox;
|
||||
|
||||
parent->removeAllWidgets();
|
||||
parent->add(tgui::ChatBox::copy(std::make_shared<tgui::ChatBox>(temp)));
|
||||
|
||||
REQUIRE_NOTHROW(parent->saveWidgetsToFile("WidgetFileChatBox2.txt"));
|
||||
REQUIRE(compareFiles("WidgetFileChatBox1.txt", "WidgetFileChatBox2.txt"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue