#!/bin/sh
#
# Copyright (c) 2005 Jonas Fonseca
#

test_description='Test parsing of FTP responses.

It tests responses from several different FTP servers.
'

. "$TEST_LIB"

CRNL="\r\n"

test_ftp_response_expect_success () {
	desc="$1"; shift
	response="$1"; shift

	response="$(echo "$response" | sed -n '2,$p')"

	test_expect_success "$desc" \
		"ftp-parser --response \"$response\""
}

test_ftp_response_expect_failure () {
	desc="$1"; shift
	response="$1"; shift

	response="$(echo "$response" | sed -n '2,$p')"

	test_expect_failure "$desc" \
		"ftp-parser --response \"$response\""
}

#############################################################################
#
# Parser for UNIX-style listing:
#

test_ftp_response_expect_success \
'ftp.freebsd.org response' \
"
drwxrwxr-x    3 0        0             512 Apr 17  2003 pub\r\n"

test_ftp_response_expect_success \
'UNIX-style listing, without inum and without blocks' \
"
-rw-r--r--   1 root     other        531 Jan 29 03:26 README\r\n
dr-xr-xr-x   2 root     other        512 Apr  8  1994 etc\r\n
dr-xr-xr-x   2 root     512 Apr  8  1994 etc\r\n
lrwxrwxrwx   1 root     other          7 Jan 25 00:17 bin -> usr/bin\r\n"

test_ftp_response_expect_success \
"Response produced by Microsoft's FTP servers for Windows" \
"
----------   1 owner    group         1803128 Jul 10 10:18 ls-lR.Z\r\n
d---------   1 owner    group               0 May  9 19:45 Softlib\r\n"

test_ftp_response_expect_success \
'Response from WFTPD for MSDOS' \
"
-rwxrwxrwx   1 noone    nogroup      322 Aug 19  1996 message.ftp\r\n"

test_ftp_response_expect_success \
'Response from FreeBSD with symbolic link' \
"
lrwxrwx--x    1 110      1002           13 Oct 24  2006 5.3 has moved to ftp-archive -> ../README.TXT\r\n"

test_ftp_response_expect_success \
'Response from NetWare' \
"
d[R----F--] supervisor            512       Jan 16 18:53    login\r\n
- [R----F--] rhesus             214059       Oct 20 15:27    cx.exe\r\n"

test_ftp_response_expect_success \
'Response from NetPresenz for the Mac' \
"
-------r--         326  1391972  1392298 Nov 22  1995 MegaPhone.sit\r\n
drwxrwxr-x               folder        2 May 10  1996 network\r\n"


#############################################################################
#
# EPLF response
#

test_ftp_response_expect_success \
'EPLF responses' \
"
+i8388621.48594,m825718503,r,s280,	djb.html\r\n
+i8388621.50690,m824255907,/,	514\r\n
+i8388621.48598,m824253270,r,s612,	514.html\r\n"

#############################################################################
#
# Parser for VMS-style MultiNet (some spaces removed from examples)
#

test_ftp_response_expect_success \
'Basic VMS responses' \
"
00README.TXT;1      2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)\r\n
CORE.DIR;1          1  8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)\r\n"

test_ftp_response_expect_success \
'Response from non-MutliNet VMS' \
"
CII-MANUAL.TEX;1  213/216  29-JAN-1996 03:33:12  [ANONYMOU,ANONYMOUS]   (RWED,RWED,,)\r\n"

test_ftp_response_expect_failure \
'A garbage line which should fail' \
"
EA95_0PS.GZ;1      No privilege for attempted operation\r\n"

#############################################################################
#
# Parser for the MSDOS-style format
#

test_ftp_response_expect_success \
'Basic MSDOS-style format' \
"
04-27-00  09:09PM       <DIR>          licensed\r\n
07-18-00  10:16AM       <DIR>          pub\r\n
04-14-00  03:47PM                  589 readme.htm\r\n"


test_done
