Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
test_SystemManager.cpp
Go to the documentation of this file.
1
15
16#include <QSignalSpy>
19#include "SystemManager.hpp"
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
22
23using ::testing::_;
24using ::testing::DoAll;
25using ::testing::NiceMock;
26using ::testing::Return;
27
35class SystemManagerTest : public ::testing::Test
36{
37protected:
38 NiceMock<MockSystemInfoProvider> mockInfoProvider;
39 NiceMock<MockBatteryController> mockBatteryController;
41
42 void SetUp() override
43 {
45 }
46
47 void TearDown() override { delete systemManager; }
48};
49
57TEST_F(SystemManagerTest, UpdateTime_EmitsCorrectSignal)
58{
59 QSignalSpy spy(systemManager, &SystemManager::timeUpdated);
60 ASSERT_TRUE(spy.isValid());
61
62 systemManager->updateTime();
63
64 ASSERT_EQ(spy.count(), 1);
65 QList<QVariant> arguments = spy.takeFirst();
66 EXPECT_FALSE(arguments.at(0).toString().isEmpty()); // Date
67 EXPECT_FALSE(arguments.at(1).toString().isEmpty()); // Time
68 EXPECT_FALSE(arguments.at(2).toString().isEmpty()); // Day
69}
70
78TEST_F(SystemManagerTest, UpdateSystemStatus_EmitsWifiStatus)
79{
80 QString mockWifiName = "MyWiFi";
81
82 EXPECT_CALL(mockInfoProvider, getWifiStatus(_))
83 .WillOnce(DoAll(testing::SetArgReferee<0>(mockWifiName), // Set wifiName argument
84 Return(QString("Connected")) // Return "Connected"
85 ));
86
87 QSignalSpy spy(systemManager, &SystemManager::wifiStatusUpdated);
88 ASSERT_TRUE(spy.isValid());
89
90 systemManager->updateSystemStatus();
91
92 ASSERT_EQ(spy.count(), 1);
93 QList<QVariant> arguments = spy.takeFirst();
94 EXPECT_EQ(arguments.at(0).toString(), "Connected");
95 EXPECT_EQ(arguments.at(1).toString(), "MyWiFi");
96}
97
105TEST_F(SystemManagerTest, UpdateSystemStatus_EmitsTemperature)
106{
107 EXPECT_CALL(mockInfoProvider, getTemperature()).WillOnce(Return(QString("42.0°C")));
108
109 QSignalSpy spy(systemManager, &SystemManager::temperatureUpdated);
110 ASSERT_TRUE(spy.isValid());
111
112 systemManager->updateSystemStatus();
113
114 ASSERT_EQ(spy.count(), 1);
115 EXPECT_EQ(spy.takeFirst().at(0).toString(), "42.0°C");
116}
117
125TEST_F(SystemManagerTest, UpdateSystemStatus_EmitsBatteryPercentage)
126{
127 EXPECT_CALL(mockBatteryController, getBatteryPercentage()).WillOnce(Return(75.0f));
128
129 QSignalSpy spy(systemManager, &SystemManager::batteryPercentageUpdated);
130 ASSERT_TRUE(spy.isValid());
131
132 systemManager->updateSystemStatus();
133
134 ASSERT_EQ(spy.count(), 1);
135 EXPECT_FLOAT_EQ(spy.takeFirst().at(0).toFloat(), 75.0f);
136}
137
145TEST_F(SystemManagerTest, UpdateSystemStatus_EmitsIpAddress)
146{
147 EXPECT_CALL(mockInfoProvider, getIpAddress()).WillOnce(Return(QString("192.168.1.100")));
148
149 QSignalSpy spy(systemManager, &SystemManager::ipAddressUpdated);
150 ASSERT_TRUE(spy.isValid());
151
152 systemManager->updateSystemStatus();
153
154 ASSERT_EQ(spy.count(), 1);
155 EXPECT_EQ(spy.takeFirst().at(0).toString(), "192.168.1.100");
156}
File containing the Mock class of the BatteryController module.
File containing Mock classes to test the SystemInfoProvider module.
Definition of the SystemManager class.
Class to test the integration between the SystemManager and the BatteryController,...
NiceMock< MockBatteryController > mockBatteryController
void TearDown() override
NiceMock< MockSystemInfoProvider > mockInfoProvider
Class that manages the system time, status, and battery. QObject.
void ipAddressUpdated(const QString &ipAddress)
void batteryPercentageUpdated(float batteryPercentage)
void wifiStatusUpdated(const QString &status, const QString &wifiName)
void timeUpdated(const QString &currentDate, const QString &currentTime, const QString &currentDay)
void temperatureUpdated(const QString &temperature)
TEST_F(SystemManagerTest, UpdateTime_EmitsCorrectSignal)
Ensures that the time is correctly updated.