Skip to content

Commit

Permalink
Add missing DeviceCommand unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolby committed Nov 25, 2023
1 parent 94cc96e commit c2a84f4
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cli/devicecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ template<> PokitPro::VoltageRange DeviceCommand::minRange(const quint32 maxValue
/// \endcond

/*!
* Returns the \a product's lowest capacitance range that can measure at least up to \a maxValue, or AutoRange if no
* such range is available.
* Returns the \a product's lowest capacitance range that can measure at least up to \a maxValue (nF), or AutoRange if
* no such range is available.
*
* \note Since Pokit Meters do not support capacitance measurement, \a product should not be PokitProduct::PokitMeter.
*
Expand All @@ -224,7 +224,7 @@ quint8 DeviceCommand::minCapacitanceRange(const PokitProduct product, const quin
}

/*!
* Returns the \a product's lowest current range that can measure at least up to \a maxValue, or AutoRange if no
* Returns the \a product's lowest current range that can measure at least up to \a maxValue (µA), or AutoRange if no
* such range is available.
*
* \see DeviceCommand::minRange<PokitMeter::CurrentRange>(const quint32 maxValue)
Expand All @@ -243,7 +243,7 @@ quint8 DeviceCommand::minCurrentRange(const PokitProduct product, const quint32
}

/*!
* Returns the \a product's lowest resistance range that can measure at least up to \a maxValue, or AutoRange if no
* Returns the \a product's lowest resistance range that can measure at least up to \a maxValue (Ω), or AutoRange if no
* such range is available.
*
* \see DeviceCommand::minRange<PokitMeter::ResistanceRange>(const quint32 maxValue)
Expand All @@ -263,7 +263,7 @@ quint8 DeviceCommand::minResistanceRange(const PokitProduct product, const quint

/*!
t
* Returns the \a product's lowest voltage range that can measure at least up to \a maxValue, or AutoRange if no
* Returns the \a product's lowest voltage range that can measure at least up to \a maxValue (mV), or AutoRange if no
* such range is available.
*
* \see DeviceCommand::minRange<PokitMeter::VoltageRange>(const quint32 maxValue)
Expand Down
262 changes: 262 additions & 0 deletions test/unit/cli/testdevicecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#include "devicecommand.h"

#include <qtpokit/statusservice.h>
#include <qtpokit/pokitmeter.h>
#include <qtpokit/pokitpro.h>

Q_DECLARE_METATYPE(PokitMeter::CurrentRange)
Q_DECLARE_METATYPE(PokitMeter::ResistanceRange)
Q_DECLARE_METATYPE(PokitMeter::VoltageRange)
Q_DECLARE_METATYPE(PokitPro::CapacitanceRange)
Q_DECLARE_METATYPE(PokitPro::CurrentRange)
Q_DECLARE_METATYPE(PokitPro::ResistanceRange)
Q_DECLARE_METATYPE(PokitPro::VoltageRange)

class MockDeviceCommand : public DeviceCommand
{
Expand Down Expand Up @@ -50,6 +60,258 @@ void TestDeviceCommand::disconnect()
// Cannot test DeviceCommand::disconnect() without a valid device controller.
}

void TestDeviceCommand::minRange_meter_current_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitMeter::CurrentRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitMeter::CurrentRange::AutoRange;
QTest::addRow("1μA") << (quint32) 1 << PokitMeter::CurrentRange::_10mA;
QTest::addRow("10mA") << (quint32) 10000 << PokitMeter::CurrentRange::_10mA;
QTest::addRow("10mA++") << (quint32) 10001 << PokitMeter::CurrentRange::_30mA;
QTest::addRow("30mA") << (quint32) 30000 << PokitMeter::CurrentRange::_30mA;
QTest::addRow("30mA++") << (quint32) 30001 << PokitMeter::CurrentRange::_150mA;
QTest::addRow("150mA") << (quint32) 150000 << PokitMeter::CurrentRange::_150mA;
QTest::addRow("150mA++") << (quint32) 150001 << PokitMeter::CurrentRange::_300mA;
QTest::addRow("300mA") << (quint32) 300000 << PokitMeter::CurrentRange::_300mA;
QTest::addRow("300mA++") << (quint32) 300001 << PokitMeter::CurrentRange::_2A;
QTest::addRow("2A") << (quint32)2000000 << PokitMeter::CurrentRange::_2A;
QTest::addRow("2A++") << (quint32)2000001 << PokitMeter::CurrentRange::AutoRange;
}

void TestDeviceCommand::minRange_meter_current()
{
QFETCH(quint32, maxValue);
QFETCH(PokitMeter::CurrentRange, expected);
const auto actual = DeviceCommand::minRange<PokitMeter::CurrentRange>(maxValue);
QCOMPARE(PokitMeter::toString(actual), PokitMeter::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_meter_resistance_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitMeter::ResistanceRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitMeter::ResistanceRange::AutoRange;
QTest::addRow("") << (quint32) 1 << PokitMeter::ResistanceRange::_160;
QTest::addRow("160Ω") << (quint32) 160 << PokitMeter::ResistanceRange::_160;
QTest::addRow("160Ω++") << (quint32) 161 << PokitMeter::ResistanceRange::_330;
QTest::addRow("330Ω") << (quint32) 330 << PokitMeter::ResistanceRange::_330;
QTest::addRow("330Ω++") << (quint32) 331 << PokitMeter::ResistanceRange::_890;
QTest::addRow("890Ω") << (quint32) 890 << PokitMeter::ResistanceRange::_890;
QTest::addRow("890Ω++") << (quint32) 891 << PokitMeter::ResistanceRange::_1K5;
QTest::addRow("1K5Ω") << (quint32) 1500 << PokitMeter::ResistanceRange::_1K5;
QTest::addRow("1K5++") << (quint32) 1501 << PokitMeter::ResistanceRange::_10K;
QTest::addRow("10KΩ") << (quint32) 10000 << PokitMeter::ResistanceRange::_10K;
QTest::addRow("10KΩ++") << (quint32) 10001 << PokitMeter::ResistanceRange::_100K;
QTest::addRow("100KΩ") << (quint32) 100000 << PokitMeter::ResistanceRange::_100K;
QTest::addRow("100KΩ++") << (quint32) 100001 << PokitMeter::ResistanceRange::_470K;
QTest::addRow("470KΩ") << (quint32) 470000 << PokitMeter::ResistanceRange::_470K;
QTest::addRow("470KΩ++") << (quint32) 470001 << PokitMeter::ResistanceRange::_1M;
QTest::addRow("1MΩ") << (quint32)1000000 << PokitMeter::ResistanceRange::_1M;
QTest::addRow("1MΩ++") << (quint32)1000001 << PokitMeter::ResistanceRange::AutoRange;
}

void TestDeviceCommand::minRange_meter_resistance()
{
QFETCH(quint32, maxValue);
QFETCH(PokitMeter::ResistanceRange, expected);
const auto actual = DeviceCommand::minRange<PokitMeter::ResistanceRange>(maxValue);
QCOMPARE(PokitMeter::toString(actual), PokitMeter::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_meter_voltage_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitMeter::VoltageRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitMeter::VoltageRange::AutoRange;
QTest::addRow("1mV") << (quint32) 1 << PokitMeter::VoltageRange::_300mV;
QTest::addRow("300mV") << (quint32) 300 << PokitMeter::VoltageRange::_300mV;
QTest::addRow("300mV++") << (quint32) 301 << PokitMeter::VoltageRange::_2V;
QTest::addRow("2V") << (quint32) 2000 << PokitMeter::VoltageRange::_2V;
QTest::addRow("2V++") << (quint32) 2001 << PokitMeter::VoltageRange::_6V;
QTest::addRow("6V") << (quint32) 6000 << PokitMeter::VoltageRange::_6V;
QTest::addRow("6V++") << (quint32) 6001 << PokitMeter::VoltageRange::_12V;
QTest::addRow("12V") << (quint32)12000 << PokitMeter::VoltageRange::_12V;
QTest::addRow("12V++") << (quint32)12001 << PokitMeter::VoltageRange::_30V;
QTest::addRow("30V") << (quint32)30000 << PokitMeter::VoltageRange::_30V;
QTest::addRow("30V++") << (quint32)30001 << PokitMeter::VoltageRange::_60V;
QTest::addRow("60V") << (quint32)60000 << PokitMeter::VoltageRange::_60V;
QTest::addRow("60V++") << (quint32)60001 << PokitMeter::VoltageRange::AutoRange;
}

void TestDeviceCommand::minRange_meter_voltage()
{
QFETCH(quint32, maxValue);
QFETCH(PokitMeter::VoltageRange, expected);
const auto actual = DeviceCommand::minRange<PokitMeter::VoltageRange>(maxValue);
QCOMPARE(PokitMeter::toString(actual), PokitMeter::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_pro_capacitance_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitPro::CapacitanceRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitPro::CapacitanceRange::AutoRange;
QTest::addRow("1nF") << (quint32) 1 << PokitPro::CapacitanceRange::_100nF;
QTest::addRow("100nF") << (quint32) 100 << PokitPro::CapacitanceRange::_100nF;
QTest::addRow("100nF++") << (quint32) 101 << PokitPro::CapacitanceRange::_10uF;
QTest::addRow("10μF") << (quint32) 10000 << PokitPro::CapacitanceRange::_10uF;
QTest::addRow("10μF++") << (quint32) 10001 << PokitPro::CapacitanceRange::_1mF;
QTest::addRow("1mF") << (quint32)1000000 << PokitPro::CapacitanceRange::_1mF;
QTest::addRow("1mF++") << (quint32)1000001 << PokitPro::CapacitanceRange::AutoRange;
}

void TestDeviceCommand::minRange_pro_capacitance()
{
QFETCH(quint32, maxValue);
QFETCH(PokitPro::CapacitanceRange, expected);
const auto actual = DeviceCommand::minRange<PokitPro::CapacitanceRange>(maxValue);
QCOMPARE(PokitPro::toString(actual), PokitPro::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_pro_current_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitPro::CurrentRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitPro::CurrentRange::AutoRange;
QTest::addRow("1μA") << (quint32) 1 << PokitPro::CurrentRange::_500uA;
QTest::addRow("500μA") << (quint32) 500 << PokitPro::CurrentRange::_500uA;
QTest::addRow("500μA++") << (quint32) 501 << PokitPro::CurrentRange::_2mA;
QTest::addRow("2mA") << (quint32) 2000 << PokitPro::CurrentRange::_2mA;
QTest::addRow("2mA++") << (quint32) 2001 << PokitPro::CurrentRange::_10mA;
QTest::addRow("10mA") << (quint32) 10000 << PokitPro::CurrentRange::_10mA;
QTest::addRow("10mA++") << (quint32) 10001 << PokitPro::CurrentRange::_125mA;
QTest::addRow("125mA") << (quint32) 125000 << PokitPro::CurrentRange::_125mA;
QTest::addRow("125mA++") << (quint32) 125001 << PokitPro::CurrentRange::_300mA;
QTest::addRow("300mA") << (quint32) 300000 << PokitPro::CurrentRange::_300mA;
QTest::addRow("300mA++") << (quint32) 300001 << PokitPro::CurrentRange::_3A;
QTest::addRow("3A") << (quint32) 3000000 << PokitPro::CurrentRange::_3A;
QTest::addRow("3A++") << (quint32) 3000001 << PokitPro::CurrentRange::_10A;
QTest::addRow("10A") << (quint32)10000000 << PokitPro::CurrentRange::_10A;
QTest::addRow("10A++") << (quint32)10000001 << PokitPro::CurrentRange::AutoRange;
}

void TestDeviceCommand::minRange_pro_current()
{
QFETCH(quint32, maxValue);
QFETCH(PokitPro::CurrentRange, expected);
const auto actual = DeviceCommand::minRange<PokitPro::CurrentRange>(maxValue);
QCOMPARE(PokitPro::toString(actual), PokitPro::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_pro_resistance_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitPro::ResistanceRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitPro::ResistanceRange::AutoRange;
QTest::addRow("") << (quint32) 1 << PokitPro::ResistanceRange::_30;
QTest::addRow("30Ω") << (quint32) 30 << PokitPro::ResistanceRange::_30;
QTest::addRow("30Ω++") << (quint32) 31 << PokitPro::ResistanceRange::_75;
QTest::addRow("75Ω") << (quint32) 75 << PokitPro::ResistanceRange::_75;
QTest::addRow("75Ω++") << (quint32) 76 << PokitPro::ResistanceRange::_400;
QTest::addRow("400Ω") << (quint32) 400 << PokitPro::ResistanceRange::_400;
QTest::addRow("400Ω++") << (quint32) 401 << PokitPro::ResistanceRange::_5K;
QTest::addRow("5KΩ") << (quint32) 5000 << PokitPro::ResistanceRange::_5K;
QTest::addRow("5KΩ++") << (quint32) 5001 << PokitPro::ResistanceRange::_10K;
QTest::addRow("10KΩ") << (quint32) 10000 << PokitPro::ResistanceRange::_10K;
QTest::addRow("10KΩ++") << (quint32) 10001 << PokitPro::ResistanceRange::_15K;
QTest::addRow("15KΩ") << (quint32) 15000 << PokitPro::ResistanceRange::_15K;
QTest::addRow("15KΩ++") << (quint32) 15001 << PokitPro::ResistanceRange::_40K;
QTest::addRow("40KΩ") << (quint32) 40000 << PokitPro::ResistanceRange::_40K;
QTest::addRow("40KΩ++") << (quint32) 40001 << PokitPro::ResistanceRange::_500K;
QTest::addRow("500KΩ") << (quint32) 500000 << PokitPro::ResistanceRange::_500K;
QTest::addRow("500KΩ++") << (quint32) 500001 << PokitPro::ResistanceRange::_700K;
QTest::addRow("700KΩ") << (quint32) 700000 << PokitPro::ResistanceRange::_700K;
QTest::addRow("700KΩ++") << (quint32) 700001 << PokitPro::ResistanceRange::_1M;
QTest::addRow("1MΩ") << (quint32)1000000 << PokitPro::ResistanceRange::_1M;
QTest::addRow("1MΩ++") << (quint32)1000001 << PokitPro::ResistanceRange::_3M;
QTest::addRow("3MΩ") << (quint32)3000000 << PokitPro::ResistanceRange::_3M;
QTest::addRow("3MΩ++") << (quint32)3000001 << PokitPro::ResistanceRange::AutoRange;
}

void TestDeviceCommand::minRange_pro_resistance()
{
QFETCH(quint32, maxValue);
QFETCH(PokitPro::ResistanceRange, expected);
const auto actual = DeviceCommand::minRange<PokitPro::ResistanceRange>(maxValue);
QCOMPARE(PokitPro::toString(actual), PokitPro::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minRange_pro_voltage_data()
{
QTest::addColumn<quint32>("maxValue");
QTest::addColumn<PokitPro::VoltageRange>("expected");

QTest::addRow("0") << (quint32) 0 << PokitPro::VoltageRange::AutoRange;
QTest::addRow("1mV") << (quint32) 1 << PokitPro::VoltageRange::_250mV;
QTest::addRow("250mV") << (quint32) 250 << PokitPro::VoltageRange::_250mV;
QTest::addRow("250mV++") << (quint32) 251 << PokitPro::VoltageRange::_2V;
QTest::addRow("2V") << (quint32) 2000 << PokitPro::VoltageRange::_2V;
QTest::addRow("2V++") << (quint32) 2001 << PokitPro::VoltageRange::_10V;
QTest::addRow("10V") << (quint32) 10000 << PokitPro::VoltageRange::_10V;
QTest::addRow("10V++") << (quint32) 10001 << PokitPro::VoltageRange::_30V;
QTest::addRow("30V") << (quint32) 30000 << PokitPro::VoltageRange::_30V;
QTest::addRow("30V++") << (quint32) 30001 << PokitPro::VoltageRange::_60V;
QTest::addRow("60V") << (quint32) 60000 << PokitPro::VoltageRange::_60V;
QTest::addRow("60V++") << (quint32) 60001 << PokitPro::VoltageRange::_125V;
QTest::addRow("125V") << (quint32)125000 << PokitPro::VoltageRange::_125V;
QTest::addRow("125V++") << (quint32)125001 << PokitPro::VoltageRange::_400V;
QTest::addRow("400V") << (quint32)400000 << PokitPro::VoltageRange::_400V;
QTest::addRow("400V++") << (quint32)400001 << PokitPro::VoltageRange::_600V;
QTest::addRow("600V") << (quint32)600000 << PokitPro::VoltageRange::_600V;
QTest::addRow("600V++") << (quint32)600001 << PokitPro::VoltageRange::AutoRange;
}

void TestDeviceCommand::minRange_pro_voltage()
{
QFETCH(quint32, maxValue);
QFETCH(PokitPro::VoltageRange, expected);
const auto actual = DeviceCommand::minRange<PokitPro::VoltageRange>(maxValue);
QCOMPARE(PokitPro::toString(actual), PokitPro::toString(expected));
QVERIFY(actual == expected);
}

void TestDeviceCommand::minCapacitanceRange()
{
const quint8 actual = DeviceCommand::minCapacitanceRange(PokitProduct::PokitPro, 123456);
QCOMPARE(actual, (quint8)PokitPro::CapacitanceRange::_1mF);
}

void TestDeviceCommand::minCurrentRange()
{
quint8 actual = DeviceCommand::minCurrentRange(PokitProduct::PokitMeter, 123456);
QCOMPARE(actual, (quint8)PokitMeter::CurrentRange::_150mA);
actual = DeviceCommand::minCurrentRange(PokitProduct::PokitPro, 123456);
QCOMPARE(actual, (quint8)PokitPro::CurrentRange::_125mA);
}

void TestDeviceCommand::minResistanceRange()
{
quint8 actual = DeviceCommand::minResistanceRange(PokitProduct::PokitMeter, 123456);
QCOMPARE(actual, (quint8)PokitMeter::ResistanceRange::_470K);
actual = DeviceCommand::minResistanceRange(PokitProduct::PokitPro, 123456);
QCOMPARE(actual, (quint8)PokitPro::ResistanceRange::_500K);
}

void TestDeviceCommand::minVoltageRange()
{
quint8 actual = DeviceCommand::minVoltageRange(PokitProduct::PokitMeter, 12345);
QCOMPARE(actual, (quint8)PokitMeter::VoltageRange::_30V);
actual = DeviceCommand::minVoltageRange(PokitProduct::PokitPro, 123456);
QCOMPARE(actual, (quint8)PokitPro::VoltageRange::_125V);
}

void TestDeviceCommand::controllerError()
{
MockDeviceCommand command;
Expand Down
29 changes: 29 additions & 0 deletions test/unit/cli/testdevicecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ private slots:

void disconnect();

void minRange_meter_current_data();
void minRange_meter_current();

void minRange_meter_resistance_data();
void minRange_meter_resistance();

void minRange_meter_voltage_data();
void minRange_meter_voltage();

void minRange_pro_capacitance_data();
void minRange_pro_capacitance();

void minRange_pro_current_data();
void minRange_pro_current();

void minRange_pro_resistance_data();
void minRange_pro_resistance();

void minRange_pro_voltage_data();
void minRange_pro_voltage();

void minCapacitanceRange();

void minCurrentRange();

void minResistanceRange();

void minVoltageRange();

void controllerError();

void deviceDisconnected();
Expand Down

0 comments on commit c2a84f4

Please sign in to comment.