Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / tests / Integer_Test.cpp
blob5660735c5c1bcd28c96b85f58d396ae151a59123
2 //=============================================================================
3 /**
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
32 DAMAGES.
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;
46 #endif /*ACE_WIN32*/
49 SnmpInt32();
50 SnmpInt32 (const long i);
51 SnmpInt32 (const SnmpInt32 &c);
52 virtual ~SnmpInt32();
53 virtual SmiUINT32 get_syntax();
54 SnmpInt32& operator=( const long i);
55 SnmpInt32& operator=( const SnmpInt32 &li);
56 operator long();
57 char *to_string();
58 SnmpSyntax *clone() const;
59 SnmpSyntax& operator=( SnmpSyntax &val);
60 int valid() const;
63 static void TestInteger32()
65 #if !defined (ACE_WIN32)
66 // constructors
67 SnmpInt32 i1;
68 ACE_ASSERT(i1 == static_cast<long> (def));
69 SnmpInt32 i2(l);
70 ACE_ASSERT(i2 == l);
71 SnmpInt32 i3(nl);
72 ACE_ASSERT(i3 == nl);
73 SnmpInt32 i4(ul);
74 ACE_ASSERT(i4 == static_cast<long> (ul));
75 SnmpInt32 i5(i);
76 ACE_ASSERT(i5 == i);
77 SnmpInt32 i6(ni);
78 ACE_ASSERT(i6 == ni);
79 SnmpInt32 i7(ui);
80 ACE_ASSERT(i7 == static_cast<long> (ui));
81 SnmpInt32 *i8 = new SnmpInt32(i5);
82 ACE_ASSERT(i8 != 0);
83 delete i8;
85 ACE_DEBUG ((LM_DEBUG, "(%P|%t) i1(\"\") [%u]\n",
86 (unsigned long)i1));
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));
100 // assignent
101 i1 = i2; // obj
102 ACE_ASSERT(i1 == i2);
103 i1 = i1; // self
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));
111 #endif /*ACE_WIN32*/
115 SnmpUInt32();
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);
126 int valid() const;
128 static void TestUnsignedInteger32()
130 #if !defined (ACE_WIN32)
131 // constructors
132 SnmpUInt32 u1;
133 ACE_ASSERT(u1 == def);
134 SnmpUInt32 u2(l);
135 ACE_ASSERT(u2 == static_cast<unsigned long> (l));
136 SnmpUInt32 u3(nl);
137 ACE_ASSERT(u3 == static_cast<unsigned long> (nl));
138 SnmpUInt32 u4(ul);
139 ACE_ASSERT(u4 == ul);
140 SnmpUInt32 u5(i);
141 ACE_ASSERT(u5 == static_cast<unsigned long> (i));
142 SnmpUInt32 u6(ni);
143 ACE_ASSERT(u6 == static_cast<unsigned long> (ni));
144 SnmpUInt32 u7(ui);
145 ACE_ASSERT(u7 == ui);
146 SnmpUInt32 *u8 = new SnmpUInt32(u5);
147 ACE_ASSERT(u8 != 0);
148 delete u8;
150 ACE_DEBUG ((LM_DEBUG, "(%P|%t) u1(\"\") [%u]\n",
151 (unsigned long)u1));
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));
165 // assignent
166 u1 = u2; // obj
167 ACE_ASSERT(u1 == u2);
168 u1 = u1; // self
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"));
184 TestInteger32();
186 TestUnsignedInteger32();
188 ACE_END_TEST;
189 return 0;