2 //=============================================================================
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.
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
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)
43 #define ULLONG unsigned __int64
45 #define LLONG long long
46 #define ULLONG unsigned long long
50 Counter64( unsigned long long llw = 0);
51 Counter64( unsigned long hiparm, unsigned long loparm);
52 Counter64( const Counter64 &ctr64);
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);
64 SnmpSyntax *clone() const;
65 SnmpSyntax& operator=( SnmpSyntax &val);
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
;
84 ACE_ASSERT(c1
.valid() == 1);
86 ACE_ASSERT(c2
.valid() == 1);
87 ACE_ASSERT(c2
.high() == ul
);
88 ACE_ASSERT(c2
.low() == ul
);
91 ACE_ASSERT(c3
.valid() == 1);
92 ACE_ASSERT(c3
.low() == ul
);
95 ACE_ASSERT(c4
.valid() == 1);
96 ACE_ASSERT(c4
.high() == ul
);
97 ACE_ASSERT(c4
.low() == ul
);
100 ACE_ASSERT(c5
.valid() == 1);
104 ACE_ASSERT(ACE::is_equal(c6
.to_long_double(), ld
));
107 ACE_ASSERT(c7
== ull
);
110 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) c1(\"\") [%s]\n",
112 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) c2(LONG_MAX,LONG_MAX) [%s]\n",
114 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) c3(LONG_MAX) [%s]\n",
116 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) c4(c2) [%s]\n",
118 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) c5(0) [%s]\n",
124 ACE_ASSERT(c1
.low() == 1);
125 ACE_ASSERT(c1
.high() == 2);
128 ACE_ASSERT(c5
== c4
);
130 ACE_ASSERT(c5
== c4
);
132 ACE_ASSERT(c5
== static_cast<ACE_UINT64
> (ll
));
133 // try simple arithmetic (needs more test cases)
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"));