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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
// NOLINTBEGIN(*)
#include "cxx_common.h"
#undef SUITE_NAME
#define SUITE_NAME WriteAttrHardware
class WriteAttrHardware : public CxxTest::TestSuite
{
protected:
DeviceProxy *device;
string att1_name;
string att2_name;
string att3_name;
vector<string> vs;
public:
SUITE_NAME()
{
//
// Arguments check -------------------------------------------------
//
string device1_name;
device1_name = CxxTest::TangoPrinter::get_param("device1");
CxxTest::TangoPrinter::validate_args();
//
// Initialization --------------------------------------------------
//
try
{
device = new DeviceProxy(device1_name);
device->ping();
att1_name = "Long64_attr_rw";
att2_name = "State_attr_rw";
att3_name = "Long64_spec_attr_rw";
vs.push_back(att1_name);
vs.push_back(att2_name);
vs.push_back(att3_name);
}
catch(CORBA::Exception &e)
{
Except::print_exception(e);
exit(-1);
}
}
virtual ~SUITE_NAME()
{
if(CxxTest::TangoPrinter::is_restore_set("restore_except"))
{
Tango::DeviceData din;
din << (short) 0;
device->command_inout("WriteAttrHardwareThrow", din);
vector<Tango::DeviceAttribute> attr_in;
Tango::DevLong64 lg64_attr = 0x800000000LL;
Tango::DevState sta_attr = Tango::FAULT;
vector<Tango::DevLong64> lg64_arr_attr;
lg64_arr_attr.push_back(0);
attr_in.push_back(Tango::DeviceAttribute(att1_name, lg64_attr));
attr_in.push_back(Tango::DeviceAttribute(att2_name, sta_attr));
attr_in.push_back(Tango::DeviceAttribute(att3_name, lg64_arr_attr));
device->write_attributes(attr_in);
}
delete device;
}
static SUITE_NAME *createSuite()
{
return new SUITE_NAME();
}
static void destroySuite(SUITE_NAME *suite)
{
delete suite;
}
//
// Tests -------------------------------------------------------
//
// Test write_attr_hardware throwing DevFailed exception
void test_DevFailed_from_write_attr_hardware(void)
{
Tango::DeviceData din;
din << (short) 1;
TS_ASSERT_THROWS_NOTHING(device->command_inout("WriteAttrHardwareThrow", din));
CxxTest::TangoPrinter::restore_set("restore_except");
vector<Tango::DeviceAttribute> *read_bef = nullptr;
vector<Tango::DeviceAttribute> *read_after = nullptr;
TS_ASSERT_THROWS_NOTHING(read_bef = device->read_attributes(vs));
vector<Tango::DevLong64> read_bef_att1;
vector<Tango::DevState> read_bef_att2;
vector<Tango::DevLong64> read_bef_att3;
(*read_bef)[0].extract_set(read_bef_att1);
(*read_bef)[1].extract_set(read_bef_att2);
(*read_bef)[2].extract_set(read_bef_att3);
vector<Tango::DeviceAttribute> attr_in;
Tango::DevLong64 lg64_attr = (Tango::DevLong64) 111;
Tango::DevState sta_attr = Tango::STANDBY;
vector<Tango::DevLong64> lg64_arr_attr;
lg64_arr_attr.push_back(4444);
attr_in.push_back(Tango::DeviceAttribute(att1_name, lg64_attr));
attr_in.push_back(Tango::DeviceAttribute(att2_name, sta_attr));
attr_in.push_back(Tango::DeviceAttribute(att3_name, lg64_arr_attr));
TS_ASSERT_THROWS_ASSERT(
device->write_attributes(attr_in),
Tango::NamedDevFailedList & e,
TS_ASSERT_EQUALS(string(e.err_list[0].name), att1_name);
TS_ASSERT_EQUALS(e.err_list[0].idx_in_call, 0);
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].reason.in()), "DevTest_WriteAttrHardware");
TS_ASSERT_DIFFERS(string(e.err_list[0].err_stack[0].origin.in()).find("DevTest::write_attr_hardware"),
std::string::npos);
TS_ASSERT_EQUALS(e.err_list[0].err_stack[0].severity, Tango::ERR);
TS_ASSERT_EQUALS(string(e.err_list[1].name), att2_name);
TS_ASSERT_EQUALS(e.err_list[1].idx_in_call, 1);
TS_ASSERT_EQUALS(string(e.err_list[1].err_stack[0].reason.in()), "DevTest_WriteAttrHardware");
TS_ASSERT_DIFFERS(string(e.err_list[1].err_stack[0].origin.in()).find("DevTest::write_attr_hardware"),
std::string::npos);
TS_ASSERT_EQUALS(e.err_list[1].err_stack[0].severity, Tango::ERR);
TS_ASSERT_EQUALS(string(e.err_list[2].name), att3_name);
TS_ASSERT_EQUALS(e.err_list[2].idx_in_call, 2);
TS_ASSERT_EQUALS(string(e.err_list[2].err_stack[0].reason.in()), "DevTest_WriteAttrHardware");
TS_ASSERT_DIFFERS(string(e.err_list[2].err_stack[0].origin.in()).find("DevTest::write_attr_hardware"),
std::string::npos);
TS_ASSERT_EQUALS(e.err_list[2].err_stack[0].severity, Tango::ERR));
TS_ASSERT_THROWS_NOTHING(read_after = device->read_attributes(vs));
vector<Tango::DevLong64> read_after_att1;
vector<Tango::DevState> read_after_att2;
vector<Tango::DevLong64> read_after_att3;
(*read_after)[0].extract_set(read_after_att1);
(*read_after)[1].extract_set(read_after_att2);
(*read_after)[2].extract_set(read_after_att3);
TS_ASSERT_EQUALS(read_bef_att1, read_after_att1);
TS_ASSERT_EQUALS(read_bef_att2, read_after_att2);
TS_ASSERT_EQUALS(read_bef_att3, read_after_att3);
delete read_bef;
delete read_after;
}
// Test write_attr_hardware throwing MultiDevFailed exception from att name
void test_MultiDevFailed_from_name_thrown_by_write_attr_hardware(void)
{
Tango::DeviceData din;
din << (short) 2;
TS_ASSERT_THROWS_NOTHING(device->command_inout("WriteAttrHardwareThrow", din));
vector<Tango::DeviceAttribute> *read_bef = nullptr;
vector<Tango::DeviceAttribute> *read_after = nullptr;
TS_ASSERT_THROWS_NOTHING(read_bef = device->read_attributes(vs));
vector<Tango::DevLong64> read_bef_att1;
(*read_bef)[0].extract_set(read_bef_att1);
vector<Tango::DeviceAttribute> attr_in;
Tango::DevLong64 lg64_attr = (Tango::DevLong64) 111;
Tango::DevState sta_attr = Tango::STANDBY;
vector<Tango::DevLong64> lg64_arr_attr;
lg64_arr_attr.push_back(4444);
attr_in.push_back(Tango::DeviceAttribute(att1_name, lg64_attr));
attr_in.push_back(Tango::DeviceAttribute(att2_name, sta_attr));
attr_in.push_back(Tango::DeviceAttribute(att3_name, lg64_arr_attr));
TS_ASSERT_THROWS_ASSERT(
device->write_attributes(attr_in),
Tango::NamedDevFailedList & e,
TS_ASSERT_EQUALS(string(e.err_list[0].name), att1_name);
TS_ASSERT_EQUALS(e.err_list[0].idx_in_call, 0);
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].reason.in()), "DevTest_WriteAttrHardware");
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].origin.in()), "DevTest::write_attr_hardware");
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].desc.in()), "aaa");
TS_ASSERT_EQUALS(e.err_list[0].err_stack[0].severity, Tango::ERR));
TS_ASSERT_THROWS_NOTHING(read_after = device->read_attributes(vs));
vector<Tango::DevLong64> read_after_att1;
vector<Tango::DevState> read_after_att2;
vector<Tango::DevLong64> read_after_att3;
(*read_after)[0].extract_set(read_after_att1);
(*read_after)[1].extract_set(read_after_att2);
(*read_after)[2].extract_set(read_after_att3);
TS_ASSERT_EQUALS(read_bef_att1, read_after_att1);
TS_ASSERT_EQUALS(read_after_att2.size(), 1u);
TS_ASSERT_EQUALS(read_after_att2[0], Tango::STANDBY);
TS_ASSERT_EQUALS(read_after_att3.size(), 1u);
TS_ASSERT_EQUALS(read_after_att3[0], 4444);
delete read_bef;
delete read_after;
}
// Test write_attr_hardware throwing MultiDevFailed exception from att index
void test_MultiDevFailed_from_ind_thrown_by_write_attr_hardware(void)
{
Tango::DeviceData din;
din << (short) 3;
TS_ASSERT_THROWS_NOTHING(device->command_inout("WriteAttrHardwareThrow", din));
vector<Tango::DeviceAttribute> *read_bef = nullptr;
vector<Tango::DeviceAttribute> *read_after = nullptr;
TS_ASSERT_THROWS_NOTHING(read_bef = device->read_attributes(vs));
vector<Tango::DevLong64> read_bef_att3;
(*read_bef)[2].extract_set(read_bef_att3);
vector<Tango::DeviceAttribute> attr_in;
Tango::DevLong64 lg64_attr = (Tango::DevLong64) 111;
Tango::DevState sta_attr = Tango::STANDBY;
vector<Tango::DevLong64> lg64_arr_attr;
lg64_arr_attr.push_back(4444);
attr_in.push_back(Tango::DeviceAttribute(att1_name, lg64_attr));
attr_in.push_back(Tango::DeviceAttribute(att2_name, sta_attr));
attr_in.push_back(Tango::DeviceAttribute(att3_name, lg64_arr_attr));
TS_ASSERT_THROWS_ASSERT(
device->write_attributes(attr_in),
Tango::NamedDevFailedList & e,
TS_ASSERT_EQUALS(string(e.err_list[0].name), att3_name);
TS_ASSERT_EQUALS(e.err_list[0].idx_in_call, 2);
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].reason.in()), "DevTest_WriteAttrHardware");
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].origin.in()), "DevTest::write_attr_hardware");
TS_ASSERT_EQUALS(string(e.err_list[0].err_stack[0].desc.in()), "bbb");
TS_ASSERT_EQUALS(e.err_list[0].err_stack[0].severity, Tango::ERR));
TS_ASSERT_THROWS_NOTHING(read_after = device->read_attributes(vs));
vector<Tango::DevLong64> read_after_att1;
vector<Tango::DevState> read_after_att2;
vector<Tango::DevLong64> read_after_att3;
(*read_after)[0].extract_set(read_after_att1);
(*read_after)[1].extract_set(read_after_att2);
(*read_after)[2].extract_set(read_after_att3);
TS_ASSERT_EQUALS(read_bef_att3, read_after_att3);
TS_ASSERT_EQUALS(read_after_att2.size(), 1u);
TS_ASSERT_EQUALS(read_after_att2[0], Tango::STANDBY);
TS_ASSERT_EQUALS(read_after_att1.size(), 1u);
TS_ASSERT_EQUALS(read_after_att1[0], 111);
}
};
// NOLINTEND(*)
|