Commit 18356ed0 authored by Thomas Braun's avatar Thomas Braun
Browse files

test: Add FreePropertyHistoryWorks

parent 71ecdcaf
Loading
Loading
Loading
Loading
+185 −0
Original line number Diff line number Diff line
@@ -352,6 +352,191 @@ BOOST_AUTO_TEST_CASE(DbPutPropertyWorks)
    }
}

BOOST_AUTO_TEST_CASE(FreePropertyHistoryWorks)
{
    const std::string objName{"globalObj"};
    const std::string propName{"propName0"};

    // write more entries than the history can hold
    size_t numEntries = DEFAULT_HISTORY_DEPTH + 1;

    // scalar property
    for(size_t i = 0; i < numEntries; i++)
    {
        std::string propValue = "prop0Value";
        propValue += std::to_string(i);

        auto in = MakeDeviceDataStringArray({objName, "1", propName, "1", propValue});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbPutProperty", in));
    }

    // propName1 with vector values, adding a different property does not influence the history depth of propName0
    for(size_t i = 0; i < numEntries; i++)
    {
        std::string propValue = "prop1ValueVec";
        propValue += std::to_string(i);

        auto in = MakeDeviceDataStringArray({objName, "1", "propName1", "2", propValue + "_0", propValue + "_1"});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbPutProperty", in));
    }

    // also if we now add a new vector value entry for propName0 we still get DEFAULT_HISTORY_DEPTH back below
    {
        std::string propValue = "prop0ValueVec0";

        auto in = MakeDeviceDataStringArray({objName, "1", propName, "2", propValue + "_0", propValue + "_1"});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbPutProperty", in));
    }

    // and check that the first value "propValue0" and "propValue1" was forgotten
    {
        auto in = MakeDeviceDataStringArray({objName, propName});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbGetPropertyHist", in));
        auto vec = ExtractStringVector(reply);

        // replace volatile data
        vec[1] = "fakeDate";
        vec[5] = "fakeDate";
        vec[9] = "fakeDate";
        vec[13] = "fakeDate";
        vec[17] = "fakeDate";
        vec[21] = "fakeDate";
        vec[25] = "fakeDate";
        vec[29] = "fakeDate";
        vec[33] = "fakeDate";
        vec[37] = "fakeDate";
        // clang-format off
        std::vector<std::string> ref = {
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value2",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value3",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value4",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value5",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value6",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value7",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value8",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value9",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value10",
                                        propName,
                                        "fakeDate",
                                        "2",
                                        "prop0ValueVec0_0",
                                        "prop0ValueVec0_1"
                                       };
        // clang-format on
        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(ref), std::end(ref));
    }

    // now delete the property
    {
        auto in = MakeDeviceDataStringArray({objName, "1", propName});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbDeleteProperty", in));
    }

    // now with DELETED entry
    {
        auto in = MakeDeviceDataStringArray({objName, propName});

        Tango::DeviceData reply;
        BOOST_CHECK_NO_THROW(reply = dp->command_inout("DbGetPropertyHist", in));
        auto vec = ExtractStringVector(reply);

        // replace volatile data
        vec[1] = "fakeDate";
        vec[5] = "fakeDate";
        vec[9] = "fakeDate";
        vec[13] = "fakeDate";
        vec[17] = "fakeDate";
        vec[21] = "fakeDate";
        vec[25] = "fakeDate";
        vec[29] = "fakeDate";
        vec[33] = "fakeDate";
        vec[38] = "fakeDate";

        // clang-format off
        std::vector<std::string> ref = {
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value3",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value4",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value5",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value6",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value7",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value8",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value9",
                                        propName,
                                        "fakeDate",
                                        "1",
                                        "prop0Value10",
                                        propName,
                                        "fakeDate",
                                        "2",
                                        "prop0ValueVec0_0",
                                        "prop0ValueVec0_1",
                                        propName,
                                        "fakeDate",
                                        "0" // count == 0 aka deleted
                                       };
        // clang-format on
        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(ref), std::end(ref));
    }
}

BOOST_FIXTURE_TEST_CASE(DbGetAttributeAliasWorks, AddAndExportDeviceFixture)
{
    const std::string attrAlias{"someAlias"};