2 //=============================================================================
6 * Test all the member functions of the Oid class. An Object
7 * representing an ASN.1 Integer64 SMI OID SYNTAX.
9 * @author Michael R. MacFaden <mrm@cisco.com>
11 //=============================================================================
13 /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 Copyright 1997 Cisco Systems, Inc.
16 Permission to use, copy, modify, and distribute this software for any
17 purpose and without fee is hereby granted, provided that this
18 copyright and permission notice appear on all copies of the software and
19 supporting documentation, the name of Cisco Systems, Inc. not be used
20 in advertising or publicity pertaining to distribution of the
21 program without specific prior permission, and notice be given
22 in supporting documentation that modification, copying and distribution is by
23 permission of Cisco Systems, Inc.
25 Cisco Systems, Inc. makes no representations about the suitability of this
26 software for any purpose. THIS SOFTWARE IS PROVIDED ``AS IS''
27 AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
28 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGMENT AND
29 FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL CISCO SYSTEMS, INC. BE
30 LIABLE FOR ANY DAMAGES ARISING OUT OF THIS LICENSE OR YOUR USE OF THE
31 SOFTWARE INCLUDING WITHOUT LIMITATION, DIRECT, INDIRECT OR CONSEQUENTIAL
33 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
35 #include "ace/OS_main.h"
36 #include "asnmp/oid.h"
37 #include "test_config.h"
40 Oid( const char * dotted_oid_string = "", size_t size = -1);
41 Oid ( const Oid &oid);
42 Oid(const unsigned long *raw_oid, size_t oid_len);
45 SmiUINT32 get_syntax();
46 Oid& operator=( const Oid &oid);
47 bool operator==( const Oid &lhs,const Oid &rhs);
48 bool operator!=( const Oid &lhs,const Oid &rhs);
49 bool operator<( const Oid &lhs,const Oid &rhs);
50 bool operator<=( const Oid &lhs,const Oid &rhs);
51 bool operator>( const Oid &lhs,const Oid &rhs);
52 bool operator>=( const Oid &lhs,const Oid &rhs);
53 Oid& operator+=( const char *a);
54 Oid& operator+=( const unsigned long i);
55 Oid& operator+=( const Oid &o);
56 unsigned long & operator[]( size_t position);
58 void set_data( const char *dotted_oid_string);
59 void set_data( const unsigned long *raw_oid, const size_t oid_len);
60 size_t length() const;
61 void trim( const size_t how_many = 1);
62 int suboid( const size_t start, const size_t end, Oid& new_oid);
63 int left_comparison( const unsigned long n, const Oid &o) const;
64 int right_comparison( const unsigned long n, const Oid &o) const;
67 SnmpSyntax *clone() const;
68 SnmpSyntax& operator=( SnmpSyntax &val);
74 ACE_ASSERT(d1
.valid() == 0);
75 ACE_ASSERT(d1
.length() == 0);
76 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d1(\"\") [%s]\n",
80 ACE_ASSERT(d2
.valid() == 1);
81 ACE_ASSERT(d2
.length() == 3);
82 ACE_ASSERT(d2
[0] == (unsigned long) 1);
83 ACE_ASSERT(d2
[1] == (unsigned long) 2);
84 ACE_ASSERT(d2
[2] == (unsigned long) 3);
85 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d2(\"1.2.3\") [%s]\n",
89 ACE_ASSERT(d3
.valid() == 1);
90 ACE_ASSERT(d3
.length() == 3);
91 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d3(\"d2\") [%s]\n",
94 unsigned long t
[3] = {2,3,4};
95 Oid
d4((unsigned long *)&t
, sizeof(t
)/sizeof(long));
96 ACE_ASSERT(d4
.valid() == 1);
97 ACE_ASSERT(d4
.length() == 3);
98 ACE_ASSERT(d4
[0] == (unsigned long) 2);
99 ACE_ASSERT(d4
[1] == (unsigned long) 3);
100 ACE_ASSERT(d4
[2] == (unsigned long) 4);
101 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d4(\"long(2.3.4)\") [%s]\n",
106 ACE_ASSERT(d4
.suboid(d5
, 1,1) == 0); // 2,3,4, 1,1 == 3
107 ACE_ASSERT(d5
.length() == 1);
108 ACE_ASSERT(d5
.valid() == 1);
109 ACE_ASSERT(d5
[0] == 3);
110 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d6::suboid(d5,1,1) [%s]\n",
115 ACE_ASSERT(d7
.valid() == 1);
117 ACE_ASSERT(d7
.length() == d4
.length() -1);
120 ACE_ASSERT(d7
.left_comparison( d7
.length(), d7
) == 0);
121 ACE_ASSERT(d4
.right_comparison( d4
.length(), d4
) == 0);
125 ACE_ASSERT(d1
.valid() == 1);
126 ACE_ASSERT(d1
== d4
);
128 ACE_ASSERT(d2
.valid() == 1);
129 ACE_ASSERT(d2
[2] == (unsigned long) 7);
131 ACE_ASSERT(d1
.valid() == 1);
134 unsigned long ll
= ULONG_MAX
;
136 d1
+= (unsigned long)0;
140 ACE_ASSERT(d1
.valid() == 1);
141 ACE_ASSERT(d1
.length() == 4);
142 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:d1(0,max,max,0) [%s]\n",
144 ACE_ASSERT(d1
[0] == (unsigned long)0);
145 ACE_ASSERT(d1
[1] == ll
);
146 ACE_ASSERT(d1
[2] == ll
);
147 ACE_ASSERT(d1
[3] == (unsigned long)0);
150 ACE_ASSERT(d2
.valid() == 1);
151 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Oid:(5.6.7.8.9.10) [%s]\n",
154 // test out max Oid string...
156 // relational operators oid,oid
157 ACE_ASSERT(d2
== d2
);
158 ACE_ASSERT(!(d2
!= d2
));
159 ACE_ASSERT(!(d2
< d2
));
160 ACE_ASSERT(!(d2
> d2
));
161 ACE_ASSERT(d2
>= d2
);
162 ACE_ASSERT(d2
<= d2
);
166 ACE_TMAIN (int, ACE_TCHAR
*[])
168 ACE_START_TEST (ACE_TEXT ("Oid_Test"));