Commit f341f888 authored by Thomas Braun's avatar Thomas Braun
Browse files

tests: Add some for DbPutDeviceAttributeProperty2

And also for the memorized attribute special case without history.
parent 36bd0625
Loading
Loading
Loading
Loading
Loading
+134 −0
Original line number Diff line number Diff line
@@ -805,6 +805,140 @@ BOOST_FIXTURE_TEST_CASE(DbGetDeviceAttributeProperty2Works, AddAndExportDeviceFi
    }
}

BOOST_FIXTURE_TEST_CASE(DbPutDeviceAttributeProperty2Works, AddAndExportDeviceFixture)
{
    const std::vector<std::string> input = {device_name,
                                            "2", // #attributes
                                            "attr0",
                                            "3", // #properties of first attribute
                                            "attr0_prop0",
                                            "1", // #property values: 1 for scalar, > 1 for arrays
                                            "attr0_prop0_scalar_val0",
                                            "attr0_prop1",
                                            "4",
                                            "attr0_prop1_array_val0",
                                            "attr0_prop1_array_val1",
                                            "attr0_prop1_array_val2",
                                            "attr0_prop1_array_val3",
                                            "attr0_prop2",
                                            "1",
                                            "attr0_prop2_scalar_val0",
                                            "attr1",
                                            "1",
                                            "attr1_prop0",
                                            "1",
                                            "attr1_prop0_scalar_val0"};
    // insert some attribute properties
    {
        auto dd = MakeDeviceDataStringArray(input);

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

    // all attributes
    {
        auto dd = MakeDeviceDataStringArray({device_name, "attr0", "attr1"});

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

        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(input), std::end(input));
    }

    // overwrite existing property attr0_prop1
    {
        const std::vector<std::string> overwrite = {device_name,
                                                    "1", // #attributes
                                                    "attr0",
                                                    "1", // #properties of first attribute
                                                    "attr0_prop1",
                                                    "4",
                                                    "attr0_prop1_array_val0_2",
                                                    "attr0_prop1_array_val1_2",
                                                    "attr0_prop1_array_val2_2",
                                                    "attr0_prop1_array_val3_2"};

        auto dd = MakeDeviceDataStringArray(overwrite);

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

    // and now query its history
    {
        auto dd = MakeDeviceDataStringArray({device_name, "attr0", "attr0_prop1"});

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

        // replace timestamps like 2025-11-02 16:04:50
        vec[2] = "time0";
        vec[10] = "time1";

        std::vector<std::string> ref = {"attr0",
                                        "attr0_prop1",
                                        "time0",
                                        "4",
                                        "attr0_prop1_array_val0",
                                        "attr0_prop1_array_val1",
                                        "attr0_prop1_array_val2",
                                        "attr0_prop1_array_val3",
                                        "attr0",
                                        "attr0_prop1",
                                        "time1",
                                        "4",
                                        "attr0_prop1_array_val0_2",
                                        "attr0_prop1_array_val1_2",
                                        "attr0_prop1_array_val2_2",
                                        "attr0_prop1_array_val3_2"};

        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(ref), std::end(ref));
    }
}

BOOST_FIXTURE_TEST_CASE(DbPutDeviceAttributeProperty2MemorizedWorks, AddAndExportDeviceFixture)
{
    const std::vector<std::string> input = {device_name,
                                            "1", // #attributes
                                            "attr0",
                                            "1", // #properties of first attribute
                                            "__value",
                                            "1",
                                            "mem_att_value"};
    {
        auto dd = MakeDeviceDataStringArray(input);

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

    // read it back
    {
        auto dd = MakeDeviceDataStringArray({device_name, "attr0"});

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

        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(input), std::end(input));
    }

    // but no history
    {
        auto dd = MakeDeviceDataStringArray({device_name, "attr0", "__value"});

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

        std::vector<std::string> ref = {};
        BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(ref), std::end(ref));
    }
}

BOOST_FIXTURE_TEST_CASE(DbGetDeviceAttributeListWorks, AddAndExportDeviceFixture)
{
    const std::vector<std::string> input = {device_name,