diff --git a/test/FakeDisplay.h b/test/FakeDisplay.h index 80f8073..6a74f06 100644 --- a/test/FakeDisplay.h +++ b/test/FakeDisplay.h @@ -14,6 +14,13 @@ class FakeDisplay : public Display int y_; }; + struct DrawnText + { + int x_; + int y_; + std::string text_; + }; + bool init() override { return true; }; void drawText([[maybe_unused]] int x, [[maybe_unused]] int y, @@ -21,7 +28,10 @@ class FakeDisplay : public Display void drawTextWithBackground( [[maybe_unused]] int x, [[maybe_unused]] int y, - [[maybe_unused]] const std::string& text) const override {}; + [[maybe_unused]] const std::string& text) const override + { + drawnTexts_.push_back({x, y, text}); + }; void drawBackground( [[maybe_unused]] ResourceType resourceType) const override {}; @@ -70,9 +80,15 @@ class FakeDisplay : public Display void resetChangedAreas() { changedAreas_.clear(); } + std::vector getDrawnTexts() const { return drawnTexts_; } + + void resetDrawnTexts() { drawnTexts_.clear(); } + private: - int resourceWidth_ {0}; - int resourceHeight_ {0}; + int resourceWidth_{0}; + int resourceHeight_{0}; mutable std::vector changedAreas_; + + mutable std::vector drawnTexts_; }; diff --git a/test/StatusTest.cpp b/test/StatusTest.cpp index cdef2a7..4193429 100644 --- a/test/StatusTest.cpp +++ b/test/StatusTest.cpp @@ -2,8 +2,11 @@ #include +#include "FakeDisplay.h" + TEST_CASE("Status usage", "[Status]") { + FakeDisplay display; Status status{{100, 100}}; SECTION("Check resource type") { @@ -15,4 +18,29 @@ TEST_CASE("Status usage", "[Status]") Point center{status.getCenter()}; REQUIRE(center == Point{200, 300}); } + + SECTION("Check texts when drawing empty stats") + { + status.draw(display); + std::vector drawnTexts{display.getDrawnTexts()}; + REQUIRE(drawnTexts.size() == 4); + REQUIRE(drawnTexts[0].text_ == "Lives: 0"); + REQUIRE(drawnTexts[1].text_ == "Shield: 0"); + REQUIRE(drawnTexts[2].text_ == "Speed: 0"); + REQUIRE(drawnTexts[3].text_ == "Attack: 0"); + } + + SECTION("Check Positions when drawing empty stats") + { + status.draw(display); + std::vector drawnTexts{display.getDrawnTexts()}; + REQUIRE(drawnTexts[0].x_ == 200); + REQUIRE(drawnTexts[0].y_ == 120); + REQUIRE(drawnTexts[1].x_ == 200); + REQUIRE(drawnTexts[1].y_ == 240); + REQUIRE(drawnTexts[2].x_ == 200); + REQUIRE(drawnTexts[2].y_ == 360); + REQUIRE(drawnTexts[3].x_ == 200); + REQUIRE(drawnTexts[3].y_ == 480); + } }