Skip to content

Commit

Permalink
add some unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Le Brun <[email protected]>
  • Loading branch information
ludovic-smile committed Jun 17, 2024
1 parent e885728 commit 3123137
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
18 changes: 12 additions & 6 deletions include/enhanced_hnz_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,6 @@ class EnhancedHNZServer
*/
static std::string framesToStr(const std::vector<std::shared_ptr<MSG_TRAME>>& frames);

/**
* Is server running
* @return True if the server is running, false otherwise
*/
bool isRuning() const { return is_running;}

/**
* Gets tcp port
* @return The tcp port
Expand Down Expand Up @@ -245,6 +239,18 @@ class EnhancedHNZServer
*/
void handChecking(int timeout_s );

/**
* Set is server running
* @param running The server running
*/
void setIsRunning(bool running) { is_running = running;}

/**
* Gets is server running
* @return The server running
*/
bool isRunning() const {return is_running;}

private:

HNZServer *server = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/hnz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ void HNZ::managerServer(const std::shared_ptr<EnhancedHNZServer> &server)
sendWaitingData(server);
}

if (server->isRuning() == false && m_is_running == true)
if (server->isRunning() == false && m_is_running == true)
{
server->stopHNZServer();
server->startHNZServer();
Expand Down
30 changes: 30 additions & 0 deletions tests/test_server_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,36 @@ TEST(HNZServerWrapper, TestHnzHandShake) {

}

TEST(HNZServerWrapper, TestHnzHandShakeRunning) {
EnhancedHNZServer m_server1(6001);

auto config = std::make_shared<HnzConfig>(protocol_stack, exchanged_data);
m_server1.getStateMachine()->setConfig(config);

ASSERT_NO_THROW(m_server1.startHNZServer());

ASSERT_NO_THROW(m_server1.waitForTCPConnection(2));
ASSERT_NO_THROW(m_server1.setIsRunning(true));
// Launch the thread
std::thread t1(&EnhancedHNZServer::handChecking,&m_server1,15);

ASSERT_NO_THROW(m_server1.stopHNZServer());

t1.join();

}

TEST(HNZServerWrapper, TestServeurIsRunning) {
EnhancedHNZServer m_server1(6001);

auto config = std::make_shared<HnzConfig>(protocol_stack, exchanged_data);
m_server1.getStateMachine()->setConfig(config);

ASSERT_FALSE(m_server1.isRunning());
ASSERT_NO_THROW(m_server1.setIsRunning(true));
ASSERT_TRUE(m_server1.isRunning());
}




Expand Down

0 comments on commit 3123137

Please sign in to comment.