summaryrefslogtreecommitdiff
path: root/ASNMP/tests/Counter_Test.cpp
blob: 061f469f6a55fc5837346296bdab76b99e0ad590 (plain)
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
/* -*- C++ -*- */
// $Id$
 
// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    Counter_Test.cpp
//
// = DESCRIPTION
//  Test all the member functions of the Counter class. An Object 
//  representing an ASN.1 Counter SMI COUNTER SYNTAX. 
// = 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.h"
#include "asnmp/counter.h"
#include "test_config.h"

// hack: do this so when linking SUNC 4.x compiler will instantiate template
#include "ace/Containers.h"
ACE_Unbounded_Set<ACE_Log_Msg*> x;


/*
   Counter32( void);
   Counter32( const unsigned long i);
   Counter32( const Counter32 &c);
*  SmiUINT32 get_syntax();
*  SnmpSyntax *clone() const;
*  SnmpSyntax& operator=( SnmpSyntax &val);
   Counter32& operator=( const Counter32 &uli);
   Counter32& operator=( const unsigned long i);
   operator unsigned long();

 --  comments tyis type appears to be a wrapper class and not
     a true SNMP counter. Practical for nms side,yet may lead to 
     some confusion if implementing an agent with this class.

  Per RFC 1155 sec 3.2.3.3
   This application-wide type represents a non-negative integer which
   monotonically increases until it reaches a maximum value, when it
  wraps around and starts increasing again from zero. This memo
  specifies a maximum value of 2^32-1 for counters
*/

static void  TestCounter()
{
   long l = LONG_MAX, nl = LONG_MIN;  // limits.h
   unsigned long ul = ULONG_MAX, def = 0;
   int i = INT_MAX, ni = INT_MIN;
   unsigned int ui = UINT_MAX;
   unsigned short us = 10;
   short si = 65535;

   // constructors
   Counter32 c1;
   ACE_ASSERT(c1 == def); 
   Counter32 c2(l);
   ACE_ASSERT(c2 == l); 
   Counter32 c3(nl);
   ACE_ASSERT(c3 == nl); 
   Counter32 c4(ul);
   ACE_ASSERT(c4 == ul); 
   Counter32 c5(i);
   ACE_ASSERT(c5 == i); 
   Counter32 c6(ni);
   ACE_ASSERT(c6 == ni); 
   Counter32 c7(ui);
   ACE_ASSERT(c7 == ui); 
   Counter32 *c8 = new Counter32(c5);
   ACE_ASSERT(c8 != 0);
   delete c8;

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c1(\"\") [%u]\n",
    (unsigned long)c1));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c2(\"%u\") [%u]\n",
    l, (unsigned long)c2));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c3(\"%u\") [%u]\n",
    nl, (unsigned long)c3));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c4(\"%u\") [%u]\n",
    ul, (unsigned long)c4));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c5(\"%u\") [%u]\n",
    i, (unsigned long)c5));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c6(\"%u\") [%u]\n",
    ni, (unsigned long)c6));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c7(\"%u\") [%u]\n",
    ui, (unsigned long)c7));

  // assignent
  c1 = c2;  // obj
  ACE_ASSERT(c1 == c2); 
  c1 = c1; // self
  ACE_ASSERT(c1 == c1); 
  c1 = def; // unsigned long
  ACE_ASSERT(c1 == def); 
  c1 = us; // unsigned short
  ACE_ASSERT(c1 == us); 
  c1 = si; // unsigned short
  ACE_ASSERT(c1 == si); 

}


int
main (int, char *[])
{
  ACE_START_TEST ("Counter_Test");

  TestCounter(); 

  ACE_END_TEST;
  return 0;
}


#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Unbounded_Set<ACE_Log_Msg*>;
#endif