#!/bin/sh
# init-functions.sh  

##########################################################################
# (C) Copyright 2005 The Open Group
#
# All rights reserved.  No part of this source code may be reproduced,
# stored in a retrieval system, or transmitted, in any form or by any
# means, electronic, mechanical, photocopying, recording or otherwise,
# except as stated in the end-user licence agreement, without the prior
# permission of the copyright owners.
#
# X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
# the UK and other countries.
#
#       PRODUCT:        LSBinitd/tset/initd/misc/init-functions.sh
#       AUTHOR:         Andrew Josey, The Open Group
#       DATE CREATED:   20 June 2005
##########################################################################

tet_startup="startup"			# startup function
tet_cleanup="cleanup"			# cleanup function
iclist="ic1 ic2 ic3 ic4 ic5 ic6 ic7"
ic1="tp1"
ic2="tp2"
ic3="tp3"
ic4="tp4"
ic5="tp5"
ic6="tp6"
ic7="tp7"

tp1()
{
        tpstart "Reference 20.2-1(A), The file /lib/lsb/init-functions shall exist"
	tet_infoline "Spec reference: 20.2. Init Script Actions"
	lsb_test_file /lib/lsb/init-functions  >out.stdout 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}

# The start_daemon, killproc and pidofproc
# log_failure_msg, log_success_msg, log_warning_msg
# shall exist in the environment after sourcing in /lib/lsb/init-functions
# its unspecified whether they are functions, utilities or whatever

tp2()
{
        tpstart "Reference 20.8-1(A), The /lib/lsb/init-functions file shall define start_daemon in the current environment"
	command -V start_daemon >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}

tp3()
{
        tpstart "Reference 20.8-2(A), The /lib/lsb/init-functions file shall define killproc in the current environment"
	command -V killproc >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}


tp4()
{
        tpstart "Reference 20.8-4(A), The /lib/lsb/init-functions file shall define pidofproc in the current environment"
	command -V pidofproc >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}

tp5()
{
        tpstart "Reference 20.8-4(A), The /lib/lsb/init-functions file shall define log_success_msg in the current environment"
	command -V log_success_msg >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}

tp6()
{
        tpstart "Reference 20.8-5(A), The /lib/lsb/init-functions file shall define log_failure_msg in the current environment"
	command -V log_failure_msg >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}

tp7()
{
        tpstart "Reference 20.8-6(A), The /lib/lsb/init-functions file shall define log_warning_msg in the current environment"
	command -V log_warning_msg >out.stderr 2>out.stderr
        check_exit_value $? 0 
        tpresult                        # set result code
}
	  
startup() # startup function
{
     rm -f out.stdout out.stderr out.experr dev.out fail.out >/dev/null 2>&1
     tet_infoline "Prep: Source /lib/lsb/init-functions into the current environment"
     if [ ! -r /lib/lsb/init-functions ]
     then 
         FAIL=Y
     else
     	.  /lib/lsb/init-functions  >out.stdout 2>out.stderr
     fi
     check_exit_value $? 0 
     if [ "$FAIL" = "Y" ]
     then
          for testcasename in tp1 tp2 tp3 tp4 tp5 tp6 tp7
          do
               tet_delete $testcasename "Source of /lib/lsb/init-functions failed"
          done
          return
     fi
     
}

cleanup() # clean-up function
{
     rm -f out.stdout out.stderr out.experr dev.out fail.out >/dev/null 2>&1
}

# source common shell functions

. $TET_EXECUTE/LIB/shfuncs.sh
. $TET_EXECUTE/LIB/lsbfuncs.sh

# execute shell test case manager - must be last line
. $TET_ROOT/lib/xpg3sh/tcm.sh
