2 //=============================================================================
4 * @file Target_Test.cpp
6 * Test all the member functions of the Target class.
7 * Not sure if this object is really required or not in the new framework
9 * @author Michael R. MacFaden <mrm@cisco.com>
11 //=============================================================================
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/octet.h"
38 #include "asnmp/target.h"
39 #include "test_config.h"
42 Percieved Problems with this CTarget aka UdpTarget Interface:
44 1) can't set snmp version during constructor (default value?)
45 2) doesn't use ANSI C++ String class (still uses char *)
46 3) Makes it easy to mix up read and write comm strs (could be diff types)
47 3) so many get/set's, leads one to rethink the design/use of UdpTarget
48 4) Use of resolve_to_C smells like a HACK...
49 5) No valid() member function returns 1 even if no address given..
50 6) No to_string()?! (Fixed)
51 7) can't access retry, timeout parameters...
52 8) can't assign or equate two UdpTargets
55 UdpTarget( const Address &address);
56 UdpTarget( const UdpTarget &target);
57 UdpTarget( const Address &address, // address
58 const char *read_community_name, // read community name
59 const char *write_community_name); // write community name
60 UdpTarget( const Address &address, // address
61 const OctetStr &read_community_name, // read community
62 const OctetStr &write_community_name); // write community
65 SnmpTarget *clone() const;
66 void get_readcommunity( OctetStr& read_community_oct);
67 void set_readcommunity( const OctetStr& read_community);
68 void get_writecommunity( OctetStr &write_community_oct);
69 void set_writecommunity( const OctetStr& write_community);
70 void get_address( UdpAddress & address);
71 int set_address( Address &address);
72 snmp_version get_version();
73 void set_version( const snmp_version v);
75 UdpTarget& operator=( const UdpTarget& target);
76 friend bool operator==( const UdpTarget &lhs, const UdpTarget &rhs);
80 static void TestSnmpTarget()
82 OctetStr
rd("rd_comm"), wr("wr_comm");
83 ACE_ASSERT(rd
.valid() == 1);
84 ACE_ASSERT(wr
.valid() == 1);
86 // constructor and get tests
88 ACE_ASSERT(ga
.valid() == 0);
91 ACE_ASSERT(c1
.valid() == 0);
92 OctetStr a
, b("public"), c("private");
93 c1
.get_read_community(a
);
95 c1
.get_write_community(a
);
98 ACE_ASSERT(c1
.get_version() == version1
);
100 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) UdpTarget:c1(\"\") [%s]\n",
103 IpAddress
ip("127.0.0.1");
105 ACE_ASSERT(c2
.valid() == 1);
107 ACE_ASSERT(ga
.valid() == 1);
108 ACE_ASSERT(c2
.get_version() == version1
);
109 ACE_ASSERT(ga
.valid() == 1);
110 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) UdpTarget:c2(\"\") [%s]\n",
113 UdpTarget
*c5
= new UdpTarget(c2
);
115 ACE_ASSERT(c5
->valid() == 1);
116 c5
->get_address (ga
);
117 ACE_ASSERT(ga
.valid() == 1);
118 ACE_ASSERT(c5
->get_version() == version1
);
119 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) UdpTarget:c5(\"\") [%s]\n",
123 // these are not supported yet
124 // ACE_ASSERT(c5 == c5);
126 // ACE_ASSERT(c5 == c2);
130 ACE_TMAIN (int, ACE_TCHAR
*[])
132 ACE_START_TEST (ACE_TEXT ("Target_Test"));