File: cxx_mem_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 (217 lines) | stat: -rw-r--r-- 5,912 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// NOLINTBEGIN(*)

#include "cxx_common.h"

#define STATUS_MEM_FAILED "Memorized attribute Short_attr_w has failed during device startup sequence"
#define STATUS_ON "The device is in ON state."

#undef SUITE_NAME
#define SUITE_NAME MemAttrTestSuite

class MemAttrTestSuite : public CxxTest::TestSuite
{
  protected:
    DeviceProxy *device1;
    string device1_name;

  public:
    SUITE_NAME()
    {
        //
        // Arguments check -------------------------------------------------
        //

        device1_name = CxxTest::TangoPrinter::get_param("device1");

        CxxTest::TangoPrinter::validate_args();

        //
        // Initialization --------------------------------------------------
        //

        try
        {
            device1 = new DeviceProxy(device1_name);
        }
        catch(CORBA::Exception &e)
        {
            Except::print_exception(e);
            exit(-1);
        }
    }

    virtual ~SUITE_NAME()
    {
        DeviceData din;
        vector<short> v_s;
        v_s.push_back(4);
        v_s.push_back(0);

        din << v_s;
        try
        {
            device1->command_inout("IOAttrThrowEx", din);
        }
        catch(CORBA::Exception &e)
        {
            TEST_LOG << endl << "Exception in suite tearDown():" << endl;
            Except::print_exception(e);
            exit(-1);
        }
        delete device1;
    }

    static SUITE_NAME *createSuite()
    {
        return new SUITE_NAME();
    }

    static void destroySuite(SUITE_NAME *suite)
    {
        delete suite;
    }

    //
    // Tests -------------------------------------------------------
    //

    // Test one memorized attribute which fails during init command

    void test_One_memorized_attribute_failing_during_init_cmd(void)
    {
        DeviceAttribute short_attr_w("Short_attr_w", static_cast<DevShort>(10));
        TS_ASSERT_THROWS_NOTHING(device1->write_attribute(short_attr_w));
        //
        // Ask the attribute to throw exception during any write call
        //

        DeviceData din;
        vector<short> v_s;
        v_s.push_back(4);
        v_s.push_back(1);

        din << v_s;

        device1->command_inout("IOAttrThrowEx", din);

        //
        // Execute init command
        //
        device1->command_inout("Init");

        //
        // Get device state and status
        //

        Tango::DevState ds = device1->state();
        TS_ASSERT_EQUALS(ds, Tango::ALARM);

        string d_status = device1->status();
        string::size_type pos = d_status.find('.');
        pos = pos + 2;
        string sub_status = d_status.substr(pos);
        TS_ASSERT_EQUALS(sub_status, STATUS_MEM_FAILED);

        //
        // Try to read the attribute
        //

        DeviceAttribute read_da = device1->read_attribute("Short_attr_w");
        short s_val;
        TS_ASSERT_THROWS_ASSERT(
            read_da >> s_val, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), "Aaaa");
            TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR);
            TS_ASSERT_EQUALS(string(e.errors[1].reason.in()), API_MemAttFailedDuringInit);
            TS_ASSERT_EQUALS(e.errors[1].severity, Tango::ERR));

        //
        // Ask attribute not to throw exception any more
        //

        v_s.clear();
        v_s.push_back(4);
        v_s.push_back(0);

        din << v_s;

        device1->command_inout("IOAttrThrowEx", din);

        //
        // Write the attribute
        //

        short val = 10;
        Tango::DeviceAttribute da("Short_attr_w", val);

        device1->write_attribute(da);

        //
        // Get device state and status
        //

        ds = device1->state();
        TS_ASSERT_EQUALS(ds, Tango::ON);

        d_status = device1->status();
        TS_ASSERT_EQUALS(d_status, STATUS_ON);

        //
        // Read the attribute
        //

        DeviceAttribute read_da_2 = device1->read_attribute("Short_attr_w");
        short s_val_2;
        read_da_2 >> s_val_2;
        TS_ASSERT_EQUALS(s_val_2, 10);
    }

    /*
     * Test for changing min and max alarm threshold of a  memorized attribute
     * with neither min_ nor max_value specified. Such scenario used to fail
     * (#401), with misleading error message claiming that memorized value
     * is above new limit.
     */

    void test_change_max_alarm_threshold_of_memorized_attribute()
    {
        const char *attr_name = "Short_attr_w";
        const DevShort attr_value = 20;

        unset_attribute_min_max_value(attr_name);

        DeviceAttribute value(attr_name, attr_value);
        TS_ASSERT_THROWS_NOTHING(device1->write_attribute(value));

        auto config = device1->get_attribute_config(attr_name);
        config.alarms.max_alarm = std::to_string(attr_value + 1);
        AttributeInfoListEx config_in = {config};
        TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
    }

    void test_change_min_alarm_threshold_of_memorized_attribute()
    {
        const char *attr_name = "Short_attr_w";
        const DevShort attr_value = -20;

        unset_attribute_min_max_value(attr_name);

        DeviceAttribute value(attr_name, attr_value);
        TS_ASSERT_THROWS_NOTHING(device1->write_attribute(value));

        auto config = device1->get_attribute_config(attr_name);
        config.alarms.min_alarm = std::to_string(attr_value - 1);
        AttributeInfoListEx config_in = {config};
        TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
    }

    void unset_attribute_min_max_value(const char *attr_name)
    {
        auto config = device1->get_attribute_config(attr_name);
        config.min_value = AlrmValueNotSpec;
        config.max_value = AlrmValueNotSpec;
        AttributeInfoListEx config_in = {config};
        TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
    }
};

// NOLINTEND(*)