regression tests for uuencode lib
This commit is contained in:
parent
c318fb3022
commit
0b1efd5ab4
3 changed files with 98 additions and 0 deletions
1
trunk/ripnews/encode/tests/testdata
Normal file
1
trunk/ripnews/encode/tests/testdata
Normal file
|
|
@ -0,0 +1 @@
|
|||
1234567890
|
||||
4
trunk/ripnews/encode/tests/testdata.uu
Normal file
4
trunk/ripnews/encode/tests/testdata.uu
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
begin 644 testdata
|
||||
+,3(S-#4V-S@Y,`K/
|
||||
`
|
||||
end
|
||||
93
trunk/ripnews/encode/tests/uu_test.rb
Executable file
93
trunk/ripnews/encode/tests/uu_test.rb
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
#!/usr/local/bin/ruby
|
||||
|
||||
# $Dwarf$
|
||||
# $Source$
|
||||
|
||||
require '../uuencode.rb'
|
||||
require 'ftools'
|
||||
|
||||
def test1
|
||||
print "Test 1: decoding a file\n"
|
||||
file = File.open("testdata.uu", mode = "r")
|
||||
tmpfile = Tempfile.new("uutmp")
|
||||
tmpfile.sync=true
|
||||
mode, filename, body = UUEncode.uudecode(file, tmpfile)
|
||||
if mode != "644"
|
||||
print "Failed, mode should be 644, but is #{mode}\n"
|
||||
elsif filename != "testdata"
|
||||
print "Failed, filename should be \"testdata\", but is \"#{filename}\"\n"
|
||||
elsif ! File.compare("testdata", tmpfile.path)
|
||||
print "Failed, result doesn't match reference data\n"
|
||||
else
|
||||
print "Succesful\n"
|
||||
end
|
||||
file.close
|
||||
tmpfile.close
|
||||
end
|
||||
|
||||
def test2
|
||||
print "Test 2: decoding an array\n"
|
||||
file = File.open("testdata.uu", mode = "r")
|
||||
lines = file.readlines
|
||||
file.close
|
||||
file = File.open("testdata", mode = "r")
|
||||
reference = file.readlines
|
||||
file.close
|
||||
|
||||
mode, filename, body = UUEncode.uudecode(lines)
|
||||
|
||||
print "#{reference.length}\n"
|
||||
print "#{body.length}\n"
|
||||
if mode != "644"
|
||||
print "Failed, mode should be 644, but is #{mode}\n"
|
||||
elsif filename != "testdata"
|
||||
print "Failed, filename should be \"testdata\", but is \"#{filename}\"\n"
|
||||
elsif reference != body
|
||||
print "Failed, result doesn't match reference data\n"
|
||||
else
|
||||
print "Succesful\n"
|
||||
end
|
||||
print "#{reference}"
|
||||
print "#{body}"
|
||||
file = File.new("blup", "w")
|
||||
file.print body
|
||||
file.close
|
||||
|
||||
i = 0
|
||||
while i < body.length
|
||||
print "I: #{i} data: #{body[i]}"
|
||||
i+=1
|
||||
end
|
||||
end
|
||||
|
||||
def test3
|
||||
print "Test 3: is_uuencoded\n"
|
||||
file = File.open("testdata.uu", mode = "r")
|
||||
lines = file.readlines
|
||||
file.close
|
||||
if UUEncode.is_uuencoded(lines)
|
||||
print "Succesful\n"
|
||||
else
|
||||
print "Failed\n"
|
||||
end
|
||||
end
|
||||
|
||||
def test4
|
||||
print "Test 4: get_filename\n"
|
||||
file = File.open("testdata.uu", mode = "r")
|
||||
lines = file.readlines
|
||||
file.close
|
||||
|
||||
filename = UUEncode.get_filename(lines)
|
||||
if filename == "testdata"
|
||||
print "Succesful\n"
|
||||
else
|
||||
print "Failed\n"
|
||||
end
|
||||
end
|
||||
|
||||
test1
|
||||
test2
|
||||
test3
|
||||
test4
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue