File: cxx_dynamic_attributes.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 (159 lines) | stat: -rw-r--r-- 4,061 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
// NOLINTBEGIN(*)

#include "cxx_common.h"

#undef SUITE_NAME
#define SUITE_NAME DynamicAttributesTestSuite

class DynamicAttributesTestSuite : public CxxTest::TestSuite
{
  protected:
    DeviceProxy *device1, *dserver;
    std::string device1_name;

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

        std::string dserver_name;

        // predefined mandatory parameters
        device1_name = CxxTest::TangoPrinter::get_param("device1");
        dserver_name = "dserver/" + CxxTest::TangoPrinter::get_param("fulldsname");

        // predefined optional parameters
        CxxTest::TangoPrinter::get_param_opt("loop"); // loop parameter is then managed by the CXX framework itself

        // always add this line, otherwise arguments will not be parsed correctly
        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 my_restore_point is restored to defaults
        if(CxxTest::TangoPrinter::is_restore_set("my_restore_point"))
        {
            try
            {
                // execute some instructions
            }
            catch(DevFailed &e)
            {
                TEST_LOG << endl << "Exception in suite tearDown():" << endl;
                Except::print_exception(e);
            }
        }

        // delete dynamically allocated objects
        delete device1;
        delete dserver;
    }

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

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

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

    // Test cppTango#1022

    void test_CppTangoIssue1022()
    {
        try
        {
            Tango::DeviceAttribute da = device1->read_attribute("Attr1");
            Tango::DevDouble double_val = -1.0;
            da >> double_val;
            TS_ASSERT_EQUALS(double_val, 0.0);
        }
        catch(const Tango::DevFailed &e)
        {
            Tango::Except::print_exception(e);
            TS_ASSERT(false);
        }

        try
        {
            Tango::DeviceData din;
            din << device1_name;
            dserver->command_inout("DevRestart", din);
        }
        catch(const Tango::DevFailed &e)
        {
            Tango::Except::print_exception(e);
            TS_ASSERT(false);
        }

        try
        {
            Tango::DeviceAttribute da = device1->read_attribute("Attr1");
            Tango::DevDouble double_val = -1.0;
            da >> double_val;
            TS_ASSERT_EQUALS(double_val, 0.0);
        }
        catch(const Tango::DevFailed &e)
        {
            Tango::Except::print_exception(e);
            TS_ASSERT(false);
        }

        try
        {
            Tango::DeviceData din;
            din << device1_name;
            dserver->command_inout("DevRestart", din);
        }
        catch(const Tango::DevFailed &e)
        {
            Tango::Except::print_exception(e);
            TS_ASSERT(false);
        }

        try
        {
            Tango::DeviceAttribute da = device1->read_attribute("Attr1");
            Tango::DevDouble double_val = -1.0;
            da >> double_val;
            TS_ASSERT_EQUALS(double_val, 0.0);
        }
        catch(const Tango::DevFailed &e)
        {
            Tango::Except::print_exception(e);
            TS_ASSERT(false);
        }
    }
};

// NOLINTEND(*)