#!/bin/sh
# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# Checks that the initLogger() call uses for unit tests respects the setting of
# the buffer value
#

testname="bufferLogger test"
echo $testname

failcount=0
tempfile=@abs_builddir@/buffer_logger_test_tempfile_$$

passfail() {
    if [ $1 -eq 0 ]; then
        echo " pass"
    else
        echo " FAIL"
        failcount=`expr $failcount + $1`
    fi
}

echo "1. Checking that buffer initialization works"

echo -n  "   - Buffer including process() call: "
cat > $tempfile << .
INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test 2>&1 | \
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
    cut -d' ' -f3- | diff $tempfile -
passfail $?

echo -n  "   - Buffer excluding process() call: "
cat > $tempfile << .
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
DEBUG [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test -n 2>&1 | diff $tempfile -
passfail $?



# Tidy up.
rm -f $tempfile

exit $failcount
