Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
test_SystemInfoProvider.cpp
Go to the documentation of this file.
1
15
18#include <gmock/gmock.h>
19#include <gtest/gtest.h>
20
21using ::testing::_;
22using ::testing::NiceMock;
23using ::testing::Return;
24
32class SystemInfoProviderTest : public ::testing::Test
33{
34protected:
35 NiceMock<MockSystemCommandExecutor> mockExecutor;
37
39
40 void TearDown() override { delete infoProvider; }
41};
42
51TEST_F(SystemInfoProviderTest, GetWifiStatus_Connected)
52{
53 QString wifiName;
54 EXPECT_CALL(mockExecutor, executeCommand(QString("nmcli -t -f DEVICE,STATE,CONNECTION dev")))
55 .WillOnce(Return(QString("wlan0:connected:MyWiFi")));
56
57 QString status = infoProvider->getWifiStatus(wifiName);
58
59 EXPECT_EQ(status, "Connected");
60 EXPECT_EQ(wifiName, "MyWiFi");
61}
62
72TEST_F(SystemInfoProviderTest, GetWifiStatus_Disconnected)
73{
74 QString wifiName;
75 EXPECT_CALL(mockExecutor, executeCommand(QString("nmcli -t -f DEVICE,STATE,CONNECTION dev")))
76 .WillOnce(Return(QString("wlan0:disconnected:")));
77
78 QString status = infoProvider->getWifiStatus(wifiName);
79
80 EXPECT_EQ(status, "Disconnected");
81 EXPECT_TRUE(wifiName.isEmpty());
82}
83
93TEST_F(SystemInfoProviderTest, GetWifiStatus_NoInterface)
94{
95 QString wifiName;
96 EXPECT_CALL(mockExecutor, executeCommand(QString("nmcli -t -f DEVICE,STATE,CONNECTION dev")))
97 .WillOnce(Return(QString("eth0:connected:Ethernet")));
98
99 QString status = infoProvider->getWifiStatus(wifiName);
100
101 EXPECT_EQ(status, "No interface detected");
102 EXPECT_TRUE(wifiName.isEmpty());
103}
104
114TEST_F(SystemInfoProviderTest, GetTemperature_ValidReading)
115{
116 EXPECT_CALL(mockExecutor, readFile(QString("/sys/class/hwmon/hwmon0/temp1_input")))
117 .WillOnce(Return(QString("45000")));
118
119 QString temperature = infoProvider->getTemperature();
120
121 EXPECT_EQ(temperature, "45.0°C");
122}
123
132TEST_F(SystemInfoProviderTest, GetTemperature_InvalidReading)
133{
134 EXPECT_CALL(mockExecutor, readFile(QString("/sys/class/hwmon/hwmon0/temp1_input")))
135 .WillOnce(Return(QString("INVALID")));
136
137 QString temperature = infoProvider->getTemperature();
138
139 EXPECT_EQ(temperature, "N/A");
140}
141
150TEST_F(SystemInfoProviderTest, GetIpAddress_Valid)
151{
152 EXPECT_CALL(
153 mockExecutor,
154 executeCommand(QString(
155 "sh -c \"ip -4 addr show wlan0 | grep -oP '(?<=inet\\s)\\d+\\.\\d+\\.\\d+\\.\\d+'\"")))
156 .WillOnce(Return(QString("192.168.1.100")));
157
158 QString ipAddress = infoProvider->getIpAddress();
159
160 EXPECT_EQ(ipAddress, "192.168.1.100");
161}
162
172{
173 EXPECT_CALL(
174 mockExecutor,
175 executeCommand(QString(
176 "sh -c \"ip -4 addr show wlan0 | grep -oP '(?<=inet\\s)\\d+\\.\\d+\\.\\d+\\.\\d+'\"")))
177 .WillOnce(Return(QString("")));
178
179 QString ipAddress = infoProvider->getIpAddress();
180
181 EXPECT_EQ(ipAddress, "No IP address");
182}
File containing the Mock class of the SystemCommandExecutor class.
Definition of the SystemInfoProvider class.
Test fixture for testing the SystemInfoProvider class.
NiceMock< MockSystemCommandExecutor > mockExecutor
SystemInfoProvider * infoProvider
Class that provides system information to the display manager.
TEST_F(SystemInfoProviderTest, GetWifiStatus_Connected)
Ensures that the wifi status is correctly retrieved.