X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8699f1cc0c8db8d3b0d6e7d607f3e92b214ec80f..f905c173820a7dae055b083481ab4cd6e6c451a2:/test/inc/test-eom-align diff --git a/test/inc/test-eom-align b/test/inc/test-eom-align index 7bba2747..cea2f377 100755 --- a/test/inc/test-eom-align +++ b/test/inc/test-eom-align @@ -34,9 +34,22 @@ fi done) check "$THISDIR/md5sums" "$MH_TEST_DIR/inctest.md5sums" 'keep first' +f="$MH_TEST_DIR/mmdf-magic" +printf '\1\1\1\1\n' >$f +got="`output_md5 $f`" +want=2636d725e650779eca70d6564c4f5982 +if test "$got" != "$want"; then + printf '%s: MMDF magic: %s: got %s, want %s\n' \ + "$0" "$f" "$got" "$want" >&2 + exit 1 +fi +mmdf_magic="$f" + +empty_line="$MH_TEST_DIR/empty-line" +printf '\n' >"$empty_line" + FILLER="$THISDIR/filler.txt" FROMLINE="$THISDIR/fromline.txt" -MMDF_DELIM='printf "\x01\x01\x01\x01\x0a"' HDR="$THISDIR/msgheader.txt" if grep From "$FILLER" >/dev/null; then @@ -53,7 +66,7 @@ fi STDIO_BUFSZ=16384 FROMLINESZ=`wc -c < "$FROMLINE"` -MMDFDELIMLINESZ=1 +MMDFDELIMLINESZ=`wc -c <"$mmdf_magic"` HDRSZ=`wc -c < "$HDR"` # makembox_A mboxname sz @@ -70,24 +83,22 @@ makembox_A () { arith_eval $SZ - $HDRSZ - $FROMLINESZ - 1; WANTSZ=$arith_val dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null echo >> "$MBOX.body" - cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX" - echo >> "$MBOX" - cat "$FROMLINE" "$HDR" "$FILLER" >> "$MBOX" - echo >> "$MBOX" + cat "$FROMLINE" "$HDR" "$MBOX.body" "$empty_line" \ + "$FROMLINE" "$HDR" "$FILLER" "$empty_line" >"$MBOX" } # makemmdf_A mmdfboxname sz +# The first email in $MBOX will be sz bytes long, including its MMDF +# magic strings that top and tail it. makemmdf_A () { MBOX="$1" SZ=$2 - arith_eval $SZ - $HDRSZ - $MMDFDELIMLINESZ - 1; WANTSZ=$arith_val + arith_eval $SZ - $MMDFDELIMLINESZ - $HDRSZ - 1 - $MMDFDELIMLINESZ; WANTSZ=$arith_val dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null echo >> "$MBOX.body" - #### The trailing $MMDF_DELIM's allows $MBOX to exactly match a file - #### created by packf. - (eval "$MMDF_DELIM"; cat "$HDR" "$MBOX.body"; eval "$MMDF_DELIM"; \ - eval "$MMDF_DELIM"; cat "$HDR" "$FILLER"; eval "$MMDF_DELIM") > "$MBOX" + cat "$mmdf_magic" "$HDR" "$MBOX.body" "$mmdf_magic" \ + "$mmdf_magic" "$HDR" "$FILLER" "$mmdf_magic" >"$MBOX" } # make_mbox_B mboxname sz @@ -103,21 +114,21 @@ makembox_B () { arith_eval $SZ - $HDRSZ - $FROMLINESZ - 1; WANTSZ=$arith_val dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null echo >> "$MBOX.body" - cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX" - echo >> "$MBOX" + cat "$FROMLINE" "$HDR" "$MBOX.body" "$empty_line" >"$MBOX" } # makemmdf_B mmdfboxname sz +# The mbox file will be sz bytes and contain a single email, topped and +# tailed with MMDF's magic strings. The end of the email's body looks +# the same as the magic string for three bytes. makemmdf_B () { MBOX="$1" SZ=$2 - arith_eval $SZ - $HDRSZ - $MMDFDELIMLINESZ - 1; WANTSZ=$arith_val + arith_eval $SZ - $MMDFDELIMLINESZ - $HDRSZ - 1 - 4 - $MMDFDELIMLINESZ; WANTSZ=$arith_val dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null - echo >> "$MBOX.body" - #### The final $MMDF_DELIM allows $MBOX to exactly match a file - #### created by packf. - (eval "$MMDF_DELIM"; cat "$HDR" "$MBOX.body"; eval "$MMDF_DELIM") > "$MBOX" + printf '\n\1\1\1\n' >>"$MBOX.body" + cat "$mmdf_magic" "$HDR" "$MBOX.body" "$mmdf_magic" >"$MBOX" } # do_one_test_A sz mbox_type @@ -126,10 +137,7 @@ do_one_test_A () { SZ=$1 MBOX_TYPE=$2 printf '%5s %s A\r' $SZ $MBOX_TYPE - case $MBOX_TYPE in - mbox) makembox_A "$MH_TEST_DIR/eom-align.mbox" $SZ ;; - mmdf) makemmdf_A "$MH_TEST_DIR/eom-align.mbox" $SZ ;; - esac + make${MBOX_TYPE}_A "$MH_TEST_DIR/eom-align.mbox" $SZ $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox" # We know the messages should be 11 and 12 in inbox # Now get the bodies back out. @@ -139,7 +147,7 @@ do_one_test_A () { sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/12" > "$body2" check "$MH_TEST_DIR/eom-align.mbox.body" "$body1" 'keep first' check "$FILLER" "$body2" 'keep first' - rmm 11 12 + rm "$MH_TEST_DIR/Mail/inbox/11" "$MH_TEST_DIR/Mail/inbox/12" } # do_one_test_B sz mbox_type @@ -148,16 +156,13 @@ do_one_test_B () { SZ=$1 MBOX_TYPE=$2 printf '%5s %s B\r' $SZ $MBOX_TYPE - case $MBOX_TYPE in - mbox) makembox_B "$MH_TEST_DIR/eom-align.mbox" $SZ ;; - mmdf) makemmdf_B "$MH_TEST_DIR/eom-align.mbox" $SZ ;; - esac + make${MBOX_TYPE}_B "$MH_TEST_DIR/eom-align.mbox" $SZ $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox" # We know the message should be 11 in the inbox body1="$MH_TEST_DIR/eom-align.inbox.body1" sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/11" > "$body1" check "$MH_TEST_DIR/eom-align.mbox.body" "$body1" 'keep first' - rmm 11 + rm "$MH_TEST_DIR/Mail/inbox/11" } # Cover a decent range around the stdio buffer size to make sure we catch @@ -184,14 +189,15 @@ done i="$START" while test $i -le $FINISH; do do_one_test_A $i mbox - do_one_test_A $i mmdf do_one_test_B $i mbox + do_one_test_A $i mmdf do_one_test_B $i mmdf i=`expr $i + 1` done printf '\n' test ${failed:-0} -eq 0 && \ -rm "$MH_TEST_DIR/eom-align.mbox" "$MH_TEST_DIR/eom-align.mbox.body" +rm "$MH_TEST_DIR/eom-align.mbox" "$MH_TEST_DIR/eom-align.mbox.body" \ + "$mmdf_magic" "$empty_line" exit $failed