#!/bin/sh
# $Id: t-mapdom-0.sh,v 1.9 2006/05/25 04:55:56 ca Exp $
# Copyright (c) 2003, 2004, 2006 Sendmail, Inc. and its suppliers.
#	All rights reserved.
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the sendmail distribution.
#
# ------------------------------------------------------------
# Description:
# Script to test lookup of domains.
# Uses t-mapdomr-0, t-mm
# ------------------------------------------------------------

test -s stop && exit 1
#

BDBIN="bdb2"
BDB="bdb2.db"
ERRS=0
PRG=./t-mapdomr-0

cat > ${BDBIN} <<EOF
a.b.c		rhsabc
.b.c		rhsbc
.c		rhsc
.		dot
d.e		rhsde
e		rhse
Tag:.b.c		rhstagbc
.some.nice.domain	rhs-some.nice.domain
.nice.domain	rhs-nice.domain
.domain		rhs-domain
DomainTag:some.nice.domain	rhs-DomainTag:some.nice.domain
DomainTag:nice.domain		rhs-DomainTag:nice.domain
DomainTag:domain		rhs-DomainTag:domain
DomainTag:.nice.domain		rhs-DomainTag:.nice.domain
DomainTag:.domain		rhs-DomainTag:.domain
Default:.match		rhs-default:.match
Default:		rhs-default
EOF

MAPTYPES="`${PRG} -l 0 2>/dev/null`"
for maptype in ${MAPTYPES}
do

# create map
rm -f ${BDB}
./t-mm -t'	' -T ${maptype} -F ${BDB} < ${BDBIN}
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test full lookup
${PRG} -T ${maptype} "a.b.c" "rhsabc"
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test subnet
${PRG} -T ${maptype} "x.b.c" "rhsbc"
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test full lookup
${PRG} -T ${maptype} "c.d.e" ""
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test subnet and no match
${PRG} -T ${maptype} "x.y.c" "rhsc" "x.y.z" ""
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test tag (full, subnet, no match)
${PRG} -T ${maptype} "tag:a.b.c" "rhstagbc"
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

${PRG} -T ${maptype} "domaintag:some.nice.domain" "rhs-DomainTag:some.nice.domain" \
	"domaintag:nice.domain" "rhs-DomainTag:nice.domain" \
	"domaintag:domain" "rhs-DomainTag:domain"
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

${PRG} -T ${maptype} "domaintag:other.nice.domain" "rhs-DomainTag:.nice.domain" \
	"domaintag:other.not.domain" "rhs-DomainTag:.domain" \
	"domaintag:dom" ""
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

# test default
${PRG} -T ${maptype} "default:nomatch" "rhs-default" "default:a.match" "rhs-default:.match"
if test $? != 0
then
  ERRS=`expr ${ERRS} + 1 `
fi

done

exit ${ERRS}


syntax highlighted by Code2HTML, v. 0.9.1