77 lines
1.5 KiB
Ruby
77 lines
1.5 KiB
Ruby
|
|
#!/usr/local/bin/ruby
|
||
|
|
|
||
|
|
# $Dwarf: uu_test.rb,v 1.1 2003/04/20 16:33:02 ward Exp $
|
||
|
|
# $Source$
|
||
|
|
|
||
|
|
require '../yenc.rb'
|
||
|
|
require 'ftools'
|
||
|
|
|
||
|
|
def test1
|
||
|
|
print "Test 1: decoding a file\n"
|
||
|
|
file = File.open("testdata.ync", "r")
|
||
|
|
tmpfile = Tempfile.new("ynctmp")
|
||
|
|
tmpfile.sync=true
|
||
|
|
mode, filename, body = YEnc.ydecode(file, tmpfile)
|
||
|
|
if 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.ync", "r")
|
||
|
|
lines = file.readlines
|
||
|
|
file.close
|
||
|
|
file = File.open("testdata", mode = "r")
|
||
|
|
reference = file.readlines
|
||
|
|
file.close
|
||
|
|
|
||
|
|
mode, filename, body = YEnc.ydecode(lines)
|
||
|
|
|
||
|
|
if 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
|
||
|
|
end
|
||
|
|
|
||
|
|
def test3
|
||
|
|
print "Test 3: is_yencoded\n"
|
||
|
|
file = File.open("testdata.ync", "r")
|
||
|
|
lines = file.readlines
|
||
|
|
file.close
|
||
|
|
if YEnc.is_yencoded(lines)
|
||
|
|
print "Succesful\n"
|
||
|
|
else
|
||
|
|
print "Failed\n"
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def test4
|
||
|
|
print "Test 4: get_filename\n"
|
||
|
|
file = File.open("testdata.ync", "r")
|
||
|
|
lines = file.readlines
|
||
|
|
file.close
|
||
|
|
|
||
|
|
filename = YEnc.get_filename(lines)
|
||
|
|
if filename == "testdata"
|
||
|
|
print "Succesful\n"
|
||
|
|
else
|
||
|
|
print "Failed\n"
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
test1
|
||
|
|
test2
|
||
|
|
test3
|
||
|
|
test4
|
||
|
|
|