Skip to content

Commit

Permalink
Tests - Add Network Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Dec 6, 2023
1 parent a935251 commit acbb1e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/network/networkmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ namespace Nickvision::Aura::Network
NLM_CONNECTIVITY connection;
if (pNLM->GetConnectivity(&connection) == S_OK)
{
switch (connection)
if ((connection & NLM_CONNECTIVITY_DISCONNECTED) == NLM_CONNECTIVITY_DISCONNECTED)
{
case NLM_CONNECTIVITY_DISCONNECTED:
newState = NetworkState::Disconnected;
break;
case NLM_CONNECTIVITY_IPV4_INTERNET:
case NLM_CONNECTIVITY_IPV6_INTERNET:
}
else if ((connection & NLM_CONNECTIVITY_IPV4_INTERNET) == NLM_CONNECTIVITY_IPV4_INTERNET || (connection & NLM_CONNECTIVITY_IPV6_INTERNET) == NLM_CONNECTIVITY_IPV6_INTERNET)
{
newState = NetworkState::ConnectedGlobal;
break;
default:
}
else
{
newState = NetworkState::ConnectedLocal;
break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enable_testing()
add_executable(${PROJECT_NAME}
eventtests.cpp
main.cpp
networktests.cpp
stringtests.cpp
versiontests.cpp
webtests.cpp)
Expand Down
26 changes: 26 additions & 0 deletions tests/networktests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <gtest/gtest.h>
#include <cstdlib>
#include "network/networkmonitor.h"

using namespace Nickvision::Aura::Network;

TEST(NetworkTests, ConnectedGlobal)
{
NetworkMonitor netmon;
netmon.stateChanged() += [](const NetworkStateChangedEventArgs& e)
{
EXPECT_EQ(e.getState(), NetworkState::ConnectedGlobal);
};
netmon.checkConnectionState();
}

TEST(NetworkTests, DisableNetCheck)
{
putenv("AURA_DISABLE_NETCHECK=true");
NetworkMonitor netmon;
netmon.stateChanged() += [](const NetworkStateChangedEventArgs& e)
{
EXPECT_EQ(e.getState(), NetworkState::ConnectedGlobal);
};
netmon.checkConnectionState();
}

0 comments on commit acbb1e7

Please sign in to comment.