2022-07-18 15:02:06 +08:00
|
|
|
#include <SFML/Graphics/Image.hpp>
|
2022-04-09 08:33:50 +08:00
|
|
|
#include <SFML/Graphics/RectangleShape.hpp>
|
2022-07-18 15:02:06 +08:00
|
|
|
#include <SFML/Graphics/RenderTexture.hpp>
|
2022-04-09 08:33:50 +08:00
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2022-04-09 08:33:50 +08:00
|
|
|
|
2022-07-18 15:02:06 +08:00
|
|
|
#include <GraphicsUtil.hpp>
|
2022-07-05 00:20:58 +08:00
|
|
|
#include <SystemUtil.hpp>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2022-07-05 13:51:18 +08:00
|
|
|
TEST_CASE("[Graphics] sf::RectangleShape")
|
2022-04-09 08:33:50 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::RectangleShape>);
|
|
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::RectangleShape>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RectangleShape>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RectangleShape>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Default constructor")
|
2022-04-09 08:33:50 +08:00
|
|
|
{
|
|
|
|
const sf::RectangleShape rectangle;
|
|
|
|
CHECK(rectangle.getSize() == sf::Vector2f(0, 0));
|
|
|
|
CHECK(rectangle.getPointCount() == 4);
|
|
|
|
CHECK(rectangle.getPoint(0) == sf::Vector2f(0, 0));
|
|
|
|
CHECK(rectangle.getPoint(1) == sf::Vector2f(0, 0));
|
|
|
|
CHECK(rectangle.getPoint(2) == sf::Vector2f(0, 0));
|
|
|
|
CHECK(rectangle.getPoint(3) == sf::Vector2f(0, 0));
|
2023-04-24 15:25:44 +08:00
|
|
|
CHECK(rectangle.getGeometricCenter() == sf::Vector2f(0, 0));
|
2022-04-09 08:33:50 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Size constructor")
|
2022-04-09 08:33:50 +08:00
|
|
|
{
|
|
|
|
const sf::RectangleShape rectangle({9, 8});
|
|
|
|
CHECK(rectangle.getSize() == sf::Vector2f(9, 8));
|
|
|
|
CHECK(rectangle.getPointCount() == 4);
|
|
|
|
CHECK(rectangle.getPoint(0) == sf::Vector2f(0, 0));
|
|
|
|
CHECK(rectangle.getPoint(1) == sf::Vector2f(9, 0));
|
|
|
|
CHECK(rectangle.getPoint(2) == sf::Vector2f(9, 8));
|
|
|
|
CHECK(rectangle.getPoint(3) == sf::Vector2f(0, 8));
|
2023-04-24 15:25:44 +08:00
|
|
|
CHECK(rectangle.getGeometricCenter() == sf::Vector2f(9.f, 8.f) / 2.f);
|
2022-04-09 08:33:50 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Set size")
|
2022-04-09 08:33:50 +08:00
|
|
|
{
|
|
|
|
sf::RectangleShape rectangle({7, 6});
|
|
|
|
rectangle.setSize({5, 4});
|
|
|
|
CHECK(rectangle.getSize() == sf::Vector2f(5, 4));
|
2023-04-24 15:25:44 +08:00
|
|
|
CHECK(rectangle.getGeometricCenter() == sf::Vector2f(5.f, 4.f) / 2.f);
|
2022-04-09 08:33:50 +08:00
|
|
|
}
|
2022-07-18 15:02:06 +08:00
|
|
|
|
|
|
|
SUBCASE("Render rectangle shape")
|
|
|
|
{
|
|
|
|
sf::RectangleShape rectangle({50.f, 20.f});
|
|
|
|
rectangle.setFillColor(sf::Color::Red);
|
|
|
|
rectangle.setOutlineColor(sf::Color::Green);
|
|
|
|
rectangle.setOutlineThickness(2.f);
|
|
|
|
rectangle.setPosition({10.f, 10.f});
|
|
|
|
|
|
|
|
sf::RenderTexture renderTexture;
|
|
|
|
REQUIRE(renderTexture.create({100, 100}));
|
|
|
|
|
|
|
|
renderTexture.clear();
|
|
|
|
renderTexture.draw(rectangle);
|
|
|
|
renderTexture.display();
|
|
|
|
|
|
|
|
auto image = renderTexture.getTexture().copyToImage();
|
|
|
|
REQUIRE(image.saveToFile("testOutput.png"));
|
|
|
|
|
|
|
|
REQUIRE(compareImages("expected/rectangleShape.png", "testOutput.png"));
|
|
|
|
}
|
2022-04-09 08:33:50 +08:00
|
|
|
}
|