1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/bin/sh
#
# Insert a test packet into a unit test.
# ./insert-packet.sh <plaintext packet file> <C++ source>
#
# searches for the initNetwork() line and inserts just below that
#
function die() {
echo "$1" >&2;
exit 1;
}
test ! -z "$1" -a ! -z "$2" || die "usage: $0 input output";
quoted=`sed -e 's/\"/\\\"/g' \
-e 's/^/ \"/' \
-e $'s/\r$//g' -e 's/$/\\\\r\\\\n\"/g' <$1`;
# Figure out where we want to insert this.
line=`egrep -n 'initNetwork\(\)\;$' <$2 | sed -e 's/:/ /' | awk '{print $1}'`;
total=`wc -l $2 | awk '{print $1}'`;
head -n ${line} $2 >.tmp;
cat >>.tmp <<EOF
{
Data txt(
${quoted}
);
std::auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
try
{
(void)message->header(h_From);
}
catch (ParseException&)
{
std::cerr << "uh, failed to parse message: "
<< __FILE__ << ':' << __LINE__
<< std::endl;
assert(false);
}
}
EOF
tail -n `expr ${total} - ${line}` $2 >>.tmp;
mv .tmp $2;
echo "inserted at line `expr ${line} + 1`";
|