Class: Gem::Package::TarTestCase
- Inherits:
-
TestCase
- Object
- MiniTest::Unit::TestCase
- TestCase
- Gem::Package::TarTestCase
show all
- Defined in:
- lib/rubygems/package/tar_test_case.rb
Overview
A test case for Gem::Package::Tar* classes
Instance Method Summary
collapse
-
#ASCIIZ(str, length) ⇒ Object
-
#assert_headers_equal(expected, actual) ⇒ Object
-
#calc_checksum(header) ⇒ Object
-
#header(type, fname, dname, length, mode, checksum = nil) ⇒ Object
-
#SP(s) ⇒ Object
-
#SP_Z(s) ⇒ Object
-
#tar_dir_header(name, prefix, mode) ⇒ Object
-
#tar_file_header(fname, dname, mode, length) ⇒ Object
-
#to_oct(n, pad_size) ⇒ Object
-
#util_dir_entry ⇒ Object
-
#util_entry(tar) ⇒ Object
-
#Z(s) ⇒ Object
Methods inherited from TestCase
#add_to_fetcher, #all_spec_names, #assert_contains_make_command, #assert_path_exists, #build_rake_in, cert_path, #create_tmpdir, #dep, #install_default_gems, #install_default_specs, #install_gem, #install_gem_user, #install_specs, key_path, load_cert, load_key, #make_command, make_command, #mu_pp, #new_default_spec, #new_spec, #nmake_found?, #parse_make_command_line, #process_based_port, process_based_port, #quick_gem, #quick_spec, #read_binary, #read_cache, #refute_path_exists, #req, rubybin, #scan_make_command_lines, #setup, #spec, #teardown, #uninstall_gem, #util_build_gem, #util_clear_gems, #util_gem, #util_gzip, #util_make_gems, #util_remove_gem, #util_set_arch, #util_setup_fake_fetcher, #util_setup_spec_fetcher, #util_spec, #util_zip, #v, vc_windows?, #vc_windows?, #wait_for_child_process_to_exit, win_platform?, #win_platform?, #write_file
ui, #ui, ui=, #ui=, use_ui, #use_ui
Instance Method Details
#ASCIIZ(str, length) ⇒ Object
9
10
11
|
# File 'lib/rubygems/package/tar_test_case.rb', line 9
def ASCIIZ(str, length)
str + "\0" * (length - str.length)
end
|
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
|
# File 'lib/rubygems/package/tar_test_case.rb', line 25
def (expected, actual)
expected = expected.to_s unless String === expected
actual = actual.to_s unless String === actual
fields = %w[
name 100
mode 8
uid 8
gid 8
size 12
mtime 12
checksum 8
typeflag 1
linkname 100
magic 6
version 2
uname 32
gname 32
devmajor 8
devminor 8
prefix 155
]
offset = 0
until fields.empty? do
name = fields.shift
length = fields.shift.to_i
if name == "checksum" then
chksum_off = offset
offset += length
next
end
assert_equal expected[offset, length], actual[offset, length],
"Field #{name} of the tar header differs."
offset += length
end
assert_equal expected[chksum_off, 8], actual[chksum_off, 8]
end
|
#calc_checksum(header) ⇒ Object
69
70
71
72
|
# File 'lib/rubygems/package/tar_test_case.rb', line 69
def calc_checksum()
sum = .unpack("C*").inject{|s,a| s + a}
SP(Z(to_oct(sum, 6)))
end
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rubygems/package/tar_test_case.rb', line 74
def (type, fname, dname, length, mode, checksum = nil)
checksum ||= " " * 8
arr = [ ASCIIZ(fname, 100), Z(to_oct(mode, 7)), Z(to_oct(0, 7)), Z(to_oct(0, 7)), Z(to_oct(length, 11)), Z(to_oct(0, 11)), checksum, type, "\0" * 100, "ustar\0", "00", ASCIIZ("wheel", 32), ASCIIZ("wheel", 32), Z(to_oct(0, 7)), Z(to_oct(0, 7)), ASCIIZ(dname, 155) ]
format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
h = if RUBY_VERSION >= "1.9" then
arr.join
else
arr = arr.join("").split(//).map{|x| x[0]}
arr.pack format
end
ret = h + "\0" * (512 - h.size)
assert_equal(512, ret.size)
ret
end
|
#SP(s) ⇒ Object
13
14
15
|
# File 'lib/rubygems/package/tar_test_case.rb', line 13
def SP(s)
s + " "
end
|
#SP_Z(s) ⇒ Object
17
18
19
|
# File 'lib/rubygems/package/tar_test_case.rb', line 17
def SP_Z(s)
s + " \0"
end
|
108
109
110
111
112
|
# File 'lib/rubygems/package/tar_test_case.rb', line 108
def (name, prefix, mode)
h = ("5", name, prefix, 0, mode)
checksum = calc_checksum(h)
("5", name, prefix, 0, mode, checksum)
end
|
114
115
116
117
118
|
# File 'lib/rubygems/package/tar_test_case.rb', line 114
def (fname, dname, mode, length)
h = ("0", fname, dname, length, mode)
checksum = calc_checksum(h)
("0", fname, dname, length, mode, checksum)
end
|
#to_oct(n, pad_size) ⇒ Object
120
121
122
|
# File 'lib/rubygems/package/tar_test_case.rb', line 120
def to_oct(n, pad_size)
"%0#{pad_size}o" % n
end
|
#util_dir_entry ⇒ Object
132
133
134
|
# File 'lib/rubygems/package/tar_test_case.rb', line 132
def util_dir_entry
util_entry ("foo", "bar", 0)
end
|
#util_entry(tar) ⇒ Object
#Z(s) ⇒ Object
21
22
23
|
# File 'lib/rubygems/package/tar_test_case.rb', line 21
def Z(s)
s + "\0"
end
|