Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KirFedotov committed May 30, 2024
1 parent 48c26e2 commit 60f842d
Showing 1 changed file with 77 additions and 29 deletions.
106 changes: 77 additions & 29 deletions test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,100 @@ class TimedDoorTest : public ::testing::Test {
};


TEST_F(TimedDoorTest, lock_door_then_unlocked_test) {
std::this_thread::sleep_for(std::chrono::seconds(door.getTimeOut() + 1));
EXPECT_NO_THROW(door.throwState());
TEST_F(TimedDoorTest, DoorInitialState) {
TimedDoor door(5);
EXPECT_FALSE(door.isDoorOpened());
EXPECT_EQ(door.getTimeOut(), 5);
}

TEST_F(TimedDoorTest, unlock_door_then_timeout_test) {
door.unlock();
std::this_thread::sleep_for(std::chrono::seconds(door.getTimeOut()));
EXPECT_THROW(door.throwState(), std::runtime_error);
TEST_F(TimedDoorTest, UnlockDoor) {
TimedDoor door(5);
door.unlock();
EXPECT_TRUE(door.isDoorOpened());
}

TEST_F(TimedDoorTest, lock_before_timeout_then_open_test) {
std::this_thread::sleep_for(std::chrono::seconds(door.getTimeOut() + 1));
door.unlock();
EXPECT_THROW(door.throwState(), std::runtime_error);
TEST_F(TimedDoorTest, LockDoor) {
TimedDoor door(5);
door.unlock();
door.lock();
EXPECT_FALSE(door.isDoorOpened());
}

TEST_F(TimedDoorTest, first_door_closed_test) {
EXPECT_FALSE(door.isDoorOpened());
TEST_F(TimedDoorTest, UnlockDoorAlreadyOpened) {
TimedDoor door(5);
door.unlock();
EXPECT_THROW(door.unlock(), std::logic_error);
}

TEST_F(TimedDoorTest, unlock_method_test) {
door.unlock();
EXPECT_TRUE(door.isDoorOpened());
TEST_F(TimedDoorTest, LockDoorAlreadyClosed) {
TimedDoor door(5);
EXPECT_THROW(door.lock(), std::logic_error);
}

TEST_F(TimedDoorTest, lock_method_test) {
door.unlock();
door.lock();
EXPECT_FALSE(door.isDoorOpened());
TEST_F(TimedDoorTest, DoorTimerAdapterTimeout) {
TimedDoor door(5);
DoorTimerAdapter adapter(door);
EXPECT_NO_THROW(adapter.Timeout());
}

TEST_F(TimedDoorTest, close_before_test) {
EXPECT_NO_THROW(door.throwState());
TEST_F(TimedDoorTest, DoorTimerAdapterTimeoutDoorOpened) {
TimedDoor door(5);
DoorTimerAdapter adapter(door);
door.unlock();
EXPECT_THROW(adapter.Timeout(), std::runtime_error);
}

TEST_F(TimedDoorTest, unlock_door_twice_test) {
door.unlock();
EXPECT_THROW(door.unlock(), std::logic_error);
TEST_F(TimedDoorTest, TimerRegister) {
TimedDoor door(5);
timer.tregister(5, new DoorTimerAdapter(door));
EXPECT_THROW(timer.tregister(5, new DoorTimerAdapter(door)), std::runtime_error);
}

TEST_F(TimedDoorTest, TimerRegisterNoTimeout) {
TimedDoor door(5);
timer.tregister(5, new DoorTimerAdapter(door));
EXPECT_NO_THROW(timer.tregister(5, new DoorTimerAdapter(door)));
}

TEST_F(TimedDoorTest, opened_exeption_test) {
TEST_F(TimedDoorTest, TimedDoorThrowState) {
TimedDoor door(5);
EXPECT_NO_THROW(door.throwState());
}

TEST_F(TimedDoorTest, TimedDoorThrowStateOpened) {
TimedDoor door(5);
door.unlock();
EXPECT_THROW(door.throwState(), std::runtime_error);
}

TEST_F(TimedDoorTest, MultipleUnlockLockCycles) {
TimedDoor door(5);
for (int i = 0; i < 10; ++i) {
door.unlock();
EXPECT_THROW(door.throwState(), std::runtime_error);
EXPECT_TRUE(door.isDoorOpened());
door.lock();
EXPECT_FALSE(door.isDoorOpened());
}
}

TEST_F(TimedDoorTest, lock_door_twice_test) {
EXPECT_THROW(door.lock(), std::logic_error);
TEST_F(TimedDoorTest, LockUnlockAfterTimeout) {
TimedDoor door(5);
door.unlock();
timer.tregister(5, new DoorTimerAdapter(door));
door.lock();
EXPECT_FALSE(door.isDoorOpened());
}

TEST_F(TimedDoorTest, TimerClientPolymorphism) {
TimerClient *client = new DoorTimerAdapter(TimedDoor(5));
EXPECT_NO_THROW(client->Timeout());
delete client;
}

TEST_F(TimedDoorTest, TimerClientPolymorphismWithException) {
TimedDoor door(5);
door.unlock();
TimerClient *client = new DoorTimerAdapter(door);
EXPECT_THROW(client->Timeout(), std::runtime_error);
delete client;
}

0 comments on commit 60f842d

Please sign in to comment.