#! /bin/sh # -*- Mode: Shell-script -*- # ---------------------------------------------------------------------- # nested.test --- test nested option values # # Time-stamp: "2007-07-04 10:11:40 bkorb" # Author: Bruce Korb # Last Modified: $Date: 2007/07/04 21:36:39 $ # by: bkorb ## ## This file is part of AutoOpts, a companion to AutoGen. ## AutoOpts is free software. ## AutoOpts is copyright (c) 1992-2007 by Bruce Korb - all rights reserved ## ## AutoOpts is available under any one of two licenses. The license ## in use must be one of these two and the choice is under the control ## of the user of the license. ## ## The GNU Lesser General Public License, version 3 or later ## See the files "COPYING.lgplv3" and "COPYING.gplv3" ## ## The Modified Berkeley Software Distribution License ## See the file "COPYING.mbsd" ## ## These files have the following md5sums: ## ## 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3 ## fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3 ## 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd # # $Id: nested.test,v 4.8 2007/07/04 21:36:39 bkorb Exp $ # ---------------------------------------------------------------------- . ./defs # # # # # # # # # # DEFINITIONS FILE # # # # # # # # # exec 5> ${testname}.def cat >&5 <<- _EOF_ AutoGen definitions options; config-header = 'config.h'; prog-name = "test_${testname}"; prog-title = "Test AutoOpts for ${testname}"; flag = { name = struct; value = s; max = NOLIMIT; descrip = 'structured argument val'; arg-type = nested; }; main = { main-type = main; _EOF_ echo ' main-text = <''<- _EOCode_' >&5 cat >&5 <<- _EOF_ { int ix = 0; const tOptionValue* pOV = optionFindValue(&DESC(STRUCT), NULL, NULL); do { printf("\nstruct opt #%d:\n", ++ix); res |= print_entry( pOV ); pOV = optionFindNextValue(&DESC(STRUCT), pOV, NULL, NULL); } while (pOV != NULL); } _EOF_ echo "_EOCode_; };" >&5 echo 'include = <''<- _EOSubr_' >&5 cat >&5 <<- _EOF_ #include int print_nested( const tOptionValue* pGV ); int print_entry( const tOptionValue* pGV ); int print_entry( const tOptionValue* pGV ) { if (pGV == NULL) { fprintf( stderr, "ENTRY NOT FOUND\n" ); return 1; } printf( "%-8s -- ", pGV->pzName ); switch (pGV->valType) { case OPARG_TYPE_NONE: fputs( "no value\n", stdout ); break; case OPARG_TYPE_STRING: printf( "string: %s\n", pGV->v.strVal ); break; case OPARG_TYPE_ENUMERATION: printf( "enum: %d\n", pGV->v.enumVal ); break; case OPARG_TYPE_BOOLEAN: printf( "bool: %s\n", pGV->v.boolVal ? "TRUE" : "false" ); break; case OPARG_TYPE_MEMBERSHIP: printf("members: 0x%08lX\n", (unsigned long)pGV->v.setVal); break; case OPARG_TYPE_NUMERIC: printf( "integer: %ld\n", pGV->v.longVal ); break; case OPARG_TYPE_HIERARCHY: printf( "nested: 0x%08lX\n", (unsigned long)pGV->v.nestVal ); return print_nested( pGV ); break; default: printf( "bad type: %d\n", pGV->valType ); return 1; } return 0; } int print_nested( const tOptionValue* pGV ) { int res = 0; const tOptionValue* pOV = optionGetValue( pGV, NULL ); while (pOV != NULL) { res |= print_entry( pOV ); pOV = optionNextValue( pGV, pOV ); } return res; } _EOF_ echo "_EOSubr_;" >&5 exec 5>&- # # # # # # # # # # CREATE PROGRAM # # # # # # # # # echo ${AG_L} ${testname}.def ${AG_L} ${testname}.def || \ failure AutoGen could not process compile "-?" # # # # # # # # # # HELP OUTPUT FILE # # # # # # # # # basehelp=${testname}-base.help echo creating ${basehelp} cat > ${basehelp} <<_EOF_ test_${testname} - Test AutoOpts for ${testname} USAGE: ${testname} [ - [] ]... Flg Arg Option-Name Description -s Cpx struct structured argument val - may appear multiple times -? no help Display usage information and exit -! no more-help Extended usage information passed thru pager _EOF_ cmp -s ${basehelp} ${testname}.help || \ failure "`diff ${basehelp} ${testname}.help`" # # # # # # # # # # SINGLE ARG TEST # # # # # # # # # cat > ${testname}-res1.base <<_EOF_ struct opt #1: struct -- nested: 0xXXXXXXXX able -- no value bar -- integer: 1234 foo -- no value stumble -- no value _EOF_ ./${testname} -s 'stumble, foo, 1234 able' | \ sed '/ nested:/s/ 0x.*/ 0xXXXXXXXX/' > ${testname}-res1.out || \ failure "FAILED: \ ./${testname} -s 'stumble, foo, 1234 baz'" cmp -s ${testname}-res1.* || \ failure "`diff ${testname}-res1.*`" # # # # # # # # # # DOUBLE ARG TEST # # # # # # # # # (./${testname} -s 'stumble, foo, 1234, able' \ -s 'foo, 4321 one, two, three' \ | sed '/ nested:/s/ 0x.*/ 0xXXXXXXXX/' ) > ${testname}-res2.out || \ failure "FAILED: ./${testname} ${arg1} ${arg2}" cat > ${testname}-res2.base <<- _EOF_ struct opt #1: struct -- nested: 0xXXXXXXXX able -- no value bar -- integer: 1234 foo -- no value stumble -- no value struct opt #2: struct -- nested: 0xXXXXXXXX bar -- integer: 4321 foo -- no value gr -- nested: 0xXXXXXXXX one -- no value three -- no value two -- no value _EOF_ cmp -s ${testname}-res2.* || \ failure "`diff ${testname}-res2.*`" # # # # # # # # # # TEST OPERATION # # # # # # # # # # cleanup ## Local Variables: ## Mode: shell-script ## indent-tabs-mode: nil ## sh-indentation: 2 ## End: # end of nested.test