2014-10-31 19:33:29 +00:00
|
|
|
#!/usr/bin/env ruby
|
2003-04-20 16:33:02 +00:00
|
|
|
|
2003-04-20 18:32:16 +00:00
|
|
|
# $Dwarf: uu_test.rb,v 1.1 2003/04/20 16:33:02 ward Exp $
|
2003-04-20 16:33:02 +00:00
|
|
|
# $Source$
|
|
|
|
|
|
|
|
|
|
require '../uuencode.rb'
|
2014-10-31 19:33:29 +00:00
|
|
|
require 'fileutils'
|
2003-04-20 16:33:02 +00:00
|
|
|
|
|
|
|
|
def test1
|
|
|
|
|
print "Test 1: decoding a file\n"
|
2003-04-20 18:32:16 +00:00
|
|
|
file = File.open("testdata.uu", "r")
|
2003-04-20 16:33:02 +00:00
|
|
|
tmpfile = Tempfile.new("uutmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = UUEncode.uudecode(file, tmpfile)
|
|
|
|
|
if mode != "644"
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, mode should be 644, but is #{mode}\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
elsif filename != "testdata"
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, filename should be \"testdata\", but is \"#{filename}\"\n"
|
2014-10-31 19:33:29 +00:00
|
|
|
elsif ! FileUtils.compare_file("testdata", tmpfile.path)
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, result doesn't match reference data\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
else
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Succesful\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test2
|
|
|
|
|
print "Test 2: decoding an array\n"
|
2003-04-20 18:32:16 +00:00
|
|
|
file = File.open("testdata.uu", "r")
|
2003-04-20 16:33:02 +00:00
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
2003-04-20 18:32:16 +00:00
|
|
|
file = File.open("testdata", "r")
|
2003-04-20 16:33:02 +00:00
|
|
|
reference = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
|
|
|
|
|
mode, filename, body = UUEncode.uudecode(lines)
|
|
|
|
|
|
|
|
|
|
if mode != "644"
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, mode should be 644, but is #{mode}\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
elsif filename != "testdata"
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, filename should be \"testdata\", but is \"#{filename}\"\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
elsif reference != body
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed, result doesn't match reference data\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
else
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Succesful\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test3
|
|
|
|
|
print "Test 3: is_uuencoded\n"
|
2003-04-20 18:32:16 +00:00
|
|
|
file = File.open("testdata.uu", "r")
|
2003-04-20 16:33:02 +00:00
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
if UUEncode.is_uuencoded(lines)
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Succesful\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
else
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test4
|
|
|
|
|
print "Test 4: get_filename\n"
|
2003-04-20 18:32:16 +00:00
|
|
|
file = File.open("testdata.uu", "r")
|
2003-04-20 16:33:02 +00:00
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
|
|
|
|
|
filename = UUEncode.get_filename(lines)
|
|
|
|
|
if filename == "testdata"
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Succesful\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
else
|
2003-04-20 18:32:16 +00:00
|
|
|
print " Failed\n"
|
2003-04-20 16:33:02 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-01-21 21:12:10 +00:00
|
|
|
def test5
|
|
|
|
|
print "Test 5: decoding a downloaded file\n"
|
|
|
|
|
file = File.open("testdata-download.uu", "r")
|
|
|
|
|
tmpfile = Tempfile.new("uutmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = UUEncode.uudecode(file, tmpfile)
|
|
|
|
|
if mode != "600"
|
|
|
|
|
print " Failed, mode should be 600, but is #{mode}\n"
|
|
|
|
|
elsif filename != "testdata-dowload.uu"
|
|
|
|
|
print " Failed, filename should be \"testdata\", but is \"#{filename}\"\n"
|
|
|
|
|
elsif ! FileUtils.compare_file("testdata-download-ydecoded.rar", tmpfile.path)
|
|
|
|
|
print " Failed, result doesn't match reference data\n"
|
|
|
|
|
else
|
|
|
|
|
print " Succesful\n"
|
|
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
2003-04-20 16:33:02 +00:00
|
|
|
test1
|
|
|
|
|
test2
|
|
|
|
|
test3
|
|
|
|
|
test4
|
2016-01-21 21:12:10 +00:00
|
|
|
test5
|
2003-04-20 16:33:02 +00:00
|
|
|
|