]> diplodocus.org Git - nmh/blob - test/inc/test-eom-align
Added m_getfld_track_filepos() for callers to indicate that they
[nmh] / test / inc / test-eom-align
1 #!/bin/sh
2 # Test all combinations of alignment of the end-of-message delimiter
3 # with the end of a stdio buffer
4
5 set -e
6
7 if test -z "${MH_OBJ_DIR}"; then
8 srcdir=`dirname "$0"`/../..
9 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
10 fi
11
12 . "$MH_OBJ_DIR/test/common.sh"
13
14 setup_test
15
16 THISDIR="$srcdir/test/inc"
17
18 if [ -z "$VALGRIND_ME" ]; then
19 VALGRIND=
20 else
21 require_prog valgrind
22 # Lack of quotes here is important
23 VALGRIND="valgrind --quiet --error-exitcode=1"
24 echo "Running tests under valgrind: takes ages!"
25 fi
26
27 # First check that all our various pieces of text are
28 # intact. (Since we're dealing in exact byte alignment
29 # minor corruptions such as line ending changes could
30 # render the tests useless.)
31 (cd "$THISDIR" && \
32 for i in *.txt; do
33 echo `output_md5 $i`' '"$i" >> "$MH_TEST_DIR/inctest.md5sums"
34 done)
35 check "$THISDIR/md5sums" "$MH_TEST_DIR/inctest.md5sums" 'keep first'
36
37 FILLER="$THISDIR/filler.txt"
38 FROMLINE="$THISDIR/fromline.txt"
39 HDR="$THISDIR/msgheader.txt"
40
41 if grep From "$FILLER" >/dev/null; then
42 echo "Somebody's messed with $FILLER -- it must not contain"
43 echo "anything that might look like a message delimiter!"
44 exit 1
45 fi
46
47 # a sort of worst-case guess for the buffer size;
48 # obviously a buffer boundary for this will be a boundary
49 # for any smaller power of two size.
50 # If you need to increase this you'll need to make filler.txt
51 # bigger as well.
52 STDIO_BUFSZ=16384
53
54 FROMLINESZ=`wc -c < "$FROMLINE"`
55 HDRSZ=`wc -c < "$HDR"`
56
57 # makembox_A mboxname sz
58 # Assemble a mailbox into file mboxname, with two messages, such
59 # that the first is exactly sz bytes long (including its header
60 # and its initial 'From' line and the newline which terminates it
61 # but not the newline which mbox format demands after each message)
62 # We also leave the body of message one in mboxname.body
63 # (the body of message two is always $FILLER in its entirety)
64 makembox_A () {
65 MBOX="$1"
66 SZ=$2
67
68 arith_eval $SZ - $HDRSZ - $FROMLINESZ - 1; WANTSZ=$arith_val
69 dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null
70 echo >> "$MBOX.body"
71 cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX"
72 echo >> "$MBOX"
73 cat "$FROMLINE" "$HDR" "$FILLER" >> "$MBOX"
74 echo >> "$MBOX"
75 }
76
77 # make_mbox_B mboxname sz
78 # Test B makes a mailbox with one message of sz bytes long,
79 # which ends in a partial mbox delimiter (ie part of the string
80 # \n\nFrom '). To both do this and be a valid mbox this means
81 # it has to end with two newlines (one of which is in the message
82 # body and one of which is the mbox format mandated one)
83 makembox_B () {
84 MBOX="$1"
85 SZ=$2
86
87 arith_eval $SZ - $HDRSZ - $FROMLINESZ - 1; WANTSZ=$arith_val
88 dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null
89 echo >> "$MBOX.body"
90 cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX"
91 echo >> "$MBOX"
92 }
93
94 # do_one_test_A sz
95 # Do a single test with message one's body of size sz.
96 do_one_test_A () {
97 SZ=$1
98 makembox_A "$MH_TEST_DIR/eom-align.mbox" $STDIO_BUFSZ
99 $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox"
100 # We know the messages should be 11 and 12 in inbox
101 # Now get the bodies back out.
102 body1="$MH_TEST_DIR/eom-align.inbox.body1"
103 body2="$MH_TEST_DIR/eom-align.inbox.body2"
104 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/11" > "$body1"
105 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/12" > "$body2"
106 check "$MH_TEST_DIR/eom-align.mbox.body" "$body1" 'keep first'
107 check "$FILLER" "$body2" 'keep first'
108 rmm 11 12
109 }
110
111 # do_one_test_B sz
112 # Do a test type B
113 do_one_test_B () {
114 SZ=$1
115 makembox_B "$MH_TEST_DIR/eom-align.mbox" $STDIO_BUFSZ
116 $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox"
117 # We know the message should be 11 in the inbox
118 body1="$MH_TEST_DIR/eom-align.inbox.body1"
119 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/11" > "$body1"
120 check "$MH_TEST_DIR/eom-align.mbox.body" "$body1" 'keep first'
121 rmm 11
122 }
123
124 # Cover a decent range around the stdio buffer size to make sure we catch
125 # any corner cases whether they relate to total message size equal to
126 # buffer size or to body size equal to buffer size.
127 arith_eval $STDIO_BUFSZ - 16; START=$arith_val
128 arith_eval $STDIO_BUFSZ + $HDRSZ + $FROMLINESZ + 32; FINISH=$arith_val
129 echo \
130 "Testing inc of files with various alignments of eom marker with buffer size..."
131 i="$START"
132 while test $i -le $FINISH; do
133 progress_update $i $START $FINISH
134 do_one_test_A $i
135 do_one_test_B $i
136 i=`expr $i + 1`
137 done
138 progress_done
139
140 test ${failed:-0} -eq 0 && \
141 rm "$MH_TEST_DIR/eom-align.mbox" "$MH_TEST_DIR/eom-align.mbox.body"
142
143 exit $failed