Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / tests / Counter64_Test.cpp
blob7ac4772cdb7ed038036ab10cb97506459dd5df30
2 //=============================================================================
3 /**
4 * @file Counter64_Test.cpp
6 * Test all the member functions of the Counter64 class. An Object
7 * representing an ASN.1 Counter64 SMI 64 bit Integer SYNTAX.
8 * (SNMPv2c)
10 * @author Michael R. MacFaden <mrm@cisco.com>
12 //=============================================================================
14 /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
15 Copyright 1997 Cisco Systems, Inc.
17 Permission to use, copy, modify, and distribute this software for any
18 purpose and without fee is hereby granted, provided that this
19 copyright and permission notice appear on all copies of the software and
20 supporting documentation, the name of Cisco Systems, Inc. not be used
21 in advertising or publicity pertaining to distribution of the
22 program without specific prior permission, and notice be given
23 in supporting documentation that modification, copying and distribution is by
24 permission of Cisco Systems, Inc.
26 Cisco Systems, Inc. makes no representations about the suitability of this
27 software for any purpose. THIS SOFTWARE IS PROVIDED ``AS IS''
28 AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
29 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGMENT AND
30 FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL CISCO SYSTEMS, INC. BE
31 LIABLE FOR ANY DAMAGES ARISING OUT OF THIS LICENSE OR YOUR USE OF THE
32 SOFTWARE INCLUDING WITHOUT LIMITATION, DIRECT, INDIRECT OR CONSEQUENTIAL
33 DAMAGES.
34 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
36 #include "ace/OS_main.h"
37 #include "asnmp/ctr64.h"
38 #include "test_config.h"
40 // TODO: verify this with ACE folks
41 #if defined(ACE_WIN32)
42 #define LLONG __int64
43 #define ULLONG unsigned __int64
44 #else
45 #define LLONG long long
46 #define ULLONG unsigned long long
47 #endif
50 Counter64( unsigned long long llw = 0);
51 Counter64( unsigned long hiparm, unsigned long loparm);
52 Counter64( const Counter64 &ctr64);
53 ~Counter64();
54 SmiUINT32 get_syntax();
55 long double to_long_double() const;
56 Counter64& assign( long double ld);
57 unsigned long high() const;
58 unsigned long low() const;
59 void set_high( const unsigned long h);
60 void set_low( const unsigned long l);
61 Counter64& operator=( const unsigned long long rhs);
62 Counter64& operator=( const Counter64 &rhs);
63 char *to_string();
64 SnmpSyntax *clone() const;
65 SnmpSyntax& operator=( SnmpSyntax &val);
66 int valid() const;
67 operator unsigned long long();
70 static void TestCounter64()
72 #if !defined (ACE_WIN32)
73 static unsigned long ul = ULONG_MAX;
74 LLONG ll = (LLONG) 0x7fffffffffffffffLL;
75 LLONG mll = (LLONG) ((-ll) - 1);
76 ULLONG ull = (ULLONG) 0xffffffffffffffffULL;
77 long double ld = (LLONG) ll;
79 cerr << "max unsigned long long is " << ull << endl;
80 cerr << "max long long is " << ll << endl;
81 cerr << "min long long is " << mll << endl;
83 Counter64 c1;
84 ACE_ASSERT(c1.valid() == 1);
85 Counter64 c2(ul, ul);
86 ACE_ASSERT(c2.valid() == 1);
87 ACE_ASSERT(c2.high() == ul);
88 ACE_ASSERT(c2.low() == ul);
90 Counter64 c3(ul);
91 ACE_ASSERT(c3.valid() == 1);
92 ACE_ASSERT(c3.low() == ul);
94 Counter64 c4(c2);
95 ACE_ASSERT(c4.valid() == 1);
96 ACE_ASSERT(c4.high() == ul);
97 ACE_ASSERT(c4.low() == ul);
99 Counter64 c5(0);
100 ACE_ASSERT(c5.valid() == 1);
102 Counter64 c6;
103 c6.assign(ld);
104 ACE_ASSERT(ACE::is_equal(c6.to_long_double(), ld));
106 Counter64 c7(ull);
107 ACE_ASSERT(c7 == ull);
110 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c1(\"\") [%s]\n",
111 c1.to_string()));
112 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c2(LONG_MAX,LONG_MAX) [%s]\n",
113 c2.to_string()));
114 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c3(LONG_MAX) [%s]\n",
115 c3.to_string()));
116 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c4(c2) [%s]\n",
117 c4.to_string()));
118 ACE_DEBUG ((LM_DEBUG, "(%P|%t) c5(0) [%s]\n",
119 c5.to_string()));
121 // misc routines
122 c1.set_low(1);
123 c1.set_high(2);
124 ACE_ASSERT(c1.low() == 1);
125 ACE_ASSERT(c1.high() == 2);
126 // assignment
127 c5 = c4;
128 ACE_ASSERT(c5 == c4);
129 c4 = c4;
130 ACE_ASSERT(c5 == c4);
131 c5 = ll;
132 ACE_ASSERT(c5 == static_cast<ACE_UINT64> (ll));
133 // try simple arithmetic (needs more test cases)
134 c5 = mll;
135 c5 = c5 + (ULLONG) 10;
136 ACE_ASSERT(c5 == static_cast<ACE_UINT64> (mll + 10));
137 #endif /*ACE_WIN32 */
141 ACE_TMAIN (int, ACE_TCHAR *[])
143 ACE_START_TEST (ACE_TEXT ("Counter64_Test"));
145 TestCounter64();
147 ACE_END_TEST;
148 return 0;