summaryrefslogtreecommitdiff
path: root/ASNMP/tests/Target_Test.cpp
blob: d843057215de97c4755b0dedde9ac016533cfbcc (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
146
147
148
149
150
151
152
153
154
/* -*- C++ -*- */
// $Id$
 
// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    Target_Test.cpp
//
// = DESCRIPTION
//  Test all the member functions of the Target class. 
//  Not sure if this object is really required or not in the new framework
// 
// = 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/octet.h"
#include "asnmp/target.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;
 
/*
  Percieved Problems with this CTarget aka UdpTarget Interface:

  1) can't set snmp version during constructor (default value?)
  2) doesn't use ANSI C++ String class (still uses char *) 
  3) Makes it easy to mix up read and write comm strs (could be diff types) 
  3) so many get/set's, leads one to rethink the design/use of UdpTarget
  4) Use of resolve_to_C smells like a HACK...
  5) No valid() member function returns 1 even if no address given..
  6) No to_string()?!  (Fixed)
  7) can't access retry, timeout parameters...
  8) can't assign or equate two UdpTargets

    UdpTarget( void);
    UdpTarget( const Address &address);
    UdpTarget( const UdpTarget &target);
    UdpTarget( const Address &address,              // address
             const char *read_community_name,     // read community name
             const char *write_community_name);   // write community name
    UdpTarget( const Address &address,                 // address
             const OctetStr &read_community_name,    // read community
             const OctetStr &write_community_name);  // write community
    ~UdpTarget();

    SnmpTarget *clone() const;
    void get_readcommunity( OctetStr& read_community_oct);
    void set_readcommunity( const OctetStr& read_community);
    void get_writecommunity( OctetStr &write_community_oct);
    void set_writecommunity( const OctetStr& write_community);
    void get_address( UdpAddress & address);
    int set_address( Address &address);
    snmp_version get_version();
    void set_version( const snmp_version v);

    UdpTarget& operator=( const UdpTarget& target);
    friend int operator==( const UdpTarget &lhs, const UdpTarget &rhs);

 */ 

static void TestSnmpTarget()
{
  OctetStr rd("rd_comm"), wr("wr_comm");
  ACE_ASSERT(rd.valid() == 1);
  ACE_ASSERT(wr.valid() == 1);
  char *crd = "rd_comm", *cwr = "wr_comm";

  // constructor and get tests
  UdpAddress ga;
  ACE_ASSERT(ga.valid() == 0);

  UdpTarget c1;
  ACE_ASSERT(c1.valid() == 0);
  OctetStr a, b("public"), c("private");
  c1.get_read_community(a);
  ACE_ASSERT(a == b);
  c1.get_write_community(a);
  ACE_ASSERT(a == c);
  c1.get_address (ga); 
  ACE_ASSERT(c1.get_version() == version1); 

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c1(\"\") [%s]\n",
    c1.to_string()));

  IpAddress ip("127.0.0.1");
  UdpTarget c2(ip);
  ACE_ASSERT(c2.valid() == 1);
  c2.get_address (ga); 
  ACE_ASSERT(ga.valid() == 1);
  ACE_ASSERT(c2.get_version() == version1); 
  ACE_ASSERT(ga.valid() == 1);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c2(\"\") [%s]\n",
    c2.to_string()));

  UdpTarget *c5 = new UdpTarget(c2);
  ACE_ASSERT(c5 != 0);
  ACE_ASSERT(c5->valid() == 1);
  c5->get_address (ga);
  ACE_ASSERT(ga.valid() == 1);
  ACE_ASSERT(c5->get_version() == version1); 
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c5(\"\") [%s]\n",
    c5->to_string()));
  delete c5;

// these are not supported yet
//   ACE_ASSERT(c5 == c5);
//   c5 = c2;
//  ACE_ASSERT(c5 == c2);
}

int
main (int, char *[])
{
  ACE_START_TEST ("Target_Test");
  TestSnmpTarget();
 
  ACE_END_TEST;
  return 0;
}

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