2 //=============================================================================
6 * Test all the member functions of the OCTET class. An Object
7 * representing an ASN.1 Integer64 SMI OCTET STRING SYNTAX.
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 "ace/OS_NS_string.h"
38 #include "asnmp/octet.h"
39 #include "test_config.h"
42 OctetStr( const char *string, long size = -1);
43 OctetStr ( const OctetStr &octet);
46 SmiUINT32 get_syntax();
47 void set_data( const SmiBYTE* string, long int size = -1);
48 OctetStr& operator=( const char *string);
49 OctetStr& operator=( const OctetStr &octet);
51 bool operator==( const OctetStr &lhs, const OctetStr &rhs);
52 bool operator!=( const OctetStr &lhs, const OctetStr &rhs);
53 bool operator<( const OctetStr &lhs, const OctetStr &rhs);
54 bool operator<=( const OctetStr &lhs,const OctetStr &rhs);
55 bool operator>( const OctetStr &lhs, const OctetStr &rhs);
56 bool operator>=( const OctetStr &lhs, const OctetStr &rhs);
57 bool operator==( const OctetStr &lhs,const char *rhs);
58 bool operator!=( const OctetStr &lhs,const char *rhs);
59 bool operator<( const OctetStr &lhs,const char *rhs);
60 bool operator<=( const OctetStr &lhs,char *rhs);
61 bool operator>( const OctetStr &lhs,const char *rhs);
62 bool operator>=( const OctetStr &lhs,const char *rhs);
63 OctetStr& operator+=( const SmiBYTE *a);
64 OctetStr& operator+=( const char c);
65 OctetStr& operator+=( const OctetStr& octetstr);
66 SmiBYTE& operator[]( int position);
67 int nCompare( const long n, const OctetStr &o) const;
68 size_t length() const ;
70 SmiBYTE *data() const;
72 char *to_string_hex();
73 SnmpSyntax *clone() const;
74 SnmpSyntax& operator=( SnmpSyntax &val);
77 static void TestOctet()
79 const char *str
= "A test of octet strings...!@@#$%^&*()_+|~{}:,./<>?";
81 ACE_ASSERT(o1
.valid() == 1);
82 ACE_ASSERT(o1
.length() == 0);
83 ACE_ASSERT(o1
.data() != (unsigned char *)0);
84 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o1(\"\") [%s]\n",
86 o1
.set_data((SmiBYTE
*)str
);
87 ACE_ASSERT(!ACE_OS::strcmp(str
, (char *)o1
.data()));
88 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o1(\"str\") [%s]\n",
92 ACE_ASSERT(o2
.valid() == 1);
93 ACE_ASSERT(o2
.data() != (unsigned char *)0);
94 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o2(\"str\") [%s]\n",
97 OctetStr
o3(str
, 4); // test setting less than full string length
98 ACE_ASSERT(o3
.valid() == 1);
99 ACE_ASSERT(o3
.length() == 4);
100 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o3(\"A te\") [%s]\n",
103 OctetStr
o4(o3
); // test setting less than full string length
104 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o4(\"A te\") [%s]\n",
106 ACE_ASSERT(o4
.valid() == 1);
107 ACE_ASSERT(o4
.length() == 4);
111 ACE_ASSERT(o5
.valid() == 1);
112 ACE_ASSERT(o5
.length() == ACE_OS::strlen(str
));
113 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o5(\"str\") [%s]\n",
118 ACE_ASSERT(o6
.valid() == 1);
119 ACE_ASSERT(o5
.length() == o6
.length());
120 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o6(\"str\") [%s]\n",
127 ACE_ASSERT(o6
[0] == (SmiBYTE
) 'A');
128 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Octet:o6(\"str\") [%s]\n",
131 ACE_ASSERT(!(o3
< o3
));
132 ACE_ASSERT(!(o3
> o3
));
133 ACE_ASSERT(o3
>= o3
);
134 ACE_ASSERT(o3
<= o3
);
135 ACE_ASSERT(o3
== o3
);
136 ACE_ASSERT(!(o3
!= o3
));
140 ACE_TMAIN (int, ACE_TCHAR
*[])
142 ACE_START_TEST (ACE_TEXT ("Octet_Test"));