#!/bin/sh
# A text collection is one ed2k link per line: comments, invalid links and
# CRLF line endings must not show up in the output. Sizes stay below 4 GiB:
# AddFile() drops larger files.
set -eu

cd "${AUTOPKGTEST_TMP:-$(mktemp -d)}"
printf '%s\n' \
	'# a comment' \
	'ed2k://|file|debian.iso|1234567|00112233445566778899aabbccddeeff|/' \
	'not a link' \
	> test.emulecollection
printf '%s\r\n' 'ed2k://|file|a.txt|4000000000|ffeeddccbbaa99887766554433221100|/' \
	>> test.emulecollection

expected='ed2k://|file|debian.iso|1234567|00112233445566778899aabbccddeeff|/
ed2k://|file|a.txt|4000000000|ffeeddccbbaa99887766554433221100|/'
out=$(amule-emc test.emulecollection 2>&1)
echo "$out"
if [ "$out" != "$expected" ]; then
	echo "FAIL: expected"
	echo "$expected"
	exit 1
fi
