Index: unittests/tst_models.cpp =================================================================== diff -u -rbab02bba94e43d8af860c206bdf27956aee3857a -refd63da6624955e82eb5a295ffd1e00c5c2f58ca --- unittests/tst_models.cpp (.../tst_models.cpp) (revision bab02bba94e43d8af860c206bdf27956aee3857a) +++ unittests/tst_models.cpp (.../tst_models.cpp) (revision efd63da6624955e82eb5a295ffd1e00c5c2f58ca) @@ -1764,23 +1764,83 @@ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAbstractDynamic ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAbstractDynamic data definition ~~~~~~~~~~~~~~~~~~~~~~~~ // void tst_models::tst_MAbstractDynamic_data () { - QTest::addColumn("errorIndex"); - QTest::addColumn("data"); - QTest::addColumn("expectedIndex"); + QTest::addColumn("errorIndex"); + QTest::addColumn("data"); + QTest::addColumn("expectedIndex"); + QTest::addColumn("expectedParameters"); - // The first 20Bytes of the data is for MAbstractDynamic before getting to the alarm triggered data - const QByteArray front20Bytes = QByteArray("00" "00" "00" "01" - "00" "00" "00" "02" - "00" "00" "00" "03" - "00" "00" "00" "04" - "00" "00" "00" "05" - ); + const QByteArray testFieldDescriptor1_U1 = QByteArray("00" "00" "00" "01" // mID + "01" "00" "00" "00" // mFieldDescriptor1 + ); + const QByteArray testFieldDescriptor1_S1 = QByteArray("00" "00" "00" "01" // mID + "02" "00" "00" "00" // mFieldDescriptor1 + ); + const QByteArray testFieldDescriptor1_F1 = QByteArray("00" "00" "00" "01" // mID + "03" "00" "00" "00" // mFieldDescriptor1 + ); + const QByteArray testFieldDescriptor1_BL = QByteArray("00" "00" "00" "01" // mID + "04" "00" "00" "00" // mFieldDescriptor1 + ); + + const QByteArray testFieldDescriptor2 = QByteArray("00" "00" "00" "01" // mID + "01" "00" "00" "00" // mFieldDescriptor1 + "02" "00" "00" "00" // mDataFieldU1 + ); + const QByteArray testFieldDescriptor2_U2 = QByteArray().append(testFieldDescriptor2).append("01" "00" "00" "00"); // mFieldDescriptor2 + const QByteArray testFieldDescriptor2_S2 = QByteArray().append(testFieldDescriptor2).append("02" "00" "00" "00"); // mFieldDescriptor2 + const QByteArray testFieldDescriptor2_F2 = QByteArray().append(testFieldDescriptor2).append("03" "00" "00" "00"); // mFieldDescriptor2 + const QByteArray testFieldDescriptor2_BL = QByteArray().append(testFieldDescriptor2).append("04" "00" "00" "00"); // mFieldDescriptor2 + + // ------------------------------------------------------------------ + // These data set are for testing the incomplete data, getting into the false case of GetValue() + // ------------------------------------------------------------------ + // test 1 to test x does not test MAbstractDynamic's parameters(), thus the expectedParameters are empty // 20 front bytes + 3 parameters * 4 bytes + 1 byte ending = 20 + 3*4 + 1 bytes - QTest::newRow("msg complete") << 0 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(20 + 3*4 + 1))<<0; + QTest::newRow("msg complete") << 0 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(20 + 3*4 + 1)) << 0 << QVariantList(); + QTest::newRow("msg mFieldDescriptor2 default Type case") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2)).append("00" "00" "00" "00") << 20 << QVariantList(); + QTest::newRow("msg mFieldDescriptor2 None Type case") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2).append("00" "00" "00" "00")) << 20 << QVariantList(); - QTest::newRow("msg incomplete mID") << 1 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(1))<<0; - QTest::newRow("msg incomplete mFieldDescriptor1") << 2 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(5))<<0; + const int numberIncompleteBytes = 3; // each field has 4 bytes to complete it, to hit the "incomplete" condition, we need to account for 3 front bytes + for(int byteCount = 1; byteCount <= numberIncompleteBytes; byteCount++) + { + QTest::newRow("msg incomplete mID") << 1 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(byteCount)) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor1") << 1 << QByteArray::fromHex(HelperFunctions_tstModel::createByteDataArray(byteCount+4)) << 0 << QVariantList(); + // mFieldDescriptor1 subFields + QTest::newRow("msg incomplete mFieldDescriptor1 mDataFieldU1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor1_U1).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor1 mDataFieldS1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor1_S1).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor1 mDataFieldF1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor1_F1).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor1 mDataFieldBL") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor1_BL).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + + // mFieldDescriptor2 subFields + QTest::newRow("msg incomplete mFieldDescriptor2 mDataFieldU1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2_U2).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor2 mDataFieldS1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2_S2).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor2 mDataFieldF1") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2_F2).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + QTest::newRow("msg incomplete mFieldDescriptor2 mDataFieldBL") << 1 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2_BL).append(HelperFunctions_tstModel::createByteDataArray(byteCount))) << 0 << QVariantList(); + } + + // ------------------------------------------------------------------ + // These data set are for testing the parameters() unreached cases + // ------------------------------------------------------------------ + quint32 zero = 0; + QVariantList testParameterFieldDescriptor2; + testParameterFieldDescriptor2 << 16777216 // mID + << 1 // mFieldDescriptor1 + << 2 // mDataFieldU1 + << zero << zero // values added for the default case in the field type switch statement + << zero << zero << zero; // the rank, priority, and cleartop + QTest::newRow("msg parameters - mFieldDescriptor2 none Type case") << 2 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2).append("00" "00" "00" "00")) << 20 << testParameterFieldDescriptor2; + QTest::newRow("msg parameters - mFieldDescriptor2 default Type case") << 2 << QByteArray::fromHex(QByteArray().append(testFieldDescriptor2).append("00" "00" "00" "01")) << 20 << testParameterFieldDescriptor2; + + QVariantList testParameterFieldDescriptor1; + testParameterFieldDescriptor1 << 16777216 // mID + << zero // mFieldDescriptor1 + << zero << zero << zero // values added for the default case in the field type switch statement + << zero << zero << zero; // the rank, priority, and cleartop + QTest::newRow("msg parameters - mFieldDescriptor1 default Type case") << 2 << QByteArray::fromHex(QByteArray("00" "00" "00" "01" // mID + "00" "00" "00" "01" // mFieldDescriptor1 + )) << 20 << testParameterFieldDescriptor1; + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAbstractDynamic test definition ~~~~~~~~~~~~~~~~~~~~~~~~ // // Will be testing MAbstractDynamic using MAlarmTriggered since MAlarmTriggered derives from MAbstractDynamic @@ -1790,6 +1850,7 @@ QFETCH(int , errorIndex ); QFETCH(QByteArray, data ); QFETCH(int , expectedIndex ); + QFETCH(QVariantList, expectedParameters); int startIndex = 0; // int index = errorIndex - 1; @@ -1800,19 +1861,28 @@ #endif switch (errorIndex) { + + // case 0 is for "complete" data tests case 0: { QVERIFY ( mData.fromByteArray(data)); QCOMPARE( expectedIndex, startIndex ); } break; - // incomplete case - case 1: // fall-through - incomplete mID - case 2: // fall-through - incomplete mFieldDescriptor1 - QVERIFY ( !mData.fromByteArray(data)); - QCOMPARE( expectedIndex, startIndex ); - break; + // case 1 is for "incomplete" data tests / partial byte set (ie: 3 bytes of 4 bytes of U32 exists) + case 1: { QVERIFY ( !mData.fromByteArray(data)); QCOMPARE( expectedIndex, startIndex ); } break; - case 3: - QVERIFY ( mData.fromByteArray(data)); - QCOMPARE( expectedIndex, startIndex ); - break; + // case 2 is testing parameters() call + case 2: + { + const QVariantList list = mData.parameters(); + bool sameLength = list.length() == expectedParameters.length(); + QVERIFY (sameLength); + if(sameLength){ + for(int i=0; i < mData.parameters().length(); i++) + { + QVERIFY(list.at(i) == expectedParameters.at(i)); + } + } + + } break; + default: QVERIFY2(false, "Incorrect Test"); break;