Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / test / lua / pinfo.lua
blob4ea613036db3d6649704f58dcd08eb6ae09456cc
1 -- test script for Pinfo and Address functions
2 -- use with dhcp.pcap in test/captures directory
4 ------------- general test helper funcs ------------
5 local testlib = require("testlib")
6 local FRAME = "frame"
7 local DENIED = "denied"
8 local GETTER = "getter"
9 local SETTER = "setter"
10 local ADDR = "address"
11 local OTHER = "other"
13 -- expected number of runs per type
14 local n_frames = 4
15 local taptests = {
16 [FRAME]=n_frames,
17 [DENIED]=n_frames*32,
18 [GETTER]=n_frames*39,
19 [SETTER]=n_frames*16,
20 [ADDR]=n_frames*6,
21 [OTHER]=n_frames*2,
23 testlib.init(taptests)
25 ---------
26 -- the following are so we can use pcall (which needs a function to call)
27 local function setPinfo(pinfo,name,value)
28 pinfo[name] = value
29 end
31 local function getPinfo(pinfo,name)
32 local foo = pinfo[name]
33 end
35 ------------- test script ------------
38 local tap = Listener.new()
41 function tap.packet(pinfo,tvb)
42 testlib.countPacket(FRAME)
43 testlib.testing(FRAME,"Pinfo in Frame")
45 testlib.test(OTHER,"typeof-1", typeof(pinfo) == "Pinfo")
47 testlib.test(OTHER,"tostring-1", tostring(pinfo) == "a Pinfo")
49 testlib.testing(FRAME,"negative tests")
51 -- try to set read-only attributes
52 testlib.test(DENIED,"Pinfo.number-set-1",not pcall(setPinfo,pinfo,"number",0))
53 testlib.test(DENIED,"Pinfo.len-set-1",not pcall(setPinfo,pinfo,"len",0))
54 testlib.test(DENIED,"Pinfo.caplen-set-1",not pcall(setPinfo,pinfo,"caplen",0))
55 testlib.test(DENIED,"Pinfo.rel_ts-set-1",not pcall(setPinfo,pinfo,"rel_ts",0))
56 testlib.test(DENIED,"Pinfo.delta_ts-set-1",not pcall(setPinfo,pinfo,"delta_ts",0))
57 testlib.test(DENIED,"Pinfo.delta_dis_ts-set-1",not pcall(setPinfo,pinfo,"delta_dis_ts",0))
58 testlib.test(DENIED,"Pinfo.visited-set-1",not pcall(setPinfo,pinfo,"visited",0))
59 testlib.test(DENIED,"Pinfo.lo-set-1",not pcall(setPinfo,pinfo,"lo",0))
60 testlib.test(DENIED,"Pinfo.hi-set-1",not pcall(setPinfo,pinfo,"hi",0))
61 testlib.test(DENIED,"Pinfo.match-set-1",not pcall(setPinfo,pinfo,"match",0))
62 testlib.test(DENIED,"Pinfo.curr_proto-set-1",not pcall(setPinfo,pinfo,"curr_proto",0))
63 testlib.test(DENIED,"Pinfo.columns-set-1",not pcall(setPinfo,pinfo,"columns",0))
64 testlib.test(DENIED,"Pinfo.cols-set-1",not pcall(setPinfo,pinfo,"cols",0))
65 testlib.test(DENIED,"Pinfo.private-set-1",not pcall(setPinfo,pinfo,"private",0))
66 testlib.test(DENIED,"Pinfo.fragmented-set-1",not pcall(setPinfo,pinfo,"fragmented",0))
67 testlib.test(DENIED,"Pinfo.in_error_pkt-set-1",not pcall(setPinfo,pinfo,"in_error_pkt",0))
68 testlib.test(DENIED,"Pinfo.match_uint-set-1",not pcall(setPinfo,pinfo,"match_uint",0))
69 testlib.test(DENIED,"Pinfo.match_string-set-1",not pcall(setPinfo,pinfo,"match_string",0))
71 -- wrong type being set
72 testlib.test(DENIED,"Pinfo.src-set-1",not pcall(setPinfo,pinfo,"src","foobar"))
73 testlib.test(DENIED,"Pinfo.dst-set-1",not pcall(setPinfo,pinfo,"dst","foobar"))
74 testlib.test(DENIED,"Pinfo.dl_src-set-1",not pcall(setPinfo,pinfo,"dl_src","foobar"))
75 testlib.test(DENIED,"Pinfo.dl_dst-set-1",not pcall(setPinfo,pinfo,"dl_dst","foobar"))
76 testlib.test(DENIED,"Pinfo.net_src-set-1",not pcall(setPinfo,pinfo,"net_src","foobar"))
77 testlib.test(DENIED,"Pinfo.net_dst-set-1",not pcall(setPinfo,pinfo,"net_dst","foobar"))
78 testlib.test(DENIED,"Pinfo.port_type-set-1",not pcall(setPinfo,pinfo,"port_type","foobar"))
79 testlib.test(DENIED,"Pinfo.src_port-set-1",not pcall(setPinfo,pinfo,"src_port","foobar"))
80 testlib.test(DENIED,"Pinfo.dst_port-set-1",not pcall(setPinfo,pinfo,"dst_port","foobar"))
81 testlib.test(DENIED,"Pinfo.can_desegment-set-1",not pcall(setPinfo,pinfo,"can_desegment","foobar"))
82 testlib.test(DENIED,"Pinfo.desegment_len-set-1",not pcall(setPinfo,pinfo,"desegment_len","foobar"))
83 testlib.test(DENIED,"Pinfo.desegment_offset-set-1",not pcall(setPinfo,pinfo,"desegment_offset","foobar"))
85 -- invalid attribute names
86 testlib.test(DENIED,"Pinfo.set-1",not pcall(setPinfo,pinfo,"foobar","foobar"))
87 testlib.test(DENIED,"Pinfo.get-12",not pcall(getPinfo,pinfo,"foobar"))
89 testlib.testing(FRAME,"basic getter tests")
91 local pktlen, srcip, dstip, srcport, dstport
93 if pinfo.number == 1 or pinfo.number == 3 then
94 pktlen = 314
95 srcip = "0.0.0.0"
96 dstip = "255.255.255.255"
97 srcport = 68
98 dstport = 67
99 else
100 pktlen = 342
101 srcip = "192.168.0.1"
102 dstip = "192.168.0.10"
103 srcport = 67
104 dstport = 68
107 testlib.test(GETTER,"Pinfo.number-get-1",pinfo.number == testlib.getPktCount(FRAME))
108 testlib.test(GETTER,"Pinfo.len-get-1",pinfo.len == pktlen)
109 testlib.test(GETTER,"Pinfo.caplen-get-1",pinfo.caplen == pktlen)
110 testlib.test(GETTER,"Pinfo.visited-get-1",pinfo.visited == true)
111 testlib.test(GETTER,"Pinfo.lo-get-1",tostring(pinfo.lo) == srcip)
112 testlib.test(GETTER,"Pinfo.lo-get-2",typeof(pinfo.lo) == "Address")
113 testlib.test(GETTER,"Pinfo.hi-get-1",tostring(pinfo.hi) == dstip)
114 testlib.test(GETTER,"Pinfo.hi-get-2",typeof(pinfo.hi) == "Address")
115 testlib.test(GETTER,"Pinfo.port_type-get-1",pinfo.port_type == 3)
116 testlib.test(GETTER,"Pinfo.match-get-1",pinfo.match == 0)
117 testlib.test(GETTER,"Pinfo.curr_proto-get-1",tostring(pinfo.curr_proto) == "<Missing Protocol Name>")
118 testlib.test(GETTER,"Pinfo.columns-get-1",tostring(pinfo.columns) == "Columns")
119 testlib.test(GETTER,"Pinfo.columns-get-2",typeof(pinfo.columns) == "Columns")
120 testlib.test(GETTER,"Pinfo.cols-get-1",tostring(pinfo.cols) == "Columns")
121 testlib.test(GETTER,"Pinfo.cols-get-2",typeof(pinfo.cols) == "Columns")
122 testlib.test(GETTER,"Pinfo.private-get-1",type(pinfo.private) == "userdata")
123 testlib.test(GETTER,"Pinfo.fragmented-get-1",pinfo.fragmented == false)
125 testlib.test(GETTER,"Pinfo.in_error_pkt-get-1",pinfo.in_error_pkt == false)
126 testlib.test(GETTER,"Pinfo.match_uint-get-1",pinfo.match_uint == 0)
127 testlib.test(GETTER,"Pinfo.match_string-get-1",pinfo.match_string == nil)
129 testlib.test(GETTER,"Pinfo.src-get-1",tostring(pinfo.src) == srcip)
130 testlib.test(GETTER,"Pinfo.src-get-2",typeof(pinfo.src) == "Address")
131 testlib.test(GETTER,"Pinfo.dst-get-1",tostring(pinfo.dst) == dstip)
132 testlib.test(GETTER,"Pinfo.dst-get-2",typeof(pinfo.dst) == "Address")
134 testlib.test(GETTER,"Pinfo.dl_src-get-1",typeof(pinfo.dl_src) == "Address")
135 testlib.test(GETTER,"Pinfo.dl_dst-get-1",typeof(pinfo.dl_dst) == "Address")
136 testlib.test(GETTER,"Pinfo.net_src-get-1",tostring(pinfo.net_src) == srcip)
137 testlib.test(GETTER,"Pinfo.net_src-get-2",typeof(pinfo.net_src) == "Address")
138 testlib.test(GETTER,"Pinfo.net_dst-get-1",tostring(pinfo.net_dst) == dstip)
139 testlib.test(GETTER,"Pinfo.net_dst-get-2",typeof(pinfo.net_dst) == "Address")
140 testlib.test(GETTER,"Pinfo.src_port-get-1",pinfo.src_port == srcport)
141 testlib.test(GETTER,"Pinfo.dst_port-get-1",pinfo.dst_port == dstport)
142 testlib.test(GETTER,"Pinfo.can_desegment-get-1",pinfo.can_desegment == 0)
143 testlib.test(GETTER,"Pinfo.desegment_len-get-1",pinfo.desegment_len == 0)
144 testlib.test(GETTER,"Pinfo.desegment_offset-get-1",pinfo.desegment_offset == 0)
146 testlib.test(GETTER,"pinfo.p2p_dir", pinfo.p2p_dir == P2P_DIR_UNKNOWN)
148 if pinfo.number == 1 then
149 testlib.test(GETTER,"Pinfo.rel_ts-get-1",pinfo.rel_ts == 0)
150 testlib.test(GETTER,"Pinfo.delta_ts-get-1",pinfo.delta_ts == 0)
151 testlib.test(GETTER,"Pinfo.delta_dis_ts-get-1",pinfo.delta_dis_ts == 0)
152 elseif pinfo.number == 2 then
153 testlib.test(GETTER,"Pinfo.rel_ts-get-1",pinfo.rel_ts == 0.000295)
154 testlib.test(GETTER,"Pinfo.delta_ts-get-1",pinfo.delta_ts == 0.000295)
155 testlib.test(GETTER,"Pinfo.delta_dis_ts-get-1",pinfo.delta_dis_ts == 0.000295)
156 elseif pinfo.number == 3 then
157 testlib.test(GETTER,"Pinfo.rel_ts-get-1",pinfo.rel_ts == 0.070031)
158 testlib.test(GETTER,"Pinfo.delta_ts-get-1",pinfo.delta_ts == 0.069736)
159 testlib.test(GETTER,"Pinfo.delta_dis_ts-get-1",pinfo.delta_dis_ts == 0.069736)
160 elseif pinfo.number == 4 then
161 testlib.test(GETTER,"Pinfo.rel_ts-get-1",pinfo.rel_ts == 0.070345)
162 testlib.test(GETTER,"Pinfo.delta_ts-get-1",pinfo.delta_ts == 0.000314)
163 testlib.test(GETTER,"Pinfo.delta_dis_ts-get-1",pinfo.delta_dis_ts == 0.000314)
167 testlib.testing(FRAME,"basic setter tests")
169 local tmp = pinfo.src
170 pinfo.src = pinfo.dst
171 pinfo.dst = tmp
172 testlib.test(SETTER,"Pinfo.src-set-1",tostring(pinfo.src) == dstip)
173 testlib.test(SETTER,"Pinfo.src-set-1",typeof(pinfo.src) == "Address")
174 testlib.test(SETTER,"Pinfo.dst-set-1",tostring(pinfo.dst) == srcip)
175 testlib.test(SETTER,"Pinfo.dst-set-1",typeof(pinfo.dst) == "Address")
177 local dl_dst_val = tostring(pinfo.dl_dst)
178 local dl_src_val = tostring(pinfo.dl_src)
179 tmp = pinfo.dl_src
180 pinfo.dl_src = pinfo.dl_dst
181 pinfo.dl_dst = tmp
182 testlib.test(SETTER,"Pinfo.dl_src-set-1",tostring(pinfo.dl_src) == dl_dst_val)
183 testlib.test(SETTER,"Pinfo.dl_dst-set-1",tostring(pinfo.dl_dst) == dl_src_val)
185 tmp = pinfo.net_src
186 pinfo.net_src = pinfo.net_dst
187 pinfo.net_dst = tmp
188 testlib.test(SETTER,"Pinfo.net_src-set-1",tostring(pinfo.net_src) == dstip)
189 testlib.test(SETTER,"Pinfo.net_src-set-1",typeof(pinfo.net_src) == "Address")
190 testlib.test(SETTER,"Pinfo.net_dst-set-1",tostring(pinfo.net_dst) == srcip)
191 testlib.test(SETTER,"Pinfo.net_dst-set-1",typeof(pinfo.net_dst) == "Address")
193 pinfo.port_type = 2
194 testlib.test(SETTER,"Pinfo.port_type-set-1",pinfo.port_type == 2)
196 tmp = pinfo.src_port
197 pinfo.src_port = pinfo.dst_port
198 pinfo.dst_port = tmp
199 testlib.test(SETTER,"Pinfo.src_port-set-1",pinfo.src_port == dstport)
200 testlib.test(SETTER,"Pinfo.dst_port-set-1",pinfo.dst_port == srcport)
202 pinfo.can_desegment = 12
203 testlib.test(SETTER,"Pinfo.can_desegment-set-1",pinfo.can_desegment == 12)
204 pinfo.desegment_len = 34
205 testlib.test(SETTER,"Pinfo.desegment_len-set-1",pinfo.desegment_len == 34)
206 pinfo.desegment_offset = 45
207 testlib.test(SETTER,"Pinfo.desegment_offset-set-1",pinfo.desegment_offset == 45)
209 testlib.testing(FRAME,"Address functions")
210 testlib.test(ADDR,"Address-eq-1", pinfo.lo == pinfo.dst)
211 testlib.test(ADDR,"Address-eq-2", pinfo.lo ~= pinfo.hi)
212 testlib.test(ADDR,"Address-lt-1", pinfo.lo < pinfo.hi)
213 testlib.test(ADDR,"Address-lt-2", pinfo.hi > pinfo.lo)
214 testlib.test(ADDR,"Address-le-1", pinfo.lo <= pinfo.hi)
215 testlib.test(ADDR,"Address-le-2", pinfo.lo <= pinfo.dst)
217 testlib.pass(FRAME)
221 function tap.draw()
222 testlib.getResults()