Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazy767 committed May 8, 2024
1 parent a0a6544 commit b6595fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/TimedDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ void TimedDoor::throwState() {

void Timer::tregister(int timeout, TimerClient* client) {
this->client = client;
if (!door->isDoorOpened()) {
return;
}
sleep(timeout);
::sleep(timeout);
client->Timeout();
}

Expand Down
11 changes: 4 additions & 7 deletions test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#include <cstdint>
#include "TimedDoor.h"

using ::testing::_;
using ::testing::Throw;

class MockTimerClient : public TimerClient {
public:
public:
MOCK_METHOD(void, Timeout, (), (override));
};

class TimedDoorTest : public ::testing::Test {
protected:
protected:
TimedDoor* door;
MockTimerClient mockClient;
Timer timer;
Expand Down Expand Up @@ -56,20 +57,16 @@ TEST_F(TimedDoorTest, TimeoutCalledOnOpenDoor) {
EXPECT_CALL(mockClient, Timeout())
.Times(1)
.WillOnce(Throw(std::runtime_error("The door is still open!")));
ASSERT_THROW({
timer.tregister(1, &mockClient);
}, std::runtime_error);
ASSERT_THROW(timer.tregister(1, &mockClient), std::runtime_error);
}

TEST_F(TimedDoorTest, NoTimeoutCalledOnClosedDoor) {
door->lock();
EXPECT_CALL(mockClient, Timeout())
.Times(0);

timer.tregister(1, &mockClient);
}


TEST_F(TimedDoorTest, DoorStateAfterTimeoutException) {
door->unlock();
try {
Expand Down

0 comments on commit b6595fe

Please sign in to comment.