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