#!/bin/sh
# Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# 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
