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
|
// NOLINTBEGIN(*)
#include "cxx_common.h"
#undef SUITE_NAME
#define SUITE_NAME DynCmdTestSuite
class DynCmdTestSuite : public CxxTest::TestSuite
{
protected:
DeviceProxy *device1, *device2;
string device1_name;
string device2_name;
public:
SUITE_NAME()
{
//
// Arguments check -------------------------------------------------
//
string full_ds_name;
// user arguments, obtained from the command line sequentially
device1_name = CxxTest::TangoPrinter::get_param("device1");
device2_name = CxxTest::TangoPrinter::get_param("device2");
// always add this line, otherwise arguments will not be parsed correctly
CxxTest::TangoPrinter::validate_args();
//
// Initialization --------------------------------------------------
//
try
{
device1 = new DeviceProxy(device1_name);
device1->ping();
device2 = new DeviceProxy(device2_name);
device2->ping();
}
catch(CORBA::Exception &e)
{
Except::print_exception(e);
exit(-1);
}
}
virtual ~SUITE_NAME()
{
delete device1;
delete device2;
}
static SUITE_NAME *createSuite()
{
return new SUITE_NAME();
}
static void destroySuite(SUITE_NAME *suite)
{
delete suite;
}
//
// Tests -------------------------------------------------------
//
// Test dynamic command installed at class level
void test_dynamic_command_at_class_level()
{
// Add a dynamic command
Tango::DevLong device_level = 0;
DeviceData din, dout;
din << device_level;
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOAddCommand", din));
// Execute command
TS_ASSERT_THROWS_NOTHING(dout = device1->command_inout("Added_cmd"));
float receiv;
dout >> receiv;
TS_ASSERT_EQUALS(receiv, 4.0);
// Command in command list?
CommandInfo ci = device1->command_query("Added_cmd");
TS_ASSERT_EQUALS(ci.cmd_name, "Added_cmd");
TS_ASSERT_EQUALS(ci.in_type, DEV_VOID);
TS_ASSERT_EQUALS(ci.out_type, DEV_FLOAT);
CommandInfoList *cil = nullptr;
TS_ASSERT_THROWS_NOTHING(cil = device1->command_list_query());
bool found = false;
size_t nb_cmd = cil->size();
for(size_t loop = 0; loop < nb_cmd; loop++)
{
if((*cil)[loop].cmd_name == "Added_cmd")
{
found = true;
}
}
TS_ASSERT(found);
// Command also in command list for device 2
CommandInfoList *cil2 = nullptr;
TS_ASSERT_THROWS_NOTHING(cil2 = device2->command_list_query());
found = false;
nb_cmd = cil2->size();
for(size_t loop = 0; loop < nb_cmd; loop++)
{
if((*cil2)[loop].cmd_name == "Added_cmd")
{
found = true;
}
}
TS_ASSERT(found);
// Remove command
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IORemoveCommand"));
}
// Test dynamic command installed at device level
void test_dynamic_command_at_device_level()
{
// Add a dynamic command
Tango::DevLong device_level = 1;
DeviceData din, dout;
din << device_level;
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOAddCommand", din));
// Execute command
TS_ASSERT_THROWS_NOTHING(dout = device1->command_inout("Added_cmd"));
float receiv;
dout >> receiv;
TS_ASSERT_EQUALS(receiv, 4.0);
// Command in command list?
CommandInfo ci = device1->command_query("Added_cmd");
TS_ASSERT_EQUALS(ci.cmd_name, "Added_cmd");
TS_ASSERT_EQUALS(ci.in_type, DEV_VOID);
TS_ASSERT_EQUALS(ci.out_type, DEV_FLOAT);
CommandInfoList *cil = nullptr;
TS_ASSERT_THROWS_NOTHING(cil = device1->command_list_query());
bool found = false;
size_t nb_cmd = cil->size();
for(size_t loop = 0; loop < nb_cmd; loop++)
{
if((*cil)[loop].cmd_name == "Added_cmd")
{
found = true;
}
}
TS_ASSERT(found);
// Command should not be in command list for device 2
CommandInfoList *cil2 = nullptr;
TS_ASSERT_THROWS_NOTHING(cil2 = device2->command_list_query());
found = false;
nb_cmd = cil2->size();
for(size_t loop = 0; loop < nb_cmd; loop++)
{
if((*cil2)[loop].cmd_name == "Added_cmd")
{
found = true;
}
}
TS_ASSERT(!found);
// Remove command
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IORemoveCommand"));
}
};
// NOLINTEND(*)
|