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

View File

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

View File

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

View File

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