Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / tests / Counter_Test.cpp
blob7432b9f1920a9c9d2b1ebef6108aaecfee990539
2 //=============================================================================
3 /**
4 * @file Counter_Test.cpp
6 * Test all the member functions of the Counter class. An Object
7 * representing an ASN.1 Counter SMI COUNTER 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/counter.h"
37 #include "test_config.h"
40 Counter32();
41 Counter32( const unsigned long i);
42 Counter32( const Counter32 &c);
43 * SmiUINT32 get_syntax();
44 * SnmpSyntax *clone() const;
45 * SnmpSyntax& operator=( SnmpSyntax &val);
46 Counter32& operator=( const Counter32 &uli);
47 Counter32& operator=( const unsigned long i);
48 operator unsigned long();
50 -- comments tyis type appears to be a wrapper class and not
51 a true SNMP counter. Practical for nms side,yet may lead to
52 some confusion if implementing an agent with this class.
54 Per RFC 1155 sec 3.2.3.3
55 This application-wide type represents a non-negative integer which
56 monotonically increases until it reaches a maximum value, when it
57 wraps around and starts increasing again from zero. This memo
58 specifies a maximum value of 2^32-1 for counters
61 static void TestCounter()
63 #if !defined (ACE_WIN32)
64 long l = LONG_MAX, nl = LONG_MIN; // limits.h
65 unsigned long ul = ULONG_MAX, def = 0;
66 int i = INT_MAX, ni = INT_MIN;
67 unsigned int ui = UINT_MAX;
68 unsigned short us = 10;
69 short si = static_cast<short> (65535);
71 // constructors
72 Counter32 c1;
73 ACE_ASSERT(c1 == def);
74 Counter32 c2(l);
75 ACE_ASSERT(c2 == static_cast<unsigned long> (l));
76 Counter32 c3(nl);
77 ACE_ASSERT(c3 == static_cast<unsigned long> (nl));
78 Counter32 c4(ul);
79 ACE_ASSERT(c4 == ul);
80 Counter32 c5(i);
81 ACE_ASSERT(c5 == static_cast<unsigned long> (i));
82 Counter32 c6(ni);
83 ACE_ASSERT(c6 == static_cast<unsigned long> (ni));
84 Counter32 c7(ui);
85 ACE_ASSERT(c7 == ui);
86 Counter32 *c8 = new Counter32(c5);
87 ACE_ASSERT(c8 != 0);
88 delete c8;
90 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c1(\"\") [%u]\n",
91 (unsigned long)c1));
92 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c2(\"%u\") [%u]\n",
93 l, (unsigned long)c2));
94 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c3(\"%u\") [%u]\n",
95 nl, (unsigned long)c3));
96 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c4(\"%u\") [%u]\n",
97 ul, (unsigned long)c4));
98 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c5(\"%u\") [%u]\n",
99 i, (unsigned long)c5));
100 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c6(\"%u\") [%u]\n",
101 ni, (unsigned long)c6));
102 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c7(\"%u\") [%u]\n",
103 ui, (unsigned long)c7));
105 // assignent
106 c1 = c2; // obj
107 ACE_ASSERT(c1 == c2);
108 c1 = c1; // self
109 ACE_ASSERT(c1 == c1);
110 c1 = def; // unsigned long
111 ACE_ASSERT(c1 == def);
112 c1 = us; // unsigned short
113 ACE_ASSERT(c1 == static_cast<unsigned long> (us));
114 c1 = si; // unsigned short
115 ACE_ASSERT(c1 == static_cast<unsigned long> (si));
116 #endif /*ACE_WIN32*/
121 ACE_TMAIN (int, ACE_TCHAR *[])
123 ACE_START_TEST (ACE_TEXT ("Counter_Test"));
125 TestCounter();
127 ACE_END_TEST;
128 return 0;