forked from CAIDA/mper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-base64-tests
executable file
·79 lines (70 loc) · 2.04 KB
/
gen-base64-tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/ruby
#############################################################################
## Generates test cases for mper_base64.c.
##
## --------------------------------------------------------------------------
## Copyright (C) 2009 The Regents of the University of California.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
#############################################################################
def print_tests(t)
puts "\n /* === encode === */"
t.each do |d, e|
printf " test_encode((unsigned char *)%p, %d, base64_buf, %p);\n",
d, d.length, e
end
puts "\n /* === decode === */"
t.each do |d, e|
printf " test_decode(%p, data_buf, (unsigned char *)%p, %d);\n",
e, d, d.length
end
end
t = [["Hello, World!\n","SGVsbG8sIFdvcmxkIQo="],
["\t","CQ=="],
["\n","Cg=="],
["\f","DA=="],
["\r","DQ=="],
["a","YQ=="],
["aa","YWE="],
["aaa","YWFh"]]
print_tests t
t2 = []
100.times do
x = []
len = rand(22) + 1
len.times do
x << rand(256)
end
s = x.pack("C*")
d = [ s ].pack("m").gsub!(/\s/, "")
t2 << [s, d]
end
# Test high incidence of NULs in data to encode.
50.times do
x = []
len = rand(22) + 1
len.times do
if rand(3) < 2 # 2/3 probability of NUL
x << 0
else
x << rand(256)
end
end
s = x.pack("C*")
d = [ s ].pack("m").gsub!(/\s/, "")
t2 << [s, d]
end
print_tests t2