Debian Codegraph @

perl/OID/test.pl

raw
1 #!./perl
2 #
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl test.pl'
5
6 use strict;
7 use warnings;
8 use Cwd qw(abs_path);
9 use Test;
10
11 BEGIN {
12 plan tests => 38;
13 }
14
15 require "../SNMP/t/readsnmptest.pl";
16 use NetSNMP::OID;
17
18 ok(1); # If we made it this far, we're ok.
19
20 #########################
21
22 # Insert your test code below, the Test module is use()ed here so read
23 # its man page ( perldoc Test ) for help writing this test script.
24
25 my $oid = new NetSNMP::OID(".1.3.6.1");
26 ok(ref($oid) eq "NetSNMP::OID");
27 ok(ref($oid->{oidptr}) eq "netsnmp_oidPtr");
28 #print STDERR ref($oid),"\n";
29
30 my $tostring = "$oid";
31 #print STDERR "$tostring\n";
32 ok($tostring eq "internet");
33
34 my $oid2 = new NetSNMP::OID(".1.3.6.1.2");
35 $tostring = "$oid2";
36 #print STDERR "$tostring\n";
37 ok($tostring eq "mgmt");
38
39 my $oid3 = new NetSNMP::OID(".1.3.6.1");
40
41 my $val = NetSNMP::OID::snmp_oid_compare($oid, $oid2);
42 #print STDERR "compare result: $val\n";
43 ok($val == -1);
44
45 $val = $oid2->snmp_oid_compare($oid);
46 #print STDERR "compare result: $val\n";
47 ok($val == 1);
48
49 $val = NetSNMP::OID::compare($oid, $oid);
50 #print STDERR "compare result: $val\n";
51 ok($val == 0);
52
53 $val = $oid->compare($oid3);
54 #print STDERR "compare result: $val\n";
55 ok($val == 0);
56
57 ok(($oid <=> $oid2) == -1);
58 ok(($oid2 <=> $oid) == 1);
59 ok(($oid <=> $oid3) == 0);
60
61 ok($oid < $oid2);
62 ok($oid <= $oid2);
63 ok($oid2 > $oid);
64 ok($oid2 >= $oid);
65 ok($oid == $oid3);
66 ok($oid <= $oid3);
67 ok($oid >= $oid3);
68
69 ok(new NetSNMP::OID('system') < new NetSNMP::OID('interfaces'));
70 ok(new NetSNMP::OID('interfaces') > new NetSNMP::OID('system'));
71 ok(new NetSNMP::OID('sysORTable') > new NetSNMP::OID('system'));
72
73 my @a = $oid->to_array();
74 ok($a[0] == 1 && $a[1] == 3 && $a[2] == 6 && $a[3] == 1 && $#a == 3);
75
76 $oid->append(".1.2.3");
77 ok("$oid" eq "directory.2.3");
78
79 my $oidmore = $oid + ".8.9.10";
80 ok($oidmore == new NetSNMP::OID("directory.2.3.8.9.10"));
81 ok("$oid" eq "directory.2.3");
82 ok(ref($oidmore) eq "NetSNMP::OID");
83
84 # += should work
85 $oidmore += ".11";
86 ok($oidmore == new NetSNMP::OID("directory.2.3.8.9.10.11"));
87
88 my $oidstr = $oidmore + "\"wes\"";
89 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.3.119.101.115"));
90
91 $oidstr = $oidmore + "\'wes\'";
92 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.119.101.115"));
93
94 # just make sure you can do it twice (ie, not modify the original)
95 $oidstr = $oidmore + "\'wes\'";
96 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.119.101.115"));
97
98 $oidstr = $oidmore + "internet";
99 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.1.3.6.1"));
100
101 $oidstr = $oidmore + "999";
102 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.999"));
103
104 $oidstr = $oidmore + (new NetSNMP::OID(".1.3.6.1"));
105 ok($oidstr == new NetSNMP::OID("directory.2.3.8.9.10.11.1.3.6.1"));
106
107 $oid = new NetSNMP::OID("nosuchoidexists");
108 ok(ref($oid) ne "NetSNMP::OID");
109
110 ok($oidstr->length() == 15);
111
112 # multiple encoded values
113 my $newtest = new NetSNMP::OID ("nsModuleName.5.109.121.99.116.120.2.1.3.14");
114
115 if ($newtest) {
116 my $arrayback = $newtest->get_indexes();
117
118 ok($#$arrayback == 2 &&
119 $arrayback->[0] eq 'myctx' &&
120 $arrayback->[1] eq '.1.3' &&
121 $arrayback->[2] eq '14'
122 );
123 }
124 else {
125 ok(0);
126 }
127
128 # implied string
129 $newtest = new NetSNMP::OID ("snmpNotifyRowStatus.105.110.116.101.114.110.97.108.48");
130
131 if ($newtest) {
132 my $arrayback = $newtest->get_indexes();
133
134 ok($#$arrayback == 0 &&
135 $arrayback->[0] eq 'internal0'
136 );
137 }
138 else {
139 ok(0);
140 }
141
142
143