Cours:ClasseTestServoMoteur
Révision datée du 17 octobre 2025 à 16:46 par Bjacquot (discussion | contributions) (Page créée avec « {|style="vertical-align:middle; width:100%; text-align:left; " |- | {{boîte déroulante/début|titre=testservomoteur.h}} <source lang=cpp> #if... »)
#ifndef TESTSERVOMOTEUR_H
#define TESTSERVOMOTEUR_H
#include <QtTest/QTest>
#include <QObject>
class TestServoMoteur : public QObject
{
Q_OBJECT
public:
explicit TestServoMoteur(QObject *parent = nullptr);
private slots:
void setPosition_data();
void setPosition();
signals:
};
#endif // TESTSERVOMOTEUR_H
|
#include "testservomoteur.h"
#include "servomoteur.h"
#include <QFile>
TestServoMoteur::TestServoMoteur(QObject *parent)
: QObject{parent}
{}
void TestServoMoteur::setPosition_data()
{
QTest::addColumn<double>("offset_ms");
QTest::addColumn<double>("amp_ms");
QTest::addColumn<double>("angle");
QTest::addColumn<int>("duty");
QTest::newRow("") << 1.5 << 0.5 << 0.0 << 1500000;
QTest::newRow("") << 1.6 << 0.5 << 0.0 << 1600000;
QTest::newRow("") << 1.4 << 0.5 << 0.0 << 1400000;
QTest::newRow("") << 1.6 << 0.5 << 0.1 << 1650000;
QTest::newRow("") << 1.4 << 0.5 << -0.1 << 1350000;
QTest::newRow("") << 1.6 << 0.25 << 0.2 << 1650000;
QTest::newRow("") << 1.4 << 0.25 << -0.2 << 1350000;
}
void TestServoMoteur::setPosition()
{
QFETCH(double, offset_ms);
QFETCH(double, amp_ms);
QFETCH(double, angle);
QFETCH(int, duty);
ServoMoteur servo{offset_ms,amp_ms};
QFile fileDuty{"/sys/class/pwm/pwmchip2/pwm2/duty_cycle"};
QVERIFY(fileDuty.open(QIODevice::ReadOnly));
servo.setPosition(angle);
QCOMPARE(duty, fileDuty.readLine().toInt());
fileDuty.close();
}
|
//main.cpp
#include "testservomoteur.h"
QTEST_MAIN(TestServoMoteur)