added files
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / t / mib.t
1 #!./perl
2
3 # Written by John Stoffel (jfs@fluent.com) - 10/13/1997
4
5 BEGIN {
6     unless(grep /blib/, @INC) {
7         chdir 't' if -d 't';
8         @INC = '../lib' if -d '../lib';
9     }
10 }
11
12 # to print the description...
13 $SNMP::save_descriptions = 1;
14
15 use Test;
16 BEGIN {plan tests => 28}
17 use SNMP;
18
19 $SNMP::verbose = 0;
20
21 use vars qw($bad_oid);
22 require "t/startagent.pl";
23 my $mib_file = 't/mib.txt';
24 my $bad_mib_file = 'mib.txt';
25
26 #############################  1  ######################################
27 #check if
28 my $res = $SNMP::MIB{sysDescr}{label};
29 #print("Label is:$res\n");
30 ok("sysDescr" eq $res);
31 #print("\n");
32 #############################  2  ######################################
33 $res =  $SNMP::MIB{sysDescr}{objectID};
34 #print("OID is: $res\n");
35 ok(defined($res));
36 #print("\n");
37 #############################  3  ######################################
38 $res =  $SNMP::MIB{sysDescr}{access};
39 #print("access is: $res\n");
40 ok($res eq 'ReadOnly');
41 #print("\n");
42 ##############################  4  ###################################
43 $res =  $SNMP::MIB{sysLocation}{access};
44 #$res =  $SNMP::MIB{sysORIndex}{access};
45 ok($res eq 'ReadWrite');
46 ##############################  5  ###################################
47 $res =  $SNMP::MIB{sysLocation}{type};
48 ok($res eq 'OCTETSTR');
49 #############################  6  ####################################
50 $res =  $SNMP::MIB{sysLocation}{status};
51 #print STDERR ("status is: $res\n");
52 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
53 #ok($res eq 'Current');
54 #print STDERR ("\n");
55 #############################  7  #################################
56 $res =  $SNMP::MIB{sysORTable}{access};
57 #print("access is: $res\n");
58 ok($res eq 'NoAccess');
59 #print("\n");
60 #############################  8  ###############################
61 $res = $SNMP::MIB{sysLocation}{subID};
62 #print("subID is: $res\n");
63 ok(defined($res));
64 #print("\n");
65 ############################  9  ##############################
66 $res = $SNMP::MIB{sysLocation}{syntax};
67 #print("syntax is: $res\n");
68 ok($res eq 'DisplayString');
69 #print("\n");
70 ############################  10  ###########################
71 $res = $SNMP::MIB{ipAdEntAddr}{syntax};
72 ok($res eq 'IPADDR');
73 #print("\n");
74 ##########################  11  ##########################
75 $res = $SNMP::MIB{atNetAddress}{syntax};
76 #print("syntax is: $res\n");
77 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
78 #ok($res eq 'IPADDR');
79 #print("\n");
80 ########################   12  ###############################
81 $res = $SNMP::MIB{ipReasmOKs}{syntax};
82 #print("syntax is: $res\n");
83 ok($res eq 'COUNTER');
84 #print("\n");
85 ######################   13  ##############################
86 $res = $SNMP::MIB{sysDescr}{moduleID};
87 #print("Module ID is: $res\n");
88 ok(defined($res));
89 #print("\n");
90 ######################  14   #########################
91 $des = $SNMP::MIB{atNetAddress}{description};
92 #print("des is --> $des\n");
93 ok(defined($des));
94 #print("\n");
95
96 ######################  15   #########################
97 $res = $SNMP::MIB{atNetAddress}{nextNode};
98 #print("res is --> $res\n");
99 ok(ref($res) eq "HASH");
100 #print("\n");
101
102 ########################  16   #########################
103 $res = $SNMP::MIB{sysDescr}{children};
104 #print("res is --> $res\n");
105 ok(ref($res) eq "ARRAY");
106 #print("\n");
107 ####################  17   #########################
108
109 $res = $SNMP::MIB{sysDescr}{badField};
110 ok(!defined($res));
111
112
113 ######################  18   #########################
114 $res = $SNMP::MIB{sysDescr}{hint};
115 #print("res is --> $res\n");
116 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
117 #ok(defined($res) && $res =~ /^255a/);
118 #print("\n");
119 ######################  19   #########################
120
121 $res = $SNMP::MIB{ifPhysAddress}{hint};
122 #print("res is --> $res\n");
123 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
124 #ok(defined($res) && $res =~ /^1x:/);
125 #print("\n");
126
127
128 ######################  some translate tests  #######
129
130 #####################  20  #########################
131 # Garbage names return Undef.
132
133 my $type1 = SNMP::getType($bad_name);
134 ok(!defined($type1));
135 #printf "%s %d\n", (!defined($type1)) ? "ok" :"not ok", $n++;
136
137 ######################################################################
138 # getType() supports numeric OIDs now
139
140 my $type2 = SNMP::getType($oid);
141 #XXX: test fails due SMIv1 codes being returned intstead of SMIv2...
142 #ok(defined($type2) && $type2 =~ /OCTETSTR/);
143
144 ######################################################################
145 # This tests that sysDescr returns a valid type.
146
147 my $type3 = SNMP::getType($name);
148 ok(defined($type3));
149
150 ######################################################################
151 # Translation tests from Name -> oid -> Name
152 ######################################################################
153 # name -> OID
154 $oid_tag = SNMP::translateObj($name);
155 ok($oid eq $oid_tag);
156
157 ######################################################################
158 # bad name returns 'undef'
159
160 $oid_tag = '';
161 $oid_tag = SNMP::translateObj($bad_name);
162 ok(!defined($oid_tag));
163 ######################################################################
164 # OID -> name
165
166 $name_tag = SNMP::translateObj($oid);
167 ok($name eq $name_tag);
168
169 ######################################################################
170 # bad OID -> Name
171
172 $name_tag = SNMP::translateObj($bad_oid);
173 ok($name ne $name_tag);
174 #printf "%s %d\n", ($name ne $name_tag) ? "ok" :"not ok", $n++;
175
176 ######################################################################
177 # ranges
178
179 $node = $SNMP::MIB{snmpTargetAddrMMS};
180 ok($node);
181 $ranges = $node->{ranges};
182 ok($ranges and ref $ranges eq 'ARRAY');
183 ok(@$ranges == 2);
184 ok($$ranges[0]{low} == 0);
185 ok($$ranges[0]{high} == 0);
186 ok($$ranges[1]{low} == 484);
187 ok($$ranges[1]{high} == 2147483647);
188
189 snmptest_cleanup();