2014-10-31 19:33:29 +00:00
|
|
|
#!/usr/bin/env ruby
|
2003-04-20 18:32:39 +00:00
|
|
|
|
2003-04-22 19:25:31 +00:00
|
|
|
# $Dwarf: yenc_test.rb,v 1.1 2003/04/20 18:32:39 ward Exp $
|
2003-04-20 18:32:39 +00:00
|
|
|
# $Source$
|
|
|
|
|
|
|
|
|
|
require '../yenc.rb'
|
2014-10-31 19:33:29 +00:00
|
|
|
require 'fileutils'
|
2003-04-20 18:32:39 +00:00
|
|
|
|
|
|
|
|
def test1
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Test 1: decoding a file"
|
2003-04-20 18:32:39 +00:00
|
|
|
file = File.open("testdata.ync", "r")
|
|
|
|
|
tmpfile = Tempfile.new("ynctmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = YEnc.ydecode(file, tmpfile)
|
|
|
|
|
if filename != "testdata"
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
2014-10-31 19:33:29 +00:00
|
|
|
elsif ! FileUtils.compare_file("testdata", tmpfile.path)
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, result doesn't match reference data"
|
2003-04-20 18:32:39 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-20 18:32:39 +00:00
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test2
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Test 2: decoding an array"
|
2003-04-20 18:32:39 +00:00
|
|
|
file = File.open("testdata.ync", "r")
|
|
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
file = File.open("testdata", mode = "r")
|
|
|
|
|
reference = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
|
2014-11-10 09:45:03 +00:00
|
|
|
puts " with dos linebreaks"
|
2003-04-20 18:32:39 +00:00
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "testdata"
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
2003-04-20 18:32:39 +00:00
|
|
|
elsif reference != body
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, result doesn't match reference data"
|
2003-04-20 18:32:39 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-20 18:32:39 +00:00
|
|
|
end
|
2003-04-22 19:25:31 +00:00
|
|
|
|
|
|
|
|
lines.collect!{|x| x.chomp("\r\n")}
|
2014-11-10 09:45:03 +00:00
|
|
|
puts " without linebreaks\n"
|
2003-04-22 19:25:31 +00:00
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "testdata"
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
2003-04-22 19:25:31 +00:00
|
|
|
elsif reference != body
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, result doesn't match reference data"
|
2003-04-22 19:25:31 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-22 19:25:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
lines.collect!{|x| x.sub(/$/, "\n")}
|
2014-11-10 09:45:03 +00:00
|
|
|
puts " with unix linebreaks"
|
2003-04-22 19:25:31 +00:00
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "testdata"
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
2003-04-22 19:25:31 +00:00
|
|
|
elsif reference != body
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed, result doesn't match reference data"
|
2003-04-22 19:25:31 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-22 19:25:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2003-04-20 18:32:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test3
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Test 3: is_yencoded"
|
2003-04-20 18:32:39 +00:00
|
|
|
file = File.open("testdata.ync", "r")
|
|
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
if YEnc.is_yencoded(lines)
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-20 18:32:39 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed"
|
2003-04-20 18:32:39 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test4
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Test 4: get_filename"
|
2003-04-20 18:32:39 +00:00
|
|
|
file = File.open("testdata.ync", "r")
|
|
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
|
|
|
|
|
filename = YEnc.get_filename(lines)
|
|
|
|
|
if filename == "testdata"
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Succesful"
|
2003-04-20 18:32:39 +00:00
|
|
|
else
|
2014-11-10 09:45:03 +00:00
|
|
|
puts "Failed"
|
2003-04-20 18:32:39 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-10 09:45:03 +00:00
|
|
|
def test5
|
|
|
|
|
puts "Test 5: decoding a larger file"
|
|
|
|
|
file = File.open("lorem-gibson.txt.ync", "r")
|
|
|
|
|
tmpfile = Tempfile.new("ynctmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = YEnc.ydecode(file, tmpfile)
|
|
|
|
|
if filename != "lorem-gibson.txt"
|
|
|
|
|
puts "Failed, filename should be \"lorem-gibson.txt\", but is \"#{filename}\""
|
|
|
|
|
elsif ! FileUtils.compare_file("lorem-gibson.txt", tmpfile.path)
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test6
|
|
|
|
|
puts "Test 6: decoding a multipart file"
|
|
|
|
|
file = File.open("lorem-gibson2.txt-multi.ync", "r")
|
|
|
|
|
tmpfile = Tempfile.new("ynctmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = YEnc.ydecode(file, tmpfile)
|
|
|
|
|
if filename != "lorem-gibson2.txt"
|
|
|
|
|
puts "Failed, filename should be \"lorem-gibson2.txt\", but is \"#{filename}\""
|
|
|
|
|
elsif ! FileUtils.compare_file("lorem-gibson2.txt", tmpfile.path)
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test7
|
|
|
|
|
puts "Test 7: decoding a downloaded file as file"
|
|
|
|
|
file = File.open("testdata-download.ync", "r")
|
|
|
|
|
tmpfile = Tempfile.new("ynctmp")
|
|
|
|
|
tmpfile.sync=true
|
|
|
|
|
mode, filename, body = YEnc.ydecode(file, tmpfile)
|
|
|
|
|
if filename != "23597-7908-23799.rar"
|
|
|
|
|
puts "Failed, filename should be \"lorem-gibson2.txt\", but is \"#{filename}\""
|
|
|
|
|
elsif ! FileUtils.compare_file("testdata-download-ydecoded.rar", tmpfile.path)
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
file.close
|
|
|
|
|
tmpfile.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test8
|
|
|
|
|
puts "Test 8: decoding a downloaded file as array"
|
|
|
|
|
puts "array is not build for multipart, so this breaks (for now)"
|
|
|
|
|
file = File.open("testdata-download.ync", "r")
|
|
|
|
|
lines = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
file = File.open("testdata-download-ydecoded.rar", mode = "r")
|
|
|
|
|
reference = file.readlines
|
|
|
|
|
file.close
|
|
|
|
|
|
|
|
|
|
puts " with dos linebreaks"
|
|
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "23597-7908-23799.rar"
|
|
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
|
|
|
|
elsif reference != body
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
lines.collect!{|x| x.chomp("\r\n")}
|
|
|
|
|
puts " without linebreaks\n"
|
|
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "23597-7908-23799.rar"
|
|
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
|
|
|
|
elsif reference != body
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
lines.collect!{|x| x.sub(/$/, "\n")}
|
|
|
|
|
puts " with unix linebreaks\n"
|
|
|
|
|
mode, filename, body = YEnc.ydecode(lines)
|
|
|
|
|
|
|
|
|
|
if filename != "23597-7908-23799.rar"
|
|
|
|
|
puts "Failed, filename should be \"testdata\", but is \"#{filename}\""
|
|
|
|
|
elsif reference != body
|
|
|
|
|
puts "Failed, result doesn't match reference data"
|
|
|
|
|
else
|
|
|
|
|
puts "Succesful"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2003-04-20 18:32:39 +00:00
|
|
|
test1
|
|
|
|
|
test2
|
|
|
|
|
test3
|
|
|
|
|
test4
|
2014-11-10 09:45:03 +00:00
|
|
|
test5
|
|
|
|
|
test6
|
|
|
|
|
test7
|
|
|
|
|
test8
|