15#include <QCoreApplication>
20#include <gtest/gtest.h>
30 static QCoreApplication *
app;
38 char *argv[] = {
nullptr};
39 app =
new QCoreApplication(argc, argv);
75 mileageManager->onSpeedUpdated(10.0f);
76 QCoreApplication::processEvents();
78 ASSERT_GT(spy.count(), 0);
79 QList<QVariant> args = spy.takeFirst();
80 EXPECT_DOUBLE_EQ(args.at(0).toDouble(), 10.0);
92 mileageManager->initialize();
95 QCoreApplication::processEvents();
96 ASSERT_GT(spy.count(), 0);
97 QList<QVariant> args = spy.takeFirst();
98 EXPECT_DOUBLE_EQ(args.at(0).toDouble(), 0.0);
112 mileageManager->onSpeedUpdated(10.0f);
113 QCoreApplication::processEvents();
115 ASSERT_GT(spy.count(), 0);
116 QList<QVariant> args = spy.takeFirst();
117 EXPECT_DOUBLE_EQ(args.at(0).toDouble(), 10.0);
129 mileageManager->onSpeedUpdated(5.0f);
130 QCoreApplication::processEvents();
132 mileageManager->saveMileage();
133 QCoreApplication::processEvents();
135 double savedMileage = mileageManager->getTotalMileage();
136 EXPECT_DOUBLE_EQ(savedMileage, 5.0);
150 mileageManager->initialize();
151 QTimer::singleShot(1000, QCoreApplication::instance(), &QCoreApplication::quit);
152 QCoreApplication::processEvents();
154 ASSERT_GT(spy.count(), 0);
166 mileageManager->initialize();
167 mileageManager->shutdown();
169 double finalMileage = mileageManager->getTotalMileage();
170 EXPECT_DOUBLE_EQ(finalMileage, 0.0);
Definition of the MileageCalculator class.
Definition of the MileageFileHandler class.
Definition of the MileageManager class.
Interface for calculating the mileage of a vehicle.
Interface for reading and writing the mileage of a vehicle to a file.
Class that calculates the total distance traveled based on speed measurements.
Class that manages the mileage file.
Class to test the integration between the MileageManager and the MileageCalculator and MileageFileHan...
MileageManager * mileageManager
static QCoreApplication * app
Initialize static member.
static void SetUpTestSuite()
static void TearDownTestSuite()
IMileageCalculator * calculator
IMileageFileHandler * fileHandler
Class that manages the mileage of a vehicle. QObject.
void mileageUpdated(double mileage)
TEST_F(MileageManagerTest, ForwardMileageData)
Ensures that the MileageManager forwards mileage data.