match_strval > try_val_to_str
[wireshark-wip.git] / tools / dftestlib / string_type.py
blob37eb7e33d0642fe287341cf17e1440243c786c62
1 # Copyright (c) 2013 by Gilbert Ramirez <gram@alumni.rice.edu>
3 # $Id$
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 from dftestlib import dftest
22 class testString(dftest.DFTest):
23 trace_file = "http.pcap"
25 def test_eq_1(self):
26 dfilter = 'http.request.method == "HEAD"'
27 self.assertDFilterCount(dfilter, 1)
29 def test_eq_2(self):
30 dfilter = 'http.request.method == "POST"'
31 self.assertDFilterCount(dfilter, 0)
33 def test_gt_1(self):
34 dfilter = 'http.request.method > "HEAC"'
35 self.assertDFilterCount(dfilter, 1)
37 def test_gt_2(self):
38 dfilter = 'http.request.method > "HEAD"'
39 self.assertDFilterCount(dfilter, 0)
41 def test_gt_3(self):
42 dfilter = 'http.request.method > "HEAE"'
43 self.assertDFilterCount(dfilter, 0)
45 def test_ge_1(self):
46 dfilter = 'http.request.method >= "HEAC"'
47 self.assertDFilterCount(dfilter, 1)
49 def test_ge_2(self):
50 dfilter = 'http.request.method >= "HEAD"'
51 self.assertDFilterCount(dfilter, 1)
53 def test_ge_3(self):
54 dfilter = 'http.request.method >= "HEAE"'
55 self.assertDFilterCount(dfilter, 0)
57 def test_lt_1(self):
58 dfilter = 'http.request.method < "HEAC"'
59 self.assertDFilterCount(dfilter, 0)
61 def test_lt_2(self):
62 dfilter = 'http.request.method < "HEAD"'
63 self.assertDFilterCount(dfilter, 0)
65 def test_lt_3(self):
66 dfilter = 'http.request.method < "HEAE"'
67 self.assertDFilterCount(dfilter, 1)
69 def test_le_1(self):
70 dfilter = 'http.request.method <= "HEAC"'
71 self.assertDFilterCount(dfilter, 0)
73 def test_le_2(self):
74 dfilter = 'http.request.method <= "HEAD"'
75 self.assertDFilterCount(dfilter, 1)
77 def test_le_3(self):
78 dfilter = 'http.request.method <= "HEAE"'
79 self.assertDFilterCount(dfilter, 1)
81 def test_slice_1(self):
82 dfilter = 'http.request.method[0] == "H"'
83 self.assertDFilterCount(dfilter, 1)
85 def test_slice_2(self):
86 dfilter = 'http.request.method[0] == "P"'
87 self.assertDFilterCount(dfilter, 0)
89 def test_slice_3(self):
90 dfilter = 'http.request.method[0:4] == "HEAD"'
91 self.assertDFilterCount(dfilter, 1)
93 def test_slice_4(self):
94 dfilter = 'http.request.method[0:4] != "HEAD"'
95 self.assertDFilterCount(dfilter, 0)
97 def test_slice_5(self):
98 dfilter = 'http.request.method[1:2] == "EA"'
99 self.assertDFilterCount(dfilter, 1)
101 def test_slice_6(self):
102 dfilter = 'http.request.method[1:2] > "EA"'
103 self.assertDFilterCount(dfilter, 0)
105 def test_slice_7(self):
106 dfilter = 'http.request.method[-1] == "D"'
107 self.assertDFilterCount(dfilter, 1)
109 def test_slice_8(self):
110 dfilter = 'http.request.method[-2] == "D"'
111 self.assertDFilterCount(dfilter, 0)
113 def xxxtest_stringz_1(self):
114 return self.DFilterCount(pkt_tftp,
115 'tftp.type == "octet"', 1)
117 def xxxtest_stringz_2(self):
118 return self.DFilterCount(pkt_tftp,
119 'tftp.type == "junk"', 0)
121 def test_contains_1(self):
122 dfilter = 'http.request.method contains "E"'
123 self.assertDFilterCount(dfilter, 1)
125 def test_contains_2(self):
126 dfilter = 'http.request.method contains "EA"'
127 self.assertDFilterCount(dfilter, 1)
129 def test_contains_3(self):
130 dfilter = 'http.request.method contains "HEAD"'
131 self.assertDFilterCount(dfilter, 1)
133 def test_contains_4(self):
134 dfilter = 'http.request.method contains "POST"'
135 self.assertDFilterCount(dfilter, 0)
137 def test_contains_5(self):
138 dfilter = 'http.request.method contains 50:4f:53:54' # "POST"
139 self.assertDFilterCount(dfilter, 0)
141 def test_contains_6(self):
142 dfilter = 'http.request.method contains 48:45:41:44' # "HEAD"
143 self.assertDFilterCount(dfilter, 1)
145 def test_contains_fail_0(self):
146 dfilter = 'http.user_agent contains "update"'
147 self.assertDFilterCount(dfilter, 0)
149 def test_contains_fail_1(self):
150 dfilter = 'http.user_agent contains "UPDATE"'
151 self.assertDFilterCount(dfilter, 0)
153 def test_contains_upper_0(self):
154 dfilter = 'upper(http.user_agent) contains "UPDATE"'
155 self.assertDFilterCount(dfilter, 1)
157 def test_contains_upper_1(self):
158 dfilter = 'upper(http.user_agent) contains "update"'
159 self.assertDFilterCount(dfilter, 0)
161 def test_contains_upper_2(self):
162 dfilter = 'upper(tcp.seq) == 4'
163 self.assertDFilterFail(dfilter)
165 def test_contains_lower_0(self):
166 dfilter = 'lower(http.user_agent) contains "UPDATE"'
167 self.assertDFilterCount(dfilter, 0)
169 def test_contains_lower_1(self):
170 dfilter = 'lower(http.user_agent) contains "update"'
171 self.assertDFilterCount(dfilter, 1)
173 def test_contains_lower_2(self):
174 dfilter = 'lower(tcp.seq) == 4'
175 self.assertDFilterFail(dfilter)