#! /bin/sh # -*- Mode: Shell-script -*- # ---------------------------------------------------------------------- # rc.test --- test loading and saving of rc files # # Time-stamp: "2007-07-04 10:12:45 bkorb" # Author: Bruce Korb ## ## 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: config.test,v 4.6 2007/07/04 21:36:39 bkorb Exp $ # ---------------------------------------------------------------------- . ./defs # # # # # # # # # # PROGRAM FILE # # # # # # # # # cat > ${testname}.c <<- _EOTest_ #include #include "config.h" #include 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 ); break; default: printf( "bad type: %d\n", pGV->valType ); return 1; } return 0; } int main( int argc, char** argv ) { int res = 0; const tOptionValue* pOV; if ((argc < 3) || (argv[1][0] == '-')) { fputs( "help\n", stdout ); return 0; } pOV = configFileLoad( *++argv ); if (pOV == NULL) { fprintf( stderr, "Could not load: %s\n", *argv ); return 1; } argc -= 2; while (argc-- > 0) { const tOptionValue* pGV = optionGetValue( pOV, *++argv ); res |= print_entry( pGV ); } { const tOptionValue* pGV = optionGetValue( pOV, "nasty" ); pGV = optionGetValue( pGV, "bar" ); if (pGV->valType != OPARG_TYPE_BOOLEAN) { res = 1; } else if (pGV->v.boolVal) { fputs( "YES!!\n", stdout ); } else { fputs( "oops!!\n", stdout ); res = 1; } } { const tOptionValue* pGV = optionGetValue( pOV, NULL ); while (pGV != NULL) { res |= print_entry( pGV ); pGV = optionNextValue( pOV, pGV ); } } print_entry( pOV ); optionUnloadNested( pOV ); return res; } _EOTest_ compile --help # # # # # # # # # # RUN TESTS # # # # # # # # # echo Constructing test ${testname} files cat > ${testname}.cfg <<- \_EOConfig_ mumble = grumble grumble : rumble stumble "The\tquick\ brown fox\tjumped\n\ over everything." foo : foolish YES!! alpha, beta ', gamma' "Carol\tTine\n" 42 _EOConfig_ cat > ${testname}.res <<- \_EOResult_ mumble -- string: grumble grumble -- string: rumble stumble -- string: The quickbrown fox jumped over everything. alpha -- no value beta -- string: , gamma zzyzx -- integer: 42 YES!! alpha -- no value beta -- string: , gamma beta -- string: Carol Tine grumble -- string: rumble mumble -- string: grumble nasty -- nested: 0xXXXXXXXX stumble -- string: The quickbrown fox jumped over everything. zzyzx -- integer: 42 ./config.cfg -- nested: 0xXXXXXXXX _EOResult_ ./${testname} ./${testname}.cfg mumble grumble stumble alpha beta zzyzx \ > ${testname}.tmp-out || { failure "Cannot run ${testname}" } sed '/ -- nested:/s/0x.*/0xXXXXXXXX/' \ ${testname}.tmp-out > ${testname}.out cmp ${testname}.out ${testname}.res || { failure "`diff -c ${testname}.out ${testname}.res`" } ./${testname} ${testname}.cfg gamma >/dev/null && \ failure "found non-existent value" # # # # # # # # # # CLEANUP # # # # # # # # # cleanup ## Local Variables: ## Mode: shell-script ## indent-tabs-mode: nil ## sh-indentation: 2 ## End: # end of config.test