2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
7 require File.join(File.expand_path(File.dirname(__FILE__)),
8 'gem_package_tar_test_case')
9 require 'rubygems/package'
11 class TestGemPackageTarHeader < TarTestCase
32 @tar_header = Gem::Package::TarHeader.new header
36 io = TempIO.new @tar_header.to_s
38 new_header = Gem::Package::TarHeader.from io
40 assert_headers_equal @tar_header, new_header
44 assert_equal '', @tar_header.checksum, 'checksum'
45 assert_equal 1, @tar_header.devmajor, 'devmajor'
46 assert_equal 2, @tar_header.devminor, 'devminor'
47 assert_equal 10000, @tar_header.gid, 'gid'
48 assert_equal 'group', @tar_header.gname, 'gname'
49 assert_equal 'link', @tar_header.linkname, 'linkname'
50 assert_equal 'ustar', @tar_header.magic, 'magic'
51 assert_equal 0644, @tar_header.mode, 'mode'
52 assert_equal 12345, @tar_header.mtime, 'mtime'
53 assert_equal 'x', @tar_header.name, 'name'
54 assert_equal 'y', @tar_header.prefix, 'prefix'
55 assert_equal 100, @tar_header.size, 'size'
56 assert_equal '0', @tar_header.typeflag, 'typeflag'
57 assert_equal 1000, @tar_header.uid, 'uid'
58 assert_equal 'user', @tar_header.uname, 'uname'
59 assert_equal '00', @tar_header.version, 'version'
61 assert !@tar_header.empty?, 'empty'
64 def test_initialize_bad
65 assert_raises ArgumentError do
66 Gem::Package::TarHeader.new :name => '', :size => '', :mode => ''
69 assert_raises ArgumentError do
70 Gem::Package::TarHeader.new :name => '', :size => '', :prefix => ''
73 assert_raises ArgumentError do
74 Gem::Package::TarHeader.new :name => '', :prefix => '', :mode => ''
77 assert_raises ArgumentError do
78 Gem::Package::TarHeader.new :prefix => '', :size => '', :mode => ''
83 assert !@tar_header.empty?
85 @tar_header = Gem::Package::TarHeader.new :name => 'x', :prefix => '',
86 :mode => 0, :size => 0,
89 assert @tar_header.empty?
93 assert_equal @tar_header, @tar_header
94 assert_equal @tar_header, @tar_header.dup
98 expected = <<-EOF.split("\n").join
99 x\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
100 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
101 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
102 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
103 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
104 \000\000\000\0000000644\0000001750\0000023420\00000000000144\00000000030071
105 \000012467\000 0link\000\000\000\000\000\000\000\000\000\000\000\000\000\000
106 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
107 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
108 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
109 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
110 \000\000\000\000\000\000ustar\00000user\000\000\000\000\000\000\000\000\000
111 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
112 group\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
113 \000\000\000\000\000\000\000\000\0000000001\0000000002\000y\000\000\000\000
114 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
115 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
116 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
117 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
118 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
119 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
120 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
121 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
122 \000\000\000\000\000\000\000\000\000\000
125 assert_headers_equal expected, @tar_header
128 def test_update_checksum
129 assert_equal '', @tar_header.checksum
131 @tar_header.update_checksum
133 assert_equal '012467', @tar_header.checksum