File: add_rem_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 (117 lines) | stat: -rw-r--r-- 2,799 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
// NOLINTBEGIN(*)

#include "old_common.h"

int main(int argc, char **argv)
{
    DeviceProxy *device;

    if((argc == 1) || (argc > 3))
    {
        TEST_LOG << "usage: %s device" << endl;
        exit(-1);
    }

    string device_name = argv[1];

    try
    {
        device = new DeviceProxy(device_name);
    }
    catch(CORBA::Exception &e)
    {
        Except::print_exception(e);
        exit(1);
    }

    TEST_LOG << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl;

    try
    {
        //
        // Get attribute number
        //

        vector<string> *att_list;
        att_list = device->get_attribute_list();
        long nb_att = att_list->size();

        TEST_LOG << "Device attribute number before add = " << nb_att << endl;

        //
        // Add one attribute to the device
        //

        Tango::ConstDevString ds = "Added_short_attr";
        Tango::DeviceData din;
        din << ds;
        device->command_inout("IOAddAttribute", din);

        //
        // Get new attribute number
        //

        vector<string> *att_list_add;
        att_list_add = device->get_attribute_list();
        long nb_att_add = att_list_add->size();

        TEST_LOG << "Device attribute number after add = " << nb_att_add << endl;
        assert(nb_att_add == (nb_att + 1));

        //
        // Redo it once, this should not change att number (attribute already added)
        //

        device->command_inout("IOAddAttribute", din);

        vector<string> *att_list_add2;
        att_list_add2 = device->get_attribute_list();
        long nb_att_add2 = att_list_add2->size();

        TEST_LOG << "Device attribute number after second add = " << nb_att_add2 << endl;
        assert(nb_att_add2 == (nb_att + 1));

        TEST_LOG << "   Adding attribute --> OK" << endl;

        //
        // Remove the attribute
        //

        device->command_inout("IORemoveAttribute", din);

        vector<string> *att_list_rem;
        att_list_rem = device->get_attribute_list();
        long nb_att_rem = att_list_rem->size();

        TEST_LOG << "Device attribute number after removing add = " << nb_att_rem << endl;
        assert(nb_att_rem == nb_att);

        //
        // Do it once more. This time, it should send an exception
        //

        bool except = false;
        try
        {
            device->command_inout("IORemoveAttribute", din);
        }
        catch(Tango::DevFailed &)
        {
            TEST_LOG << "Received exception" << endl;
            except = true;
        }

        assert(except == true);

        TEST_LOG << "   Removing attribute --> OK" << endl;
    }
    catch(Tango::DevFailed &e)
    {
        Except::print_exception(e);
        exit(-1);
    }

    return 0;
}

// NOLINTEND(*)