#!/usr/local/bin/ruby

# $Dwarf: uu_test.rb,v 1.1 2003/04/20 16:33:02 ward Exp $
# $Source$

require '../uuencode.rb'
require 'ftools'

def test1
	print "Test 1: decoding a file\n"
	file = File.open("testdata.uu", "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", "r")
	lines = file.readlines
	file.close
	file = File.open("testdata", "r")
	reference = file.readlines
	file.close

	mode, filename, body = UUEncode.uudecode(lines)

	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
end

def test3
	print "Test 3: is_uuencoded\n"
	file = File.open("testdata.uu", "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", "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

