File: misc_devattr.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 (111 lines) | stat: -rw-r--r-- 1,915 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
// NOLINTBEGIN(*)

#include "old_common.h"

int main()
{
    // Test empty

    DeviceAttribute da;
    long lo;
    bitset<DeviceAttribute::numFlags> flags;
    flags.reset(DeviceAttribute::isempty_flag);
    da.exceptions(flags);

    bool ret = da >> lo;
    assert(ret == false);

    TEST_LOG << "   Extraction from empty object --> OK" << endl;

    flags.set(DeviceAttribute::isempty_flag);
    da.exceptions(flags);

    try
    {
        da >> lo;
        assert(false);
    }
    catch(Tango::DevFailed &)
    {
    }

    TEST_LOG << "   Extraction from empty object (exception) --> OK" << endl;
    flags.reset();

    // Test wrong type

    DeviceAttribute db;
    long l = 2;
    db << l;

    short fl;

    ret = db >> fl;
    assert(ret == false);

    TEST_LOG << "   Extraction with wrong type --> OK" << endl;

    flags.set(DeviceAttribute::wrongtype_flag);
    db.exceptions(flags);

    try
    {
        db >> fl;
        assert(false);
    }
    catch(Tango::DevFailed &)
    {
    }

    TEST_LOG << "   Extraction with wrong type (exception) --> OK" << endl;

    // Test assignement operator

    DeviceAttribute dd, dd_c;
    string v_str("abc");

    dd << v_str;
    dd_c = dd;

    string out;
    dd_c >> out;

    assert(out == "abc");

    TEST_LOG << "   assignement operator --> OK" << endl;

    // Test copy constructor

    DeviceAttribute d;
    double db2 = 3.45;
    d << db2;

    DeviceAttribute dc(d);

    double db_out;
    dc >> db_out;

    assert(db_out == db2);

    TEST_LOG << "   Copy constructor --> OK" << endl;

    // Test move assignement

    DeviceAttribute d_ma;
    float fl_move = 2.0;
    d_ma << fl_move;

    DeviceAttribute d_ma_out;
    d_ma_out = std::move(d_ma);

    float fl_move_out;
    d_ma_out >> fl_move_out;

    assert(fl_move == fl_move_out);

    TEST_LOG << "   Move assignement --> OK" << endl;

    return 0;
}

// NOLINTEND(*)