Index: unittests/tst_models.cpp =================================================================== diff -u -rc8b2c06141831ba2908323138d94dec0ccc0d402 -r14c541d2b780b0a244bc84860aa565cf8dd7fe4b --- unittests/tst_models.cpp (.../tst_models.cpp) (revision c8b2c06141831ba2908323138d94dec0ccc0d402) +++ unittests/tst_models.cpp (.../tst_models.cpp) (revision 14c541d2b780b0a244bc84860aa565cf8dd7fe4b) @@ -39,6 +39,7 @@ #include "MTreatmentTimeData.h" #include "MTreatmentPressureOcclusionData.h" #include "MTreatmentSalineData.h" +#include "MPrimingData.h" #include "MTreatmentAdjustUltrafiltrationStateResponse.h" #include "MTreatmentAdjustUltrafiltrationEditResponse.h" @@ -50,9 +51,14 @@ #include "MAlarmTriggered.h" #include "MAlarmCleared.h" -#include "MTreatmentParameters.h" #include "MTreatmentParametersResp.h" +#include "MStartTreatmentResponse.h" +#include "MEndTreatmentResponse.h" +#include "MessageInterpreter.h" + +using namespace Can; + #undef CONSOLEOUT /*! @@ -992,7 +998,7 @@ void tst_models::tst_MOutletFlowData_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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); + 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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); QTest::newRow("mRefUFVol ") << 1 << QByteArray::fromHex(QByteArray()); QTest::newRow("mRefUFVol ") << 1 << QByteArray::fromHex(QByteArray("00")); QTest::newRow("mRefUFVol ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); @@ -1058,7 +1064,7 @@ void tst_models::tst_MBloodFlowData_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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); + 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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray()); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray("00")); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); @@ -1124,7 +1130,7 @@ void tst_models::tst_MDialysateFlowData_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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); + 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" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B")); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray()); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray("00")); QTest::newRow("mFlowSetPoint ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); @@ -1236,7 +1242,7 @@ void tst_models::tst_MPressureOcclusionData_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" "12" "13")); + 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" "12" "13")); QTest::newRow("mArterialPressure ") << 1 << QByteArray::fromHex(QByteArray()); QTest::newRow("mArterialPressure ") << 1 << QByteArray::fromHex(QByteArray("00")); QTest::newRow("mArterialPressure ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); @@ -1457,6 +1463,9 @@ } } + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MTreatmentParametersResp test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MTreatmentParametersResp data definition ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void tst_models::tst_MTreatmentParametersResp_data() { QTest::addColumn("errorIndex"); @@ -1536,6 +1545,7 @@ QTest::newRow("rinsebackFlowRate") << 18 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2B" "2C" "2D" "2E" "2F" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F" "40" "41" "42" "43" "44" "45" "46" "47")); } +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MTreatmentParametersResp test definition ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void tst_models::tst_MTreatmentParametersResp() { Model::MTreatmentParametersResponse mData; @@ -1627,113 +1637,132 @@ } } -void tst_models::tst_MTreatmentParametersResp_fromVariantList() -{ - Model::MTreatmentParametersResponse mData; +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MPrimingData ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MPrimingData data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MPrimingData_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")); + QTest::newRow("currentState ") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("currentState ") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("currentState ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("currentState ") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); + QTest::newRow("secondsRemaining ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("secondsRemaining ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04")); + QTest::newRow("secondsRemaining ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05")); + QTest::newRow("secondsRemaining ") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06")); + QTest::newRow("secondsTotal ") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07")); + QTest::newRow("secondsTotal ") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08")); + QTest::newRow("secondsTotal ") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09")); + QTest::newRow("secondsTotal ") << 3 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A")); +} - QVariantList list; - for (int i = 0; i < 20; ++i) - { +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MPrimingData test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MPrimingData() { + Model::MPrimingData mData; - list.append(QVariant(1)); - AdjustTreatmentParametersResponseData tempData = mData.fromVariantList(list); - if (i == 17) { - QVERIFY(1 == tempData.requestValid); - QVERIFY(1 == tempData.bloodFlowRate); - QVERIFY(1 == tempData.dialysateFlowRate); - QVERIFY(1 == tempData.duration); - QVERIFY(1 == tempData.heparinDispensingRate); - QVERIFY(1 == tempData.heparinBolusVolume); - QVERIFY(1 == tempData.heparinStopTime); - QVERIFY(1 == tempData.salineBolus); - QVERIFY(1 == tempData.acidConcentrate); - QVERIFY(1 == tempData.bicarbonateConcentrate); - QVERIFY(1 == tempData.dialyzerType); - QVERIFY(1 == tempData.dialysateTemp); - QVERIFY(1 == tempData.arterialPressureLimitLow); - QVERIFY(1 == tempData.arterialPressureLimitHigh); - QVERIFY(1 == tempData.venousPressureLimitLow); - QVERIFY(1 == tempData.venousPressureLimitHigh); - QVERIFY(1 == tempData.bloodPressureMeasureInterval); - QVERIFY(1 == tempData.rinsebackFlowRate); - } - else { - AdjustTreatmentParametersResponseData data; - QVERIFY(data.requestValid == tempData.requestValid); - QVERIFY(data.bloodFlowRate == tempData.bloodFlowRate); - QVERIFY(data.dialysateFlowRate == tempData.dialysateFlowRate); - QVERIFY(data.duration == tempData.duration); - QVERIFY(data.heparinDispensingRate == tempData.heparinDispensingRate); - QVERIFY(data.heparinBolusVolume == tempData.heparinBolusVolume); - QVERIFY(data.heparinStopTime == tempData.heparinStopTime); - QVERIFY(data.salineBolus == tempData.salineBolus); - QVERIFY(data.acidConcentrate == tempData.acidConcentrate); - QVERIFY(data.bicarbonateConcentrate == tempData.bicarbonateConcentrate); - QVERIFY(data.dialyzerType == tempData.dialyzerType); - QVERIFY(data.dialysateTemp == tempData.dialysateTemp); - QVERIFY(data.arterialPressureLimitLow == tempData.arterialPressureLimitLow); - QVERIFY(data.arterialPressureLimitHigh == tempData.arterialPressureLimitHigh); - QVERIFY(data.venousPressureLimitLow == tempData.venousPressureLimitLow); - QVERIFY(data.venousPressureLimitHigh == tempData.venousPressureLimitHigh); - QVERIFY(data.bloodPressureMeasureInterval== tempData.bloodPressureMeasureInterval); - QVERIFY(data.rinsebackFlowRate == tempData.rinsebackFlowRate); + 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.currentState ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 2: { index = index * sizeof mData._data.secondsRemaining ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 3: { index = index * sizeof mData._data.secondsTotal ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + default: + QVERIFY2(false, "Incorrect Test"); + break; } } -void tst_models::tst_MTreatmentParameters_fromVariantList() -{ - Model::MAdjustTreatmentParametersRequest mData; +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MStartTreatmentResponse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MStartTreatmentResponse data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MStartTreatmentResponse_data () { + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::newRow("msg complete ") << 0 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06" "07")); + QTest::newRow("startTreatmentResponse ") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("startTreatmentResponse ") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("startTreatmentResponse ") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("startTreatmentResponse ") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); + QTest::newRow("startTreatmentRejectReason") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("startTreatmentRejectReason") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04")); + QTest::newRow("startTreatmentRejectReason") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05")); + QTest::newRow("startTreatmentRejectReason") << 2 << QByteArray::fromHex(QByteArray("00" "01" "02" "03" "04" "05" "06")); +} - QVariantList list; - for (int i = 0; i < 20; ++i) - { +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MStartTreatmentResponse test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MStartTreatmentResponse() { + Model::MStartTreatmentResponse mData; - list.append(QVariant(1)); - AdjustTreatmentParametersRequestData tempData = mData.fromVariantList(list); - if (i == 16) { - QVERIFY(1 == tempData.bloodFlowRate); - QVERIFY(1 == tempData.dialysateFlowRate); - QVERIFY(1 == tempData.duration); - QVERIFY(1 == tempData.heparinDispensingRate); - QVERIFY(1 == tempData.heparinBolusVolume); - QVERIFY(1 == tempData.heparinStopTime); - QVERIFY(1 == tempData.salineBolus); - QVERIFY(1 == tempData.acidConcentrate); - QVERIFY(1 == tempData.bicarbonateConcentrate); - QVERIFY(1 == tempData.dialyzerType); - QVERIFY(1 == tempData.dialysateTemp); - QVERIFY(1 == tempData.arterialPressureLimitLow); - QVERIFY(1 == tempData.arterialPressureLimitHigh); - QVERIFY(1 == tempData.venousPressureLimitLow); - QVERIFY(1 == tempData.venousPressureLimitHigh); - QVERIFY(1 == tempData.bloodPressureMeasureInterval); - QVERIFY(1 == tempData.rinsebackFlowRate); - } - else { - AdjustTreatmentParametersRequestData data; - QVERIFY(data.bloodFlowRate == tempData.bloodFlowRate); - QVERIFY(data.dialysateFlowRate == tempData.dialysateFlowRate); - QVERIFY(data.duration == tempData.duration); - QVERIFY(data.heparinDispensingRate == tempData.heparinDispensingRate); - QVERIFY(data.heparinBolusVolume == tempData.heparinBolusVolume); - QVERIFY(data.heparinStopTime == tempData.heparinStopTime); - QVERIFY(data.salineBolus == tempData.salineBolus); - QVERIFY(data.acidConcentrate == tempData.acidConcentrate); - QVERIFY(data.bicarbonateConcentrate == tempData.bicarbonateConcentrate); - QVERIFY(data.dialyzerType == tempData.dialyzerType); - QVERIFY(data.dialysateTemp == tempData.dialysateTemp); - QVERIFY(data.arterialPressureLimitLow == tempData.arterialPressureLimitLow); - QVERIFY(data.arterialPressureLimitHigh == tempData.arterialPressureLimitHigh); - QVERIFY(data.venousPressureLimitLow == tempData.venousPressureLimitLow); - QVERIFY(data.venousPressureLimitHigh == tempData.venousPressureLimitHigh); - QVERIFY(data.bloodPressureMeasureInterval== tempData.bloodPressureMeasureInterval); - QVERIFY(data.rinsebackFlowRate == tempData.rinsebackFlowRate); + 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.startTreatmentResponse ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + case 2: { index = index * sizeof mData._data.startTreatmentRejectReason ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + default: + QVERIFY2(false, "Incorrect Test"); + break; } } + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MEndTreatmentResponse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MEndTreatmentResponse data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MEndTreatmentResponse_data () { + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::newRow("msg complete ") << 0 << QByteArray::fromHex(QByteArray("00" "01" "02" "03")); + QTest::newRow("endTreatmentResponse") << 1 << QByteArray::fromHex(QByteArray()); + QTest::newRow("endTreatmentResponse") << 1 << QByteArray::fromHex(QByteArray("00")); + QTest::newRow("endTreatmentResponse") << 1 << QByteArray::fromHex(QByteArray("00" "01")); + QTest::newRow("endTreatmentResponse") << 1 << QByteArray::fromHex(QByteArray("00" "01" "02")); +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MEndTreatmentResponse test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // +void tst_models::tst_MEndTreatmentResponse() { + Model::MEndTreatmentResponse 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.endTreatmentResponse ; QVERIFY (! mData.fromByteArray(data)); QCOMPARE( index, startIndex ); } break; + default: + QVERIFY2(false, "Incorrect Test"); + break; + } +} + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MSalineBolusResponse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MSalineBolusResponse data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // @@ -1784,3 +1813,49 @@ break; } } + +void tst_models::tst_MAlarmAcknowledgeRequest() +{ + MessageInterpreter interpreter; + QVariantList vData; + QByteArray payload; + QVERIFY(!interpreter.interpretMessage(Gui::GuiActions::ID_AlarmUserAckReq, vData, payload)); +} + +void tst_models::tst_MStartTreatmentRequest() +{ + MessageInterpreter interpreter; + QVariantList vData; + QByteArray payload; + QVERIFY(!interpreter.interpretMessage(Gui::GuiActions::ID_StartTreatmentReq, vData, payload)); +} + +void tst_models::tst_MConfirmTreatmentRequest() +{ + MessageInterpreter interpreter; + QVariantList vData; + QByteArray payload; + QVERIFY(!interpreter.interpretMessage(Gui::GuiActions::ID_ConfirmTreatmentReq, vData, payload)); +} + +void tst_models::tst_MEndTreatmentRequest() +{ + MessageInterpreter interpreter; + QVariantList vData; + QByteArray payload; + Message msg; + msg.actionId = Gui::GuiActions::ID_EndTreatmentReq; + + QVERIFY(interpreter.interpretMessage(Gui::GuiActions::ID_EndTreatmentReq, vData, payload)); + QVERIFY(!interpreter.interpretMessage_HD(msg,vData)); + vData.append(0); + QVERIFY(!interpreter.interpretMessage(Gui::GuiActions::ID_EndTreatmentReq, vData, payload)); +} + +void tst_models::tst_MAdjustmentTreatmentParametersRequest() +{ + MessageInterpreter interpreter; + QVariantList vData; + QByteArray payload; + QVERIFY(!interpreter.interpretMessage(Gui::GuiActions::ID_CreateTreatmentReq, vData, payload)); +}