summaryrefslogtreecommitdiff
path: root/ASNMP/tests/Varbind_Test.cpp
blob: e9c9ecc923b98298b57bf3f081b583661f1cdeac (plain)
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
194
195
196
197
// $Id$

// ============================================================================
//
// = LIBRARY
//    asnmp
//
// = FILENAME
//    Varbind_Test.cpp
//
// = DESCRIPTION
//  Test all the member functions of the Varbind class.
//   A varbind is a list of { oids and associated values }
//
// = AUTHOR
//    Michael R. MacFaden <mrm@cisco.com>
//
// ============================================================================

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Copyright 1997 Cisco Systems, Inc.

Permission to use, copy, modify, and distribute this software for any
purpose and without fee is hereby granted, provided that this
copyright and permission notice appear on all copies of the software and
supporting documentation, the name of Cisco Systems, Inc. not be used
in advertising or publicity pertaining to distribution of the
program without specific prior permission, and notice be given
in supporting documentation that modification, copying and distribution is by
permission of Cisco Systems, Inc.

Cisco Systems, Inc. makes no representations about the suitability of this
software for any purpose.  THIS SOFTWARE IS PROVIDED ``AS IS''
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGMENT AND
FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL CISCO SYSTEMS, INC. BE
LIABLE FOR ANY DAMAGES ARISING OUT OF THIS LICENSE OR YOUR USE OF THE
SOFTWARE INCLUDING WITHOUT LIMITATION, DIRECT, INDIRECT OR CONSEQUENTIAL
DAMAGES.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

#include "ace/OS_main.h"
#include "asnmp/oid.h"
#include "asnmp/vb.h"
#include "test_config.h"

ACE_RCSID(tests, Varbind_Test, "$Id$")
/*
  Vb( void);
  Vb( const Oid &oid);
  Vb( const Vb &vb);
  Vb( const Oid& vb, const SnmpSyntax &val, const SmiUINT32=SNMP_CLASS_SUCCESS);
  ~Vb();
   int valid() const;
   Vb& operator=( const Vb &vb);
   void set_oid( const Oid& oid);
   void get_oid( Oid &oid) const;
   void set_null();
   void set_value( const TimeTicks& ticks);
   void set_value( const Oid& oid);
   void set_value( const Counter32& ctr);
   void set_value( const Counter64& ctr);
   void set_value( const Gauge32& ctr);
   void set_value( const SnmpUInt32& ctr);
   void set_value( const SnmpInt32& ctr);
   void set_value( const OctetStr& oct_str);
   int get_value( TimeTicks& ticks);
   int get_value( Oid& oid);
   int get_value( Counter32& ctr);
   int get_value( Counter64& ctr);
   int get_value( Gauge32& ctr);
   int get_value( SnmpUInt32& ctr);
   int get_value( SnmpInt32& ctr);
   int get_value( OctetStr& oct_str);
   int get_value( SnmpSyntax &val);
   void set_value( const SnmpSyntax &val);
   int get_value( const SnmpSyntax &val);
   SmiUINT32 get_syntax();
   friend void set_exception_status( Vb *vb, const SmiUINT32 status);
   char *to_string();
   char *to_string_value();
   char *to_string_oid();
 */

static void VbTest()
{
#if !defined (ACE_WIN32)

  Vb v1;
  ACE_ASSERT(v1.valid() == 0);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n",
    v1.to_string()));

  // purpose of this routine??
  set_exception_status( &v1, 10);

  Vb v2(v1);
  ACE_ASSERT(v2.valid() == 0);
  Oid o1("1.2.3"), o2;
  v2.set_oid(o1);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n",
    v2.to_string()));

  v2.get_oid(o2);
  ACE_ASSERT(o2 == o1);
  ACE_ASSERT(v2.valid() == 0);
  v2.set_null();
  ACE_ASSERT(v2.valid() == 0);
  v2.get_oid(o2);

  Vb v3;
  TimeTicks t(0), t1;
  v3.set_oid(o1);
  v3.set_value(t);
  ACE_ASSERT(v3.valid() == 1);
  v3.get_value(t1);
  ACE_ASSERT(t == t1);

  Vb v4;
  v4.set_oid(o1);
  v4.set_value(o1);
  ACE_ASSERT(v4.valid() == 1);
  v4.get_value(o2);
  ACE_ASSERT(o1 == o2);

  Vb v5;
  Counter32 c1(12), c2;
  v5.set_oid(o1);
  v5.set_value(c1);
  ACE_ASSERT(v5.valid() == 1);
  v5.get_value(c2);
  ACE_ASSERT(c1 == c2);

  Vb v6;
  Counter64 c3(12345678901234ULL), c4;
  v6.set_oid(o1);
  v6.set_value(c3);
  ACE_ASSERT(v6.valid() == 1);
  v6.get_value(c4);
  ACE_ASSERT(c3 == c4);

  Vb v7;
  Gauge32 g1(0123456), g2;
  v7.set_oid(o1);
  v7.set_value(g1);
  ACE_ASSERT(v7.valid() == 1);
  v7.get_value(g2);
  ACE_ASSERT(g1 == g2);

  Vb v8;
  SnmpInt32 i1(0123456), i2;
  v8.set_oid(o1);
  v8.set_value(i1);
  ACE_ASSERT(v8.valid() == 1);
  v8.get_value(i2);
  ACE_ASSERT(i1 == i2);

  Vb v9;
  SnmpUInt32 u1(0123456), u2;
  v9.set_oid(o1);
  v9.set_value(u1);
  ACE_ASSERT(v9.valid() == 1);
  v9.get_value(u2);
  ACE_ASSERT(u1 == u2);

  Vb v10;
  OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2;
  v10.set_oid(o1);
  v10.set_value(s1);
  ACE_ASSERT(v10.valid() == 1);
  v10.get_value(s2);
  ACE_ASSERT(s1 == s2);
  ACE_ASSERT(s1.length() == s2.length());

  // test assignment over all datatypes
  v10 = v5;
  ACE_ASSERT(v10 == v5);


  Vb v11(o1, s1, SNMP_CLASS_SUCCESS);
  ACE_ASSERT(v11.valid() == 1);
  v11.get_oid(o2);
  ACE_ASSERT(o1 == o2);
  v11.get_value(s2);
  ACE_ASSERT(s1 == s2);
#endif /*if ACE_WIN32*/
}

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Varbind_Test"));
  VbTest();
  ACE_END_TEST;
  return 0;
}