Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test code for WiFiSIgnalStrengthMonitor.cpp #24

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/gnome_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: gnome_unit_test

on:
push:
branches: [ main, develop, 'release/**']
branches: [ main, develop, Test]
pull_request:
branches: [ main, develop, 'release/**']
branches: [ main, develop, Test]

env:
THUNDER_REF: "R4.4.1"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ install(TARGETS ${PLUGIN_LEGACY_DEPRECATED_WIFI} DESTINATION ${CMAKE_INSTALL_PRE
write_config()
write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_NETWORK}.so)
write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so)

include(Tests/WiFi/wifiTest.cmake)
58 changes: 58 additions & 0 deletions Tests/WiFi/test_WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "WiFiSignalStrengthMonitor.h"
#include "NetworkManagerImplementation.h"
#include "NetworkManagerLogger.h"
#include "INetworkManager.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <iostream>
#include <thread>
#include <chrono>
#include <list>
#include <string>

using namespace std;
using namespace WPEFramework;
using namespace WPEFramework::Plugin;
namespace WPEFramework
{
namespace Plugin
{
NetworkManagerImplementation* _instance;
void NetworkManagerImplementation::ReportWiFiSignalStrengthChange(const string ssid, const string strength, const WiFiSignalQuality quality)
{
return;
}
void NetworkManagerImplementation::ReportInternetStatusChange(const InternetStatus prevState, const InternetStatus currState)
{
return;
}
}
}

class WiFiSignalStrengthMonitorTest : public ::testing::Test {
protected:
WPEFramework::Plugin::WiFiSignalStrengthMonitor monitor;
void SetUp() override {
}
void TearDown() override {
}
};
#define BUFFER_SIZE 1024

TEST_F(WiFiSignalStrengthMonitorTest, GetSignalData_Connected) {
std::string ssid = "TestSSID";
Exchange::INetworkManager::WiFiSignalQuality quality;
std::string strengthOut= "-55";
monitor.getSignalData(ssid, quality, strengthOut);
}

TEST_F(WiFiSignalStrengthMonitorTest, StartWiFiSignalStrengthMonitor) {
monitor.startWiFiSignalStrengthMonitor(1);

}

int main(int argc, char **argv) {
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}

42 changes: 42 additions & 0 deletions Tests/WiFi/wifiTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.10)
set(WIFI_TEST "wifiTest")

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GIO REQUIRED gio-2.0)
pkg_check_modules(LIBNM REQUIRED libnm)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)

FetchContent_MakeAvailable(googletest)
add_executable(${WIFI_TEST}
Tests/WiFi/test_WiFiSignalStrengthMonitor.cpp
WiFiSignalStrengthMonitor.cpp
NetworkManagerLogger.cpp
NetworkManagerConnectivity.cpp
)
set_target_properties(${WIFI_TEST} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
)
target_compile_options(${WIFI_TEST} PRIVATE -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h)

target_include_directories(${WIFI_TEST} PRIVATE
${GLIB_INCLUDE_DIRS}
${LIBNM_INCLUDE_DIRS}
${GIO_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
Tests
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/../googlemock/include
)

target_link_libraries(${WIFI_TEST} PRIVATE gmock_main ${NAMESPACE}Core::${NAMESPACE}Core ${GLIB_LIBRARIES} ${GIO_LIBRARIES} ${LIBNM_LIBRARIES} ${CURL_LIBRARIES})
target_include_directories(${WIFI_TEST} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS ${WIFI_TEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

1 change: 1 addition & 0 deletions WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <thread>
#include <chrono>
#include <atomic>
#include <stdlib.h>
#include "NetworkManagerLogger.h"
#include "NetworkManagerImplementation.h"
#include "WiFiSignalStrengthMonitor.h"
Expand Down
Loading