Skip to content

Commit

Permalink
Added tests for new signals
Browse files Browse the repository at this point in the history
  • Loading branch information
texus committed Feb 23, 2019
1 parent 43e6312 commit aa5a366
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
14 changes: 14 additions & 0 deletions tests/Widgets/CheckBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ TEST_CASE("[CheckBox]")
REQUIRE_NOTHROW(checkBox->connect("Unchecked", [](bool){}));
REQUIRE_NOTHROW(checkBox->connect("Unchecked", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(checkBox->connect("Unchecked", [](tgui::Widget::Ptr, std::string, bool){}));

REQUIRE_NOTHROW(checkBox->connect("Changed", [](){}));
REQUIRE_NOTHROW(checkBox->connect("Changed", [](bool){}));
REQUIRE_NOTHROW(checkBox->connect("Changed", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(checkBox->connect("Changed", [](tgui::Widget::Ptr, std::string, bool){}));
}

SECTION("WidgetType")
Expand Down Expand Up @@ -183,29 +188,36 @@ TEST_CASE("[CheckBox]")

unsigned int checkCount = 0;
unsigned int uncheckCount = 0;
unsigned int changedCount = 0;
checkBox->connect("Checked", &genericCallback, std::ref(checkCount));
checkBox->connect("Unchecked", &genericCallback, std::ref(uncheckCount));
checkBox->connect("Changed", &genericCallback, std::ref(changedCount));

checkBox->setChecked(true);
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 0);
REQUIRE(changedCount == 1);

checkBox->setChecked(false);
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 1);
REQUIRE(changedCount == 2);

checkBox->leftMousePressed({65, 60});
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 1);
REQUIRE(changedCount == 2);

checkBox->leftMouseReleased({65, 60});
REQUIRE(checkCount == 2);
REQUIRE(uncheckCount == 1);
REQUIRE(changedCount == 3);

checkBox->leftMousePressed({65, 60});
checkBox->leftMouseReleased({65, 60});
REQUIRE(checkCount == 2);
REQUIRE(uncheckCount == 2);
REQUIRE(changedCount == 4);

SECTION("Key pressed")
{
Expand All @@ -219,11 +231,13 @@ TEST_CASE("[CheckBox]")
checkBox->keyPressed(keyEvent);
REQUIRE(checkCount == 3);
REQUIRE(uncheckCount == 2);
REQUIRE(changedCount == 5);

keyEvent.code = sf::Keyboard::Return;
checkBox->keyPressed(keyEvent);
REQUIRE(checkCount == 3);
REQUIRE(uncheckCount == 3);
REQUIRE(changedCount == 6);
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions tests/Widgets/ChildWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ TEST_CASE("[ChildWindow]")
REQUIRE_NOTHROW(childWindow->connect("Minimized", [](tgui::ChildWindow::Ptr){}));
REQUIRE_NOTHROW(childWindow->connect("Minimized", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(childWindow->connect("Minimized", [](tgui::Widget::Ptr, std::string, tgui::ChildWindow::Ptr){}));

REQUIRE_NOTHROW(childWindow->connect("EscapeKeyPressed", [](){}));
REQUIRE_NOTHROW(childWindow->connect("EscapeKeyPressed", [](tgui::ChildWindow::Ptr){}));
REQUIRE_NOTHROW(childWindow->connect("EscapeKeyPressed", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(childWindow->connect("EscapeKeyPressed", [](tgui::Widget::Ptr, std::string, tgui::ChildWindow::Ptr){}));
}

SECTION("WidgetType")
Expand Down Expand Up @@ -184,10 +189,6 @@ TEST_CASE("[ChildWindow]")

SECTION("Events / Signals")
{
unsigned int mousePressedCount = 0;
unsigned int mouseReleasedCount = 0;
unsigned int clickedCount = 0;

childWindow->setPosition(40, 30);
childWindow->setSize(150, 100);
childWindow->getRenderer()->setTitleBarHeight(20);
Expand Down Expand Up @@ -231,6 +232,20 @@ TEST_CASE("[ChildWindow]")
REQUIRE(mouseLeftCount == 1);
}

SECTION("EscapeKeyPressed")
{
unsigned int escapeKeyPressedCount = 0;
childWindow->connect("EscapeKeyPressed", &genericCallback, std::ref(escapeKeyPressedCount));

sf::Event::KeyEvent event;
event.code = sf::Keyboard::Escape;
event.alt = false;
event.control = false;
event.shift = false;
event.system = false;
childWindow->keyPressed(event);
}

/// TODO: Test title button events and dragging and resizing window
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Widgets/RadioButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ TEST_CASE("[RadioButton]")
REQUIRE_NOTHROW(radioButton->connect("Unchecked", [](bool){}));
REQUIRE_NOTHROW(radioButton->connect("Unchecked", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(radioButton->connect("Unchecked", [](tgui::Widget::Ptr, std::string, bool){}));

REQUIRE_NOTHROW(radioButton->connect("Changed", [](){}));
REQUIRE_NOTHROW(radioButton->connect("Changed", [](bool){}));
REQUIRE_NOTHROW(radioButton->connect("Changed", [](tgui::Widget::Ptr, std::string){}));
REQUIRE_NOTHROW(radioButton->connect("Changed", [](tgui::Widget::Ptr, std::string, bool){}));
}

SECTION("WidgetType")
Expand Down Expand Up @@ -160,27 +165,33 @@ TEST_CASE("[RadioButton]")

unsigned int checkCount = 0;
unsigned int uncheckCount = 0;
unsigned int changedCount = 0;
radioButton->connect("Checked", &genericCallback, std::ref(checkCount));
radioButton->connect("Unchecked", &genericCallback, std::ref(uncheckCount));
radioButton->connect("Changed", &genericCallback, std::ref(changedCount));

radioButton->leftMousePressed({105, 90});
REQUIRE(checkCount == 0);
REQUIRE(uncheckCount == 0);
REQUIRE(changedCount == 0);

radioButton->leftMouseReleased({105, 90});
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 0);
REQUIRE(changedCount == 1);

// Radio buttons can't be unchecked by user interaction
radioButton->leftMousePressed({105, 90});
radioButton->leftMouseReleased({105, 90});
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 0);
REQUIRE(changedCount == 1);

// Programmably unchecking is however possible
radioButton->setChecked(false);
REQUIRE(checkCount == 1);
REQUIRE(uncheckCount == 1);
REQUIRE(changedCount == 2);

SECTION("Key pressed")
{
Expand All @@ -193,12 +204,15 @@ TEST_CASE("[RadioButton]")
keyEvent.code = sf::Keyboard::Space;
radioButton->keyPressed(keyEvent);
REQUIRE(checkCount == 2);
REQUIRE(changedCount == 3);

radioButton->setChecked(false);
REQUIRE(changedCount == 4);

keyEvent.code = sf::Keyboard::Return;
radioButton->keyPressed(keyEvent);
REQUIRE(checkCount == 3);
REQUIRE(changedCount == 5);
}
}
}
Expand Down

0 comments on commit aa5a366

Please sign in to comment.