Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / tests / Varbind_Test.cpp
blobf0caf0f93e1b8f14ce4135ed769f500d4259f2ac
2 //=============================================================================
3 /**
4 * @file Varbind_Test.cpp
6 * Test all the member functions of the Varbind class.
7 * A varbind is a list of { oids and associated values }
9 * @author Michael R. MacFaden <mrm@cisco.com>
11 //=============================================================================
14 /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
15 Copyright 1997 Cisco Systems, Inc.
17 Permission to use, copy, modify, and distribute this software for any
18 purpose and without fee is hereby granted, provided that this
19 copyright and permission notice appear on all copies of the software and
20 supporting documentation, the name of Cisco Systems, Inc. not be used
21 in advertising or publicity pertaining to distribution of the
22 program without specific prior permission, and notice be given
23 in supporting documentation that modification, copying and distribution is by
24 permission of Cisco Systems, Inc.
26 Cisco Systems, Inc. makes no representations about the suitability of this
27 software for any purpose. THIS SOFTWARE IS PROVIDED ``AS IS''
28 AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
29 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGMENT AND
30 FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL CISCO SYSTEMS, INC. BE
31 LIABLE FOR ANY DAMAGES ARISING OUT OF THIS LICENSE OR YOUR USE OF THE
32 SOFTWARE INCLUDING WITHOUT LIMITATION, DIRECT, INDIRECT OR CONSEQUENTIAL
33 DAMAGES.
34 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
36 #include "ace/OS_main.h"
37 #include "asnmp/oid.h"
38 #include "asnmp/vb.h"
39 #include "test_config.h"
42 Vb();
43 Vb( const Oid &oid);
44 Vb( const Vb &vb);
45 Vb( const Oid& vb, const SnmpSyntax &val, const SmiUINT32=SNMP_CLASS_SUCCESS);
46 ~Vb();
47 int valid() const;
48 Vb& operator=( const Vb &vb);
49 void set_oid( const Oid& oid);
50 void get_oid( Oid &oid) const;
51 void set_null();
52 void set_value( const TimeTicks& ticks);
53 void set_value( const Oid& oid);
54 void set_value( const Counter32& ctr);
55 void set_value( const Counter64& ctr);
56 void set_value( const Gauge32& ctr);
57 void set_value( const SnmpUInt32& ctr);
58 void set_value( const SnmpInt32& ctr);
59 void set_value( const OctetStr& oct_str);
60 int get_value( TimeTicks& ticks);
61 int get_value( Oid& oid);
62 int get_value( Counter32& ctr);
63 int get_value( Counter64& ctr);
64 int get_value( Gauge32& ctr);
65 int get_value( SnmpUInt32& ctr);
66 int get_value( SnmpInt32& ctr);
67 int get_value( OctetStr& oct_str);
68 int get_value( SnmpSyntax &val);
69 void set_value( const SnmpSyntax &val);
70 int get_value( const SnmpSyntax &val);
71 SmiUINT32 get_syntax();
72 friend void set_exception_status( Vb *vb, const SmiUINT32 status);
73 char *to_string();
74 char *to_string_value();
75 char *to_string_oid();
78 static void VbTest()
80 #if !defined (ACE_WIN32)
82 Vb v1;
83 ACE_ASSERT(v1.valid() == 0);
84 ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n",
85 v1.to_string()));
87 // purpose of this routine??
88 set_exception_status( &v1, 10);
90 Vb v2(v1);
91 ACE_ASSERT(v2.valid() == 0);
92 Oid o1("1.2.3"), o2;
93 v2.set_oid(o1);
94 ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n",
95 v2.to_string()));
97 v2.get_oid(o2);
98 ACE_ASSERT(o2 == o1);
99 ACE_ASSERT(v2.valid() == 0);
100 v2.set_null();
101 ACE_ASSERT(v2.valid() == 0);
102 v2.get_oid(o2);
104 Vb v3;
105 TimeTicks t(0), t1;
106 v3.set_oid(o1);
107 v3.set_value(t);
108 ACE_ASSERT(v3.valid() == 1);
109 v3.get_value(t1);
110 ACE_ASSERT(t == t1);
112 Vb v4;
113 v4.set_oid(o1);
114 v4.set_value(o1);
115 ACE_ASSERT(v4.valid() == 1);
116 v4.get_value(o2);
117 ACE_ASSERT(o1 == o2);
119 Vb v5;
120 Counter32 c1(12), c2;
121 v5.set_oid(o1);
122 v5.set_value(c1);
123 ACE_ASSERT(v5.valid() == 1);
124 v5.get_value(c2);
125 ACE_ASSERT(c1 == c2);
127 Vb v6;
128 Counter64 c3(12345678901234ULL), c4;
129 v6.set_oid(o1);
130 v6.set_value(c3);
131 ACE_ASSERT(v6.valid() == 1);
132 v6.get_value(c4);
133 ACE_ASSERT(c3 == c4);
135 Vb v7;
136 Gauge32 g1(0123456), g2;
137 v7.set_oid(o1);
138 v7.set_value(g1);
139 ACE_ASSERT(v7.valid() == 1);
140 v7.get_value(g2);
141 ACE_ASSERT(g1 == g2);
143 Vb v8;
144 SnmpInt32 i1(0123456), i2;
145 v8.set_oid(o1);
146 v8.set_value(i1);
147 ACE_ASSERT(v8.valid() == 1);
148 v8.get_value(i2);
149 ACE_ASSERT(i1 == i2);
151 Vb v9;
152 SnmpUInt32 u1(0123456), u2;
153 v9.set_oid(o1);
154 v9.set_value(u1);
155 ACE_ASSERT(v9.valid() == 1);
156 v9.get_value(u2);
157 ACE_ASSERT(u1 == u2);
159 Vb v10;
160 OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2;
161 v10.set_oid(o1);
162 v10.set_value(s1);
163 ACE_ASSERT(v10.valid() == 1);
164 v10.get_value(s2);
165 ACE_ASSERT(s1 == s2);
166 ACE_ASSERT(s1.length() == s2.length());
168 // test assignment over all datatypes
169 v10 = v5;
170 ACE_ASSERT(v10 == v5);
173 Vb v11(o1, s1, SNMP_CLASS_SUCCESS);
174 ACE_ASSERT(v11.valid() == 1);
175 v11.get_oid(o2);
176 ACE_ASSERT(o1 == o2);
177 v11.get_value(s2);
178 ACE_ASSERT(s1 == s2);
179 #endif /*if ACE_WIN32*/
183 ACE_TMAIN (int, ACE_TCHAR *[])
185 ACE_START_TEST (ACE_TEXT ("Varbind_Test"));
186 VbTest();
187 ACE_END_TEST;
188 return 0;