t_protoent.sh revision 1.1
11.1Spgoyette# $NetBSD: t_protoent.sh,v 1.1 2011/01/12 17:32:27 pgoyette Exp $
21.1Spgoyette#
31.1Spgoyette# Copyright (c) 2008 The NetBSD Foundation, Inc.
41.1Spgoyette# All rights reserved.
51.1Spgoyette#
61.1Spgoyette# Redistribution and use in source and binary forms, with or without
71.1Spgoyette# modification, are permitted provided that the following conditions
81.1Spgoyette# are met:
91.1Spgoyette# 1. Redistributions of source code must retain the above copyright
101.1Spgoyette#    notice, this list of conditions and the following disclaimer.
111.1Spgoyette# 2. Redistributions in binary form must reproduce the above copyright
121.1Spgoyette#    notice, this list of conditions and the following disclaimer in the
131.1Spgoyette#    documentation and/or other materials provided with the distribution.
141.1Spgoyette#
151.1Spgoyette# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Spgoyette# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Spgoyette# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Spgoyette# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Spgoyette# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Spgoyette# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Spgoyette# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Spgoyette# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Spgoyette# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Spgoyette# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Spgoyette# POSSIBILITY OF SUCH DAMAGE.
261.1Spgoyette#
271.1Spgoyette
281.1Spgoyetteatf_test_case protoent
291.1Spgoyetteprotoent_head()
301.1Spgoyette{
311.1Spgoyette	atf_set "descr" "Checks {get,set,end}protoent(3)"
321.1Spgoyette}
331.1Spgoyetteprotoent_body()
341.1Spgoyette{
351.1Spgoyette	#
361.1Spgoyette	# Munge original to:
371.1Spgoyette	#  (1) match output format of the test program
381.1Spgoyette	#  (2) fold all names for the same port/proto together
391.1Spgoyette	#  (3) prune duplicates
401.1Spgoyette	#
411.1Spgoyette	tr '\t' ' ' </etc/protocols | awk '
421.1Spgoyette		function add(key, name,      i, n, ar) {
431.1Spgoyette		n = split(names[key], ar);
441.1Spgoyette		for (i=1; i<=n; i++) {
451.1Spgoyette			if (name == ar[i]) {
461.1Spgoyette			return;
471.1Spgoyette			}
481.1Spgoyette		}
491.1Spgoyette		delete ar;
501.1Spgoyette		names[key] = names[key] " " name;
511.1Spgoyette		}
521.1Spgoyette
531.1Spgoyette		{
541.1Spgoyette		sub("#.*", "", $0);
551.1Spgoyette		gsub("  *", " ", $0);
561.1Spgoyette		if (NF==0) {
571.1Spgoyette			next;
581.1Spgoyette		}
591.1Spgoyette		add($2, $1, 0);
601.1Spgoyette		for (i=3; i<=NF; i++) {
611.1Spgoyette			add($2, $i, 1);
621.1Spgoyette		}
631.1Spgoyette		}
641.1Spgoyette		END {
651.1Spgoyette		for (key in names) {
661.1Spgoyette			proto = key;
671.1Spgoyette
681.1Spgoyette			n = split(names[key], ar);
691.1Spgoyette			printf "name=%s, proto=%s, aliases=", ar[1], proto;
701.1Spgoyette			for (i=2; i<=n; i++) {
711.1Spgoyette			if (i>2) {
721.1Spgoyette				printf " ";
731.1Spgoyette			}
741.1Spgoyette			printf "%s", ar[i];
751.1Spgoyette			}
761.1Spgoyette			printf "\n";
771.1Spgoyette			delete ar;
781.1Spgoyette		}
791.1Spgoyette		}
801.1Spgoyette	' | sort >exp
811.1Spgoyette
821.1Spgoyette	# run test program
831.1Spgoyette	"$(atf_get_srcdir)/h_protoent" | sed 's/ *$//' | sort >out
841.1Spgoyette
851.1Spgoyette	diff -u exp out || \
861.1Spgoyette	    atf_fail "Observed output does not match reference output"
871.1Spgoyette}
881.1Spgoyette
891.1Spgoyetteatf_init_test_cases()
901.1Spgoyette{
911.1Spgoyette	atf_add_test_case protoent
921.1Spgoyette}
93