Index: unittests/tst_models.cpp =================================================================== diff -u -r9cc1608f615e66d0f1c3a022aa6d19579d76b241 -rbf645acccabb7b5a84801620c4f7fa0b0e6878e0 --- unittests/tst_models.cpp (.../tst_models.cpp) (revision 9cc1608f615e66d0f1c3a022aa6d19579d76b241) +++ unittests/tst_models.cpp (.../tst_models.cpp) (revision bf645acccabb7b5a84801620c4f7fa0b0e6878e0) @@ -44,6 +44,8 @@ #include "MTreatmentAdjustUltrafiltrationConfirmResponse.h" #include "MAlarmStatusData.h" +#include "MAlarmTriggered.h" +#include "MAlarmCleared.h" // #define CONSOLEOUT @@ -379,18 +381,7 @@ } } -void tst_models::tst_MAlarmStatus() -{ - for (int i = 1; i < Gui::GuiAlarmID::NUM_OF_ALARM_IDS; ++i) { - QVERIFY(!Model::MAlarmStatus::toText(Gui::GuiAlarmID(i)).isEmpty()); - } - - QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(0)), tr("")); - QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(-1)), tr("Alarm Not Recognized.")); - QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(599)), tr("Alarm Not Recognized.")); -} - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DGROPumpData ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DGROPumpData data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // @@ -1248,4 +1239,140 @@ } } +void tst_models::tst_MAlarmStatus_text() +{ + for (int i = 1; i < Gui::GuiAlarmID::NUM_OF_ALARM_IDS; ++i) { + QVERIFY(!Model::MAlarmStatus::toText(Gui::GuiAlarmID(i)).isEmpty()); + } + + QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(0)), tr("")); + QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(-1)), tr("Alarm Not Recognized.")); + QCOMPARE(Model::MAlarmStatus::toText(Gui::GuiAlarmID(599)), tr("Alarm Not Recognized.")); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmStatus ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmStatus data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmStatus_data () { + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::newRow("msg complete") << 0 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F" "10" "11")); + QTest::newRow("mState ") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("mState ") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("mState ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("mState ") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); + QTest::newRow("mTop ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("mTop ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04")); + QTest::newRow("mTop ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05")); + QTest::newRow("mTop ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06")); + QTest::newRow("mEscalatesIn") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07")); + QTest::newRow("mEscalatesIn") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08")); + QTest::newRow("mEscalatesIn") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09")); + QTest::newRow("mEscalatesIn") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A")); + QTest::newRow("mMuteTimeout") << 4 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B")); + QTest::newRow("mMuteTimeout") << 4 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C")); + QTest::newRow("mMuteTimeout") << 4 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D")); + QTest::newRow("mMuteTimeout") << 4 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E")); + QTest::newRow("mFlags ") << 5 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F")); + QTest::newRow("mFlags ") << 5 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F" "10")); +} +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmStatus test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmStatus() { + Model::MAlarmStatus mData; + + QFETCH(int , errorIndex ); + QFETCH(QByteArray, data ); + + int startIndex = 0; + int index = errorIndex - 1; + bool ok = mData.fromByteArray(data, &startIndex); + Q_UNUSED(ok) +#ifdef CONSOLEOUT + qDebug() << index << errorIndex << startIndex << ok << data ; +#endif + + switch (errorIndex) { + case 0: { index = 0 ; QVERIFY ( mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 1: { index = index * sizeof mData._data.mState ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 2: { index = index * sizeof mData._data.mTop ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 3: { index = index * sizeof mData._data.mEscalatesIn; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 4: { index = index * sizeof mData._data.mMuteTimeout; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 5: { index = index * sizeof mData._data.mFlags ; QVERIFY (! mData.fromByteArray(data)); /* GetBits doesn't need this */} break; + default: + QVERIFY2(false, "Incorrect Test"); + break; + } +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmTriggered ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmTriggered data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmTriggered_data () { + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::newRow("msg complete") << 0 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); +} +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmTriggered test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmTriggered() { + Model::MAlarmTriggered mData; + + QFETCH(int , errorIndex ); + QFETCH(QByteArray, data ); + + int startIndex = 0; + int index = errorIndex - 1; + bool ok = mData.fromByteArray(data, &startIndex); + Q_UNUSED(ok) +#ifdef CONSOLEOUT + qDebug() << index << errorIndex << startIndex << ok << data ; +#endif + + switch (errorIndex) { + case 0: { index = 0 ; QVERIFY ( mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 1: { index = index * sizeof mData._data.mAlarmID; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + default: + QVERIFY2(false, "Incorrect Test"); + break; + } +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmCleared ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmCleared data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmCleared_data () { + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::newRow("msg complete") << 0 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("mAlarmID ") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); +} +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAlarmCleared test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MAlarmCleared() { + Model::MAlarmCleared mData; + + QFETCH(int , errorIndex ); + QFETCH(QByteArray, data ); + + int startIndex = 0; + int index = errorIndex - 1; + bool ok = mData.fromByteArray(data, &startIndex); + Q_UNUSED(ok) +#ifdef CONSOLEOUT + qDebug() << index << errorIndex << startIndex << ok << data ; +#endif + + switch (errorIndex) { + case 0: { index = 0 ; QVERIFY ( mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 1: { index = index * sizeof mData._data.mAlarmID; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + default: + QVERIFY2(false, "Incorrect Test"); + break; + } +}