2 //=============================================================================
4 * @file Integer_Test.cpp
6 * Test all the member functions of the Integer class. An Object
7 * representing an ASN.1 Integer64 SMI 32 bit Integer 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/integer.h"
37 #include "test_config.h"
39 #if !defined (ACE_WIN32)
40 static long l
= LONG_MAX
, nl
= LONG_MIN
; // limits.h
41 static unsigned long ul
= ULONG_MAX
, def
= 0;
42 static int i
= INT_MAX
, ni
= INT_MIN
;
43 static unsigned int ui
= UINT_MAX
;
44 static unsigned short us
= 10;
45 static unsigned short si
= 32768;
50 SnmpInt32 (const long i);
51 SnmpInt32 (const SnmpInt32 &c);
53 virtual SmiUINT32 get_syntax();
54 SnmpInt32& operator=( const long i);
55 SnmpInt32& operator=( const SnmpInt32 &li);
58 SnmpSyntax *clone() const;
59 SnmpSyntax& operator=( SnmpSyntax &val);
63 static void TestInteger32()
65 #if !defined (ACE_WIN32)
68 ACE_ASSERT(i1
== static_cast<long> (def
));
74 ACE_ASSERT(i4
== static_cast<long> (ul
));
80 ACE_ASSERT(i7
== static_cast<long> (ui
));
81 SnmpInt32
*i8
= new SnmpInt32(i5
);
85 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i1(\"\") [%u]\n",
87 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i2(\"%u\") [%u]\n",
88 l
, (unsigned long)i2
));
89 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i3(\"%u\") [%u]\n",
90 nl
, (unsigned long)i3
));
91 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i4(\"%u\") [%u]\n",
92 ul
, (unsigned long)i4
));
93 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i5(\"%u\") [%u]\n",
94 i
, (unsigned long)i5
));
95 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i6(\"%u\") [%u]\n",
96 ni
, (unsigned long)i6
));
97 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) i7(\"%u\") [%u]\n",
98 ui
, (unsigned long)i7
));
102 ACE_ASSERT(i1
== i2
);
104 ACE_ASSERT(i1
== i1
);
105 i1
= def
; // unsigned long
106 ACE_ASSERT(i1
== static_cast<long> (def
));
107 i1
= us
; // unsigned short
108 ACE_ASSERT(i1
== static_cast<long> (us
));
109 i1
= si
; // unsigned short
110 ACE_ASSERT(i1
== static_cast<long> (si
));
116 SnmpUInt32 (const unsigned long i);
117 SnmpUInt32( const SnmpUInt32 &c);
118 virtual ~SnmpUInt32();
119 virtual SmiUINT32 get_syntax();
120 SnmpUInt32& operator=( const unsigned long i);
121 SnmpUInt32& operator=( const SnmpUInt32 &uli);
122 operator unsigned long();
123 virtual char *to_string();
124 virtual SnmpSyntax *clone() const;
125 SnmpSyntax& operator=( SnmpSyntax &val);
128 static void TestUnsignedInteger32()
130 #if !defined (ACE_WIN32)
133 ACE_ASSERT(u1
== def
);
135 ACE_ASSERT(u2
== static_cast<unsigned long> (l
));
137 ACE_ASSERT(u3
== static_cast<unsigned long> (nl
));
139 ACE_ASSERT(u4
== ul
);
141 ACE_ASSERT(u5
== static_cast<unsigned long> (i
));
143 ACE_ASSERT(u6
== static_cast<unsigned long> (ni
));
145 ACE_ASSERT(u7
== ui
);
146 SnmpUInt32
*u8
= new SnmpUInt32(u5
);
150 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u1(\"\") [%u]\n",
152 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u2(\"%u\") [%u]\n",
153 l
, (unsigned long)u2
));
154 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u3(\"%u\") [%u]\n",
155 nl
, (unsigned long)u3
));
156 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u4(\"%u\") [%u]\n",
157 ul
, (unsigned long)u4
));
158 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u5(\"%u\") [%u]\n",
159 i
, (unsigned long)u5
));
160 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u6(\"%u\") [%u]\n",
161 ni
, (unsigned long)u6
));
162 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) u7(\"%u\") [%u]\n",
163 ui
, (unsigned long)u7
));
167 ACE_ASSERT(u1
== u2
);
169 ACE_ASSERT(u1
== u1
);
170 u1
= def
; // unsigned long
171 ACE_ASSERT(u1
== def
);
172 u1
= us
; // unsigned short
173 ACE_ASSERT(u1
== static_cast<unsigned long> (us
));
174 u1
= si
; // unsigned short
175 ACE_ASSERT(u1
== static_cast<unsigned long> (si
));
176 #endif /*ACE_WIN32 */
180 ACE_TMAIN (int, ACE_TCHAR
*[])
182 ACE_START_TEST (ACE_TEXT ("Integer_Test"));
186 TestUnsignedInteger32();