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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
|
// NOLINTBEGIN(*)
#include "cxx_common.h"
#undef SUITE_NAME
#define SUITE_NAME PollTestSuite__loop
class PollTestSuite__loop : public CxxTest::TestSuite
{
protected:
DeviceProxy *device1, *dserver;
string device1_name, dserver_name;
public:
SUITE_NAME()
{
//
// Arguments check -------------------------------------------------
//
device1_name = CxxTest::TangoPrinter::get_param("device1");
dserver_name = "dserver/" + CxxTest::TangoPrinter::get_param("fulldsname");
CxxTest::TangoPrinter::get_param_opt("loop");
CxxTest::TangoPrinter::get_param_opt("suiteloop");
CxxTest::TangoPrinter::validate_args();
//
// Initialization --------------------------------------------------
//
try
{
device1 = new DeviceProxy(device1_name);
dserver = new DeviceProxy(dserver_name);
device1->ping();
dserver->ping();
}
catch(CORBA::Exception &e)
{
Except::print_exception(e);
exit(-1);
}
}
virtual ~SUITE_NAME()
{
//
// Clean up --------------------------------------------------------
//
// clean up in case test suite terminates before 'Double_attr'
// attribute polling state is restored to defaults for device1
if(CxxTest::TangoPrinter::is_restore_set("dev1_Double_attr_polling"))
{
DeviceData din;
DevVarStringArray rem_attr_poll;
rem_attr_poll.length(3);
rem_attr_poll[0] = device1_name.c_str();
rem_attr_poll[1] = "attribute";
rem_attr_poll[2] = "Double_attr";
din << rem_attr_poll;
try
{
dserver->command_inout("RemObjPolling", din);
}
catch(DevFailed &e)
{
TEST_LOG << endl << "Exception in suite tearDown():" << endl;
Except::print_exception(e);
}
}
// clean up in case test suite terminates before 'IOStr1'
// command polling state is restored to defaults for device1
if(CxxTest::TangoPrinter::is_restore_set("dev1_IOStr1_polling"))
{
DeviceData din;
DevVarStringArray rem_cmd_poll;
rem_cmd_poll.length(3);
rem_cmd_poll[0] = device1_name.c_str();
rem_cmd_poll[1] = "command";
rem_cmd_poll[2] = "IOStr1";
din << rem_cmd_poll;
try
{
dserver->command_inout("RemObjPolling", din);
}
catch(DevFailed &e)
{
TEST_LOG << endl << "Exception in suite tearDown():" << endl;
Except::print_exception(e);
}
}
// clean up in case test suite terminates before 'attr_wrong_size'
// attribute polling state is restored to defaults for device1
if(CxxTest::TangoPrinter::is_restore_set("dev1_attr_wrong_size_polling"))
{
DeviceData din;
DevVarStringArray rem_attr_poll;
rem_attr_poll.length(3);
rem_attr_poll[0] = device1_name.c_str();
rem_attr_poll[1] = "attribute";
rem_attr_poll[2] = "attr_wrong_size";
din << rem_attr_poll;
try
{
dserver->command_inout("RemObjPolling", din);
}
catch(DevFailed &e)
{
TEST_LOG << endl << "Exception in suite tearDown():" << endl;
Except::print_exception(e);
}
}
// clean up in case test suite terminates before 'IOExcept'
// command polling state is restored to defaults for device1
if(CxxTest::TangoPrinter::is_restore_set("dev1_IOExcept_polling"))
{
DeviceData din;
DevVarStringArray rem_cmd_poll;
rem_cmd_poll.length(3);
rem_cmd_poll[0] = device1_name.c_str();
rem_cmd_poll[1] = "command";
rem_cmd_poll[2] = "IOExcept";
din << rem_cmd_poll;
try
{
dserver->command_inout("RemObjPolling", din);
}
catch(DevFailed &e)
{
TEST_LOG << endl << "Exception in suite tearDown():" << endl;
Except::print_exception(e);
}
}
delete device1;
delete dserver;
}
static SUITE_NAME *createSuite()
{
return new SUITE_NAME();
}
static void destroySuite(SUITE_NAME *suite)
{
delete suite;
}
//
// Tests -------------------------------------------------------
//
// Test polling exceptions
void test_polling_exceptions(void)
{
DeviceData dout;
DeviceAttribute short_attr, mock_attr;
DevShort sh;
string str_out;
// check if the devices are not polled
const DevVarStringArray *polled_devices;
TS_ASSERT_THROWS_NOTHING(dout = dserver->command_inout("PolledDevice"));
dout >> polled_devices;
for(unsigned int i = 0; i < polled_devices->length(); i++)
{
TEST_LOG << "Polled device = " << (*polled_devices)[i] << endl;
}
TS_ASSERT_EQUALS((*polled_devices).length(), 0u);
// check if the data source is set to polling buffer and than device (CACHE_DEV)
TS_ASSERT_EQUALS(device1->get_source(), Tango::CACHE_DEV);
// set the data source to device (DEV)
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::DEV));
// execute some commands
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOVoid"));
TS_ASSERT_THROWS_NOTHING(dout = device1->command_inout("IOStr1"));
dout >> str_out;
TS_ASSERT_EQUALS(str_out, "Hello from IOStr1");
// execute non-existing command
TS_ASSERT_THROWS_ASSERT(device1->command_inout("IOxxx"),
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_CommandNotFound);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// now set the data source to polling buffer (CACHE)
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE));
// execute non-existing command
TS_ASSERT_THROWS_ASSERT(device1->command_inout("IOxxx"),
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_CommandNotFound);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// execute non-polled command
TS_ASSERT_THROWS_ASSERT(device1->command_inout("IOStr1"),
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_CmdNotPolled);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// set the data source again to device (DEV)
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::DEV));
// read an attribute
TS_ASSERT_THROWS_NOTHING(short_attr = device1->read_attribute("Short_attr"));
short_attr >> sh;
TS_ASSERT_EQUALS(short_attr.name, "Short_attr");
TS_ASSERT_EQUALS(short_attr.quality, Tango::ATTR_VALID);
TS_ASSERT_EQUALS(short_attr.dim_x, 1);
TS_ASSERT_EQUALS(short_attr.dim_y, 0);
TS_ASSERT_EQUALS(sh, 12);
// read a non-existing attribute
TS_ASSERT_THROWS_NOTHING(mock_attr = device1->read_attribute("xxx"));
TS_ASSERT_THROWS_ASSERT(
mock_attr >> sh, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrNotFound);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// set the data source again to polling buffer (CACHE)
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE));
// again read a non-existing attribute
TS_ASSERT_THROWS_NOTHING(mock_attr = device1->read_attribute("xxx"));
TS_ASSERT_THROWS_ASSERT(
mock_attr >> sh, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrNotFound);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// read a non-polled attribute
TS_ASSERT_THROWS_NOTHING(short_attr = device1->read_attribute("Short_attr"));
TS_ASSERT_THROWS_ASSERT(short_attr >> sh,
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrNotPolled);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
}
// Test commands and attributes obtained from polling buffer
void test_commands_and_attributes_obtained_from_polling_buffer(void)
{
DeviceData din, dout;
DevVarLongStringArray attr_poll, cmd_poll;
// poll Double_attr
attr_poll.lvalue.length(1);
attr_poll.lvalue[0] = 200;
attr_poll.svalue.length(3);
attr_poll.svalue[0] = device1_name.c_str();
attr_poll.svalue[1] = "attribute";
attr_poll.svalue[2] = "Double_attr";
din << attr_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("AddObjPolling", din));
CxxTest::TangoPrinter::restore_set("dev1_Double_attr_polling");
// poll IOStr1
cmd_poll.lvalue.length(1);
cmd_poll.lvalue[0] = 200;
cmd_poll.svalue.length(3);
cmd_poll.svalue[0] = device1_name.c_str();
cmd_poll.svalue[1] = "command";
cmd_poll.svalue[2] = "IOStr1";
din << cmd_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("AddObjPolling", din));
CxxTest::TangoPrinter::restore_set("dev1_IOStr1_polling");
// poll attr_wrong_size
attr_poll.lvalue[0] = 300;
attr_poll.svalue[0] = device1_name.c_str();
attr_poll.svalue[1] = "attribute";
attr_poll.svalue[2] = "attr_wrong_size";
din << attr_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("AddObjPolling", din));
CxxTest::TangoPrinter::restore_set("dev1_attr_wrong_size_polling");
// poll IOExcept
cmd_poll.lvalue[0] = 550;
cmd_poll.svalue[0] = device1_name.c_str();
cmd_poll.svalue[1] = "command";
cmd_poll.svalue[2] = "IOExcept";
din << cmd_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("AddObjPolling", din));
CxxTest::TangoPrinter::restore_set("dev1_IOExcept_polling");
std::this_thread::sleep_for(std::chrono::seconds(3));
// set the data source to polling buffer (CACHE)
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE));
// execute a command
string str_out;
TS_ASSERT_THROWS_NOTHING(dout = device1->command_inout("IOStr1"));
dout >> str_out;
TS_ASSERT_EQUALS(str_out, "Hello from IOStr1");
// read an attribute
DeviceAttribute db_attr;
DevDouble db;
TS_ASSERT_THROWS_NOTHING(db_attr = device1->read_attribute("Double_attr"));
db_attr >> db;
TS_ASSERT_EQUALS(db_attr.name, "Double_attr");
TS_ASSERT_EQUALS(db_attr.quality, Tango::ATTR_VALID);
TS_ASSERT_EQUALS(db_attr.dim_x, 1);
TS_ASSERT_EQUALS(db_attr.dim_y, 0);
TS_ASSERT_EQUALS(db, 3.2);
// read an attribute which throws an exception
DeviceAttribute mock_attr;
DevLong lg;
TS_ASSERT_THROWS_NOTHING(mock_attr = device1->read_attribute("attr_wrong_size"));
TS_ASSERT_THROWS_ASSERT(
mock_attr >> lg, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrOptProp);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// execute a command which throws an exception
TS_ASSERT_THROWS_ASSERT(device1->command_inout("IOExcept"),
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_ThrowException);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
}
// Check the CACHE_DEV source parameter
void test_check_the_CACHE_DEV_source_parameter(void)
{
DeviceData din, dout;
DeviceAttribute db_attr, mock_attr, lg_attr;
DevVarStringArray rem_cmd_poll, rem_attr_poll;
DevDouble db;
DevLong lg;
string str_out;
//
// Read from cache
//
// set the data source to CACHE_DEV
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE_DEV));
// read an attribute from cache
TS_ASSERT_THROWS_NOTHING(db_attr = device1->read_attribute("Double_attr"));
db_attr >> db;
TS_ASSERT_EQUALS(db_attr.name, "Double_attr");
TS_ASSERT_EQUALS(db_attr.quality, Tango::ATTR_VALID);
TS_ASSERT_EQUALS(db_attr.dim_x, 1);
TS_ASSERT_EQUALS(db_attr.dim_y, 0);
TS_ASSERT_EQUALS(db, 3.2);
// read an attribute from cache, which throws an exception
TS_ASSERT_THROWS_NOTHING(mock_attr = device1->read_attribute("attr_wrong_size"));
TS_ASSERT_THROWS_ASSERT(
mock_attr >> lg, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrOptProp);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
//
// If data not in cache, while data source is set to cache, throw exception
//
// set the data source to polling buffer
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE));
// read a non-polled attribute from cache
TS_ASSERT_THROWS_NOTHING(lg_attr = device1->read_attribute("Long_attr"));
TS_ASSERT_THROWS_ASSERT(
lg_attr >> lg, Tango::DevFailed & e, TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_AttrNotPolled);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
// execute non-polled command with polling buffer as data source
TS_ASSERT_THROWS_ASSERT(device1->command_inout("IOStr2"),
Tango::DevFailed & e,
TS_ASSERT_EQUALS(string(e.errors[0].reason.in()), API_CmdNotPolled);
TS_ASSERT_EQUALS(e.errors[0].severity, Tango::ERR));
//
// If data not in cache, read from device
//
// set the data source to polling buffer and then device
TS_ASSERT_THROWS_NOTHING(device1->set_source(Tango::CACHE_DEV));
// try to read a non-polled attribute from cache and then from device
TS_ASSERT_THROWS_NOTHING(lg_attr = device1->read_attribute("Long_attr"));
lg_attr >> lg;
TS_ASSERT_EQUALS(lg_attr.name, "Long_attr");
TS_ASSERT_EQUALS(lg_attr.quality, Tango::ATTR_VALID);
TS_ASSERT_EQUALS(lg_attr.dim_x, 1);
TS_ASSERT_EQUALS(lg_attr.dim_y, 0);
TS_ASSERT_EQUALS(lg, 1246);
// execute non-polled command firstly with polling buffer and then device as the data source
TS_ASSERT_THROWS_NOTHING(dout = device1->command_inout("IOStr2"));
dout >> str_out;
TS_ASSERT_EQUALS(str_out, "Hello from IOStr2");
//
// Restore polling to defaults
//
rem_attr_poll.length(3);
rem_cmd_poll.length(3);
// remove Double_attr polling
rem_attr_poll[0] = device1_name.c_str();
rem_attr_poll[1] = "attribute";
rem_attr_poll[2] = "Double_attr";
din << rem_attr_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("RemObjPolling", din));
CxxTest::TangoPrinter::restore_unset("dev1_Double_attr_polling");
// remove IOStr1 polling
rem_cmd_poll[0] = device1_name.c_str();
rem_cmd_poll[1] = "command";
rem_cmd_poll[2] = "IOStr1";
din << rem_cmd_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("RemObjPolling", din));
CxxTest::TangoPrinter::restore_unset("dev1_IOStr1_polling");
// remove attr_wrong_size polling
rem_attr_poll[0] = device1_name.c_str();
rem_attr_poll[1] = "attribute";
rem_attr_poll[2] = "attr_wrong_size";
din << rem_attr_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("RemObjPolling", din));
CxxTest::TangoPrinter::restore_unset("dev1_attr_wrong_size_polling");
// remove IOExcept polling
rem_cmd_poll[0] = device1_name.c_str();
rem_cmd_poll[1] = "command";
rem_cmd_poll[2] = "IOExcept";
din << rem_cmd_poll;
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("RemObjPolling", din));
CxxTest::TangoPrinter::restore_unset("dev1_IOExcept_polling");
}
};
// NOLINTEND(*)
|