File: test_auto_attr.cpp

package info (click to toggle)
tango 10.0.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 272; sql: 72; ruby: 24
file content (77 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <tango/tango.h>

#include <memory>

#include "utils/utils.h"

static constexpr double ATTR_TEST_VALUE = 42.0;

// Test device class
template <class Base>
class AutoAttrDev : public Base
{
  public:
    using Base::Base;

    ~AutoAttrDev() override { }

    void init_device() override
    {
        value = 0;
    }

    void read_value(Tango::Attribute &att)
    {
        att.set_value_date_quality(&value, std::chrono::system_clock::now(), Tango::ATTR_VALID);
    }

    void write_value(Tango::WAttribute &att)
    {
        att.get_write_value(value);
    }

    static void attribute_factory(std::vector<Tango::Attr *> &attrs)
    {
        attrs.push_back(
            new TangoTest::AutoAttr<&AutoAttrDev::read_value, &AutoAttrDev::write_value>("value", Tango::DEV_DOUBLE));
    }

  private:
    Tango::DevDouble value;
};

TANGO_TEST_AUTO_DEV_TMPL_INSTANTIATE(AutoAttrDev, 3)

SCENARIO("AutoAttr can be read and written")
{
    int idlver = GENERATE(TangoTest::idlversion(3));
    GIVEN("a device proxy to a simple IDLv" << idlver << " device")
    {
        TangoTest::Context ctx{"auto_attr", "AutoAttrDev", idlver};
        auto device = ctx.get_proxy();

        REQUIRE(idlver == device->get_idl_version());

        AND_GIVEN("an attribute name")
        {
            std::string att{"value"};

            WHEN("we write the attribute")
            {
                Tango::DeviceAttribute in;
                in.set_name(att);
                in << ATTR_TEST_VALUE;
                REQUIRE_NOTHROW(device->write_attribute(in));

                THEN("we read back matching value")
                {
                    Tango::DeviceAttribute out;
                    REQUIRE_NOTHROW(out = device->read_attribute(att));
                    double value;
                    out >> value;
                    REQUIRE(value == ATTR_TEST_VALUE);
                }
            }
        }
    }
}