~ test if text has been cleared

~ test for negative values for set pixel
This commit is contained in:
Johannes Theiner 2019-12-05 09:49:54 +01:00
parent 71bd846c6b
commit 469ac1479d
4 changed files with 25 additions and 15 deletions

View File

@ -118,6 +118,9 @@ namespace vkvm {
} }
auto getPixel(int x, int y) -> Color { auto getPixel(int x, int y) -> Color {
if(x < 0 || y < 0) {
return getBackgroundColor();
}
if (x > getWidth() || y > getHeight()) { if (x > getWidth() || y > getHeight()) {
return getBackgroundColor(); return getBackgroundColor();
} }
@ -180,7 +183,9 @@ namespace vkvm {
} }
auto getText() -> std::string { auto getText() -> std::string {
return std::string(getTextArea()); std::string text = getTextArea();
return text.substr(0, getCharactersPerColumn() * getCharactersPerRow());
} }
auto clearText() -> bool { auto clearText() -> bool {

View File

@ -3,7 +3,6 @@
TEST_CASE("AREA") { TEST_CASE("AREA") {
vkvm::initialize(0); vkvm::initialize(0);
vkvm::setMode(vkvm::RGB);
vkvm::setWidth(200); vkvm::setWidth(200);
vkvm::setHeight(200); vkvm::setHeight(200);
@ -13,10 +12,12 @@ TEST_CASE("AREA") {
} }
SECTION("Out of bounds") { SECTION("Out of bounds") {
REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white)); REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white));
REQUIRE(vkvm::getPixel(400, 400) == vkvm::black); REQUIRE(vkvm::getPixel(400, 400) == vkvm::black);
REQUIRE_FALSE(vkvm::setPixel(-5, -5, vkvm::white));
REQUIRE(vkvm::getPixel(-5, -5) == vkvm::black);
vkvm::setBackgroundColor(vkvm::blue); vkvm::setBackgroundColor(vkvm::blue);
REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue); REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue);

View File

@ -7,26 +7,26 @@ TEST_CASE("Event") {
SECTION("Register") { SECTION("Register") {
bool mouseMove = false; bool mouseMove = false;
bool timer = false; bool keyup = false;
bool timer2 = false; bool keyup2 = false;
vkvm::registerEvent(vkvm::MouseMove, [&]() { vkvm::registerEvent(vkvm::MouseMove, [&]() {
mouseMove = true; mouseMove = true;
}); });
vkvm::registerEvent(vkvm::Timer, [&]() { vkvm::registerEvent(vkvm::KeyUp, [&]() {
timer = true; keyup = true;
}); });
vkvm::registerEvent(vkvm::Timer, [&]() { vkvm::registerEvent(vkvm::KeyUp, [&]() {
timer2 = true; keyup2 = true;
}); });
REQUIRE_FALSE(mouseMove); REQUIRE_FALSE(mouseMove);
vkvm::callEvent(vkvm::MouseMove); vkvm::callEvent(vkvm::MouseMove);
REQUIRE(mouseMove); REQUIRE(mouseMove);
REQUIRE_FALSE(timer); REQUIRE_FALSE(keyup);
REQUIRE_FALSE(timer2); REQUIRE_FALSE(keyup2);
vkvm::callEvent(vkvm::Timer); vkvm::callEvent(vkvm::KeyUp);
REQUIRE(timer); REQUIRE(keyup);
REQUIRE(timer2); REQUIRE(keyup2);
} }
} }

View File

@ -20,5 +20,9 @@ TEST_CASE("Text") {
REQUIRE(vkvm::getCharactersPerRow() == 1); REQUIRE(vkvm::getCharactersPerRow() == 1);
REQUIRE(vkvm::setText("Hello World")); REQUIRE(vkvm::setText("Hello World"));
REQUIRE(vkvm::getText() == "Hello World"); REQUIRE(vkvm::getText() == "Hello");
REQUIRE(vkvm::clearText());
REQUIRE(vkvm::getText().empty());
} }