[brlcad-commits] SF.net SVN: brlcad:[50775] brlcad/branches/STABLE
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2012-05-31 02:12:05
|
Revision: 50775 http://brlcad.svn.sourceforge.net/brlcad/?rev=50775&view=rev Author: starseeker Date: 2012-05-31 02:11:54 +0000 (Thu, 31 May 2012) Log Message: ----------- Back up the libbu vls work to 50646 - regressions appear to be breaking. Modified Paths: -------------- brlcad/branches/STABLE/regress/CMakeLists.txt brlcad/branches/STABLE/regress/Makefile.am brlcad/branches/STABLE/src/libbu/CMakeLists.txt brlcad/branches/STABLE/src/libbu/Makefile.am brlcad/branches/STABLE/src/libbu/parse.c brlcad/branches/STABLE/src/libbu/test_booleanize.c brlcad/branches/STABLE/src/libbu/test_quote.c brlcad/branches/STABLE/src/libbu/vls.c Added Paths: ----------- brlcad/branches/STABLE/regress/vls.sh brlcad/branches/STABLE/src/libbu/test_vls.c Removed Paths: ------------- brlcad/branches/STABLE/regress/vls_vprintf.sh brlcad/branches/STABLE/src/libbu/test_bitv.c brlcad/branches/STABLE/src/libbu/test_ctype.c brlcad/branches/STABLE/src/libbu/test_vls_vprintf.c brlcad/branches/STABLE/src/libbu/vls_internals.h brlcad/branches/STABLE/src/libbu/vls_vprintf.c Modified: brlcad/branches/STABLE/regress/CMakeLists.txt =================================================================== --- brlcad/branches/STABLE/regress/CMakeLists.txt 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/regress/CMakeLists.txt 2012-05-31 02:11:54 UTC (rev 50775) @@ -61,9 +61,9 @@ ${SH_EXEC} ${CMAKE_SOURCE_DIR}/regress/red.sh ${CMAKE_SOURCE_DIR} DEPENDS mged ) - add_custom_target(regress-vls_vprintf - ${SH_EXEC} ${CMAKE_SOURCE_DIR}/regress/vls_vprintf.sh ${CMAKE_SOURCE_DIR} - DEPENDS test_vls_vprintf + add_custom_target(regress-vls + ${SH_EXEC} ${CMAKE_SOURCE_DIR}/regress/vls.sh ${CMAKE_SOURCE_DIR} + DEPENDS test_vls ) add_custom_target(regress-nirt ${SH_EXEC} ${CMAKE_SOURCE_DIR}/regress/nirt.sh ${CMAKE_SOURCE_DIR} @@ -100,7 +100,7 @@ regress-solids regress-shaders regress-spdi regress-iges regress-weight regress-gqa regress-fastgen regress-bots regress-repository regress-red regress-nirt - regress-vls_vprintf regress-comgeom regress-gnff regress-gdot + regress-vls regress-comgeom regress-gnff regress-gdot ) endif(SH_EXEC) @@ -151,7 +151,7 @@ tgms/comgeom-tgt-1-v4.cg tgms/m35.asc.gz tgms/m35.cg.gz - vls_vprintf.sh + vls.sh weight.sh ) Modified: brlcad/branches/STABLE/regress/Makefile.am =================================================================== --- brlcad/branches/STABLE/regress/Makefile.am 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/regress/Makefile.am 2012-05-31 02:11:54 UTC (rev 50775) @@ -1,8 +1,8 @@ -.PHONY : regression regress test mged red moss lights solids shaders spdi iges weight gqa fastgen bots repository comgeom gdot gnff vls_vprintf +.PHONY : regression regress test mged red moss lights solids shaders spdi iges weight gqa fastgen bots repository comgeom gdot gnff SUBDIRS = mged -regression: clean mged moss lights solids shaders spdi iges weight gqa fastgen bots repository comgeom gdot gnff vls_vprintf +regression: clean mged moss lights solids shaders spdi iges weight gqa fastgen bots repository comgeom gdot gnff @${ECHO} --- @${ECHO} Regression testing completed. @@ -78,10 +78,6 @@ -${SH} $(top_srcdir)/regress/g-nff.sh $(top_srcdir) @${ECHO} +++ $@ test complete. -vls_vprintf: $(top_srcdir)/regress/vls_vprintf.sh - -${SH} $(top_srcdir)/regress/vls_vprintf.sh $(top_srcdir) - @${ECHO} +++ $@ test complete. - # these are here because they go in the distribution but are not installed EXTRA_DIST = \ bots.sh \ @@ -115,7 +111,7 @@ spdi.sh \ spdipix.asc \ testlib.c \ - vls_vprintf.sh \ + vls.sh \ weight.sh \ CMakeLists.txt Added: brlcad/branches/STABLE/regress/vls.sh =================================================================== --- brlcad/branches/STABLE/regress/vls.sh (rev 0) +++ brlcad/branches/STABLE/regress/vls.sh 2012-05-31 02:11:54 UTC (rev 50775) @@ -0,0 +1,125 @@ +#!/bin/sh +# V L S . S H +# BRL-CAD +# +# Copyright (c) 2010-2012 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# for debugging uncomment the following: +#set -x +# Ensure /bin/sh +export PATH || (echo "This isn't sh."; sh $0 $*; kill $$) + +# source common library functionality, setting ARGS, NAME_OF_THIS, +# PATH_TO_THIS, and THIS. +. "$1/regress/library.sh" + +TEST=vls +TESTSCRIPT=$TEST.sh +TESTEXE=test_vls +TESTLOG=${TEST}_test.log +TESTCMD="`ensearch $TESTEXE`" +if test ! -f "$TESTCMD" ; then + echo "Unable to find $TESTEXE, aborting" + exit 1 +fi + +# another file for test output +ERRLOG=${TEST}_test.stderr + +rm -f $TESTLOG $ERRLOG + +# the known number of expected failures is: +KNOWNEXP=0 +# run the test and capture exit status +`$TESTCMD 1> $TESTLOG 2>$ERRLOG` +STATUS=$? +# STATUS contains number of UNEXPECTED failures +# get the failure numbers +if [ -f $ERRLOG ] ; then + EXP=`cat $ERRLOG` +else + EXP=0 +fi +if [ $STATUS -ge 128 ] ; then + # a signal received + SIGNUM=`expr $STATUS - 128` + echo "-> $TESTSCRIPT FAILED with signal $SIGNUM." + if [ $SIGNUM -eq 11 ] ; then + echo " (SIGSEGV, invalid memory reference)" + fi + echo " See file './regress/$TESTLOG' for results (may be empty with a code dump)." + # allow the rest of the test to continue + STATUS=`expr $STATUS - $SIGNUM - 128` +fi + +# FIXME: this if/else block can be more efficient +if [ $STATUS -eq 0 ] ; then + if [ $KNOWNEXP -ne 0 ] ; then + if [ $EXP -eq $KNOWNEXP ] ; then + echo "-> $TESTSCRIPT succeeded with $EXP expected failed test(s)." + echo " See file './regress/$TESTLOG' for results." + echo " Do NOT use the failures in production code." + fi + elif [ $EXP -ne 0 ] ; then + echo "-> $TESTSCRIPT succeeded with $EXP expected failed test(s)." + echo " But SURPRISE! We expected $KNOWNEXP failed tests so something has changed!" + echo " See file './regress/$TESTLOG' for results and compare" + echo " with file './src/libbu/test_vls.c'." + echo " Do NOT use the failures in production code." + else + echo "-> $TESTSCRIPT succeeded with no failures of any kind." + # but one more check + if [ $KNOWNEXP -ne 0 ] ; then + echo " But SURPRISE! We expected $KNOWNEXP failed tests so something has changed!" + echo " See file './regress/$TESTLOG' for results and compare" + echo " with file './src/libbu/test_vls.c'." + else + # remove test products since all appears well + rm -f $TESTLOG $ERRLOG + fi + fi +else + echo "-> $TESTSCRIPT unexpectedly FAILED $STATUS test(s)." + echo " See file './regress/$TESTLOG' for results." +fi + +exit $STATUS + +# Local Variables: +# mode: sh +# tab-width: 8 +# sh-indentation: 4 +# sh-basic-offset: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 Property changes on: brlcad/branches/STABLE/regress/vls.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/x-sh Added: svn:eol-style + native Deleted: brlcad/branches/STABLE/regress/vls_vprintf.sh =================================================================== --- brlcad/branches/STABLE/regress/vls_vprintf.sh 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/regress/vls_vprintf.sh 2012-05-31 02:11:54 UTC (rev 50775) @@ -1,127 +0,0 @@ -#!/bin/sh -# V L S _ V P R I N T F . S H -# BRL-CAD -# -# Copyright (c) 2010-2012 United States Government as represented by -# the U.S. Army Research Laboratory. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# 3. The name of the author may not be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -### -# for debugging uncomment the following: -#set -x -# Ensure /bin/sh -export PATH || (echo "This isn't sh."; sh $0 $*; kill $$) - -# source common library functionality, setting ARGS, NAME_OF_THIS, -# PATH_TO_THIS, and THIS. -. "$1/regress/library.sh" - -TEST=vls_vprintf -TESTSCRIPT=$TEST.sh -TESTEXE=test_vls_vprintf -TESTLOG=${TEST}_test.log -TESTCMD="`ensearch $TESTEXE`" -if test ! -f "$TESTCMD" ; then - echo "Unable to find $TESTEXE, aborting" - exit 1 -fi - -# another file for test output -ERRLOG=${TEST}_test.stderr - -rm -f $TESTLOG $ERRLOG - -# the known number of expected failures is: -KNOWNEXP=0 -# run the test and capture exit status -`$TESTCMD 1> $TESTLOG 2>$ERRLOG` -STATUS=$? -# STATUS contains number of UNEXPECTED failures -# get the failure numbers -if [ -f $ERRLOG ] ; then - EXP=`cat $ERRLOG` -else - EXP=0 -fi -if [ $STATUS -ge 128 ] ; then - # a signal received - SIGNUM=`expr $STATUS - 128` - echo "-> $TESTSCRIPT FAILED with signal $SIGNUM." - if [ $SIGNUM -eq 11 ] ; then - echo " (SIGSEGV, invalid memory reference)" - fi - echo " See file './regress/$TESTLOG' for results (may be empty with a code dump)." - # allow the rest of the test to continue - STATUS=`expr $STATUS - $SIGNUM - 128` -fi - -# FIXME: this if/else block can be more efficient -if [ $STATUS -eq 0 ] ; then - if [ $KNOWNEXP -ne 0 ] ; then - if [ $EXP -eq $KNOWNEXP ] ; then - echo "-> $TESTSCRIPT succeeded with $EXP expected failed test(s)." - echo " See file './regress/$TESTLOG' for results." - echo " Do NOT use the failures in production code." - fi - elif [ $EXP -ne 0 ] ; then - echo "-> $TESTSCRIPT succeeded with $EXP expected failed test(s)." - echo " But SURPRISE! We expected $KNOWNEXP failed tests so something has changed!" - echo " See file './regress/$TESTLOG' for results and compare" - echo " with file './src/libbu/test_vls.c'." - echo " Do NOT use the failures in production code." - else - echo "-> $TESTSCRIPT succeeded with no failures of any kind." - # but one more check - if [ $KNOWNEXP -ne 0 ] ; then - echo " But SURPRISE! We expected $KNOWNEXP failed tests so" - echo " something has changed!" - echo " See file './regress/$TESTLOG' for results and compare" - echo " with file './src/libbu/test_vls.c'." - else - # remove test products since all appears well - rm -f $TESTLOG $ERRLOG - fi - fi -else - echo "-> $TESTSCRIPT unexpectedly FAILED $STATUS test(s)." - echo " See files './regress/$TESTLOG' and." - echo " './regress/$ERRLOG' for results." -fi - -exit $STATUS - -# Local Variables: -# mode: sh -# tab-width: 8 -# sh-indentation: 4 -# sh-basic-offset: 4 -# indent-tabs-mode: t -# End: -# ex: shiftwidth=4 tabstop=8 Modified: brlcad/branches/STABLE/src/libbu/CMakeLists.txt =================================================================== --- brlcad/branches/STABLE/src/libbu/CMakeLists.txt 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/CMakeLists.txt 2012-05-31 02:11:54 UTC (rev 50775) @@ -87,7 +87,6 @@ vfont.c vlb.c vls.c - vls_vprintf.c whereis.c which.c xdr.c @@ -101,16 +100,14 @@ endif("${BRLCAD_TCL_BUILD}" STREQUAL "ON") BRLCAD_ADDEXEC(test_basename test_basename.c libbu NO_INSTALL) -BRLCAD_ADDEXEC(test_bitv test_bitv.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_booleanize test_booleanize.c libbu NO_INSTALL) -BRLCAD_ADDEXEC(test_ctype test_ctype.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_dirname test_dirname.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_escape test_escape.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_progname test_progname.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_quote test_quote.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_sscanf test_sscanf.c libbu NO_INSTALL) BRLCAD_ADDEXEC(test_timer test_timer.c libbu NO_INSTALL) -BRLCAD_ADDEXEC(test_vls_vprintf test_vls_vprintf.c libbu NO_INSTALL) +BRLCAD_ADDEXEC(test_vls test_vls.c libbu NO_INSTALL) set(bu_MAN3 htond.3 @@ -121,7 +118,6 @@ set(bu_ignore_files rb_internals.h uce-dirent.h - vls_internals.h ) CMAKEFILES(${bu_ignore_files}) CMAKEFILES(Makefile.am) Modified: brlcad/branches/STABLE/src/libbu/Makefile.am =================================================================== --- brlcad/branches/STABLE/src/libbu/Makefile.am 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/Makefile.am 2012-05-31 02:11:54 UTC (rev 50775) @@ -5,15 +5,13 @@ noinst_PROGRAMS = \ test_basename \ test_booleanize \ - test_ctype \ test_dirname \ test_escape \ test_progname \ test_quote \ test_timer \ - test_vls_vprintf \ - test_sscanf \ - test_bitv + test_vls \ + test_sscanf libbu_nil_la_SOURCES = \ argv.c \ @@ -92,7 +90,6 @@ vfont.c \ vlb.c \ vls.c \ - vls_vprintf.c \ whereis.c \ which.c \ xdr.c @@ -105,19 +102,8 @@ test_booleanize_SOURCES = test_booleanize.c test_booleanize_LDADD = \ - libbu.la \ + libbu.la ${BU_LIBS} - -test_bitv_SOURCES = test_bitv.c -test_bitv_LDADD = \ - libbu.la \ - ${BU_LIBS} - -test_ctype_SOURCES = test_ctype.c -test_ctype_LDADD = \ - libbu.la \ - ${BU_LIBS} - test_timer_SOURCES = test_timer.c test_timer_LDADD = \ libbu.la \ @@ -148,8 +134,8 @@ libbu.la \ ${BU_LIBS} -test_vls_vprintf_SOURCES = test_vls_vprintf.c -test_vls_vprintf_LDADD = \ +test_vls_SOURCES = test_vls.c +test_vls_LDADD = \ libbu.la \ ${BU_LIBS} @@ -159,8 +145,7 @@ ${BU_LIBS} noinst_HEADERS = \ - rb_internals.h \ - vls_internals.h + rb_internals.h man_MANS = \ htond.3 \ Modified: brlcad/branches/STABLE/src/libbu/parse.c =================================================================== --- brlcad/branches/STABLE/src/libbu/parse.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/parse.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -683,6 +683,9 @@ } } break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { struct bu_vls *vls = (struct bu_vls *)loc; @@ -996,6 +999,9 @@ else bu_vls_printf(vp, "%s", (char *)loc); break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { struct bu_vls *vls = (struct bu_vls *)loc; @@ -1125,6 +1131,9 @@ bu_log("\t%s=\"%s\"\n", sdp->sp_name, (char *)loc); break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { struct bu_vls *vls = (struct bu_vls *)loc; @@ -1329,6 +1338,9 @@ bu_vls_free(&tmpstr); } break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { struct bu_vls *vls_p = (struct bu_vls *)loc; @@ -1450,6 +1462,9 @@ bu_vls_printf(vls_out, "\t%s=\"%s\"\n", sdp->sp_name, (char *)loc); break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { struct bu_vls *vls = (struct bu_vls *)loc; @@ -2194,6 +2209,7 @@ /* These types are specified by lengths, e.g. %80s */ if (BU_STR_EQUAL(sp->sp_fmt, "%c") || BU_STR_EQUAL(sp->sp_fmt, "%s") || + BU_STR_EQUAL(sp->sp_fmt, "%S") || /* XXX - DEPRECATED [7.14] */ BU_STR_EQUAL(sp->sp_fmt, "%V")) { if (sp->sp_count > 1) { /* Make them all look like %###s */ @@ -2285,6 +2301,9 @@ bu_vls_printf(logstr, "%s %c ", sdp->sp_name, *loc); } break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ case 'V': { /* copy the string to a bu_vls (string of Deleted: brlcad/branches/STABLE/src/libbu/test_bitv.c =================================================================== --- brlcad/branches/STABLE/src/libbu/test_bitv.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/test_bitv.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -1,266 +0,0 @@ -/* T E S T _ B I T V . C - * BRL-CAD - * - * Copyright (c) 2012 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ - - -#include "common.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include "bu.h" - - -unsigned int -power(unsigned int base , int exponent) -{ - int i ; - unsigned int product = 1; - - for (i = 0; i < exponent; i++) { - product = product*base; - } - - return product; -} - - -int -test_bu_hex_to_bitv(char *inp, char *res , int errno) -{ - struct bu_bitv *res_bitv ; - int pass; - - res_bitv = bu_hex_to_bitv(inp); - - if (errno == 1 && res_bitv == NULL) { - printf("\nbu_hex_to_bitv PASSED Input:%s Output:%s", inp, res); - return 0; - } - - if (!bu_strcmp((char*)res_bitv->bits, res)) { - printf("\nbu_hex_to_bitv PASSED Input:%s Output:%s", inp, (char*)res_bitv->bits); - pass = 1 ; - } else { - printf("\nbu_hex_to_bitv FAILED for Input:%s Expected:%s", inp, res); - pass = 0; - } - - bu_bitv_free(res_bitv); - - return pass; -} - - -int -test_bu_bitv_to_hex(char *inp , char *res , int length) -{ - struct bu_vls *a; - struct bu_bitv *res_bitv; - int pass; - - a = bu_vls_vlsinit(); - res_bitv = bu_bitv_new(length); - - /* accessing the bits array directly as a char* is not safe since - * there's no bounds checking and assumes implementation is - * contiguous memory. - */ - bu_strlcpy((char*)res_bitv->bits, inp, length/8); - - bu_bitv_to_hex(a, res_bitv); - - if (!bu_strcmp(a->vls_str, res)) { - printf("\nbu_bitv_to_hex PASSED Input:%5s Output:%9s", inp, res); - pass = 1 ; - } else { - printf("\nbu_bitv_to_hex FAILED for Input:%s Expected:%s", inp, res); - pass = 0; - } - - bu_bitv_free(res_bitv); - bu_vls_free(a); - - return pass; -} - - -int -test_bu_bitv_vls(char *inp , char *exp) -{ - struct bu_vls *a; - struct bu_bitv *res_bitv; - int pass; - - a = bu_vls_vlsinit(); - res_bitv = bu_hex_to_bitv(inp); - bu_bitv_vls(a, res_bitv); - - if (!bu_strcmp(a->vls_str, exp)) { - printf("\nbu_bitv_vls test PASSED Input:%s Output:%s", inp, (char *)a->vls_str); - pass = 1; - } else { - printf("\nbu_bitv_vls FAILED for Input:%s Expected:%s", inp, exp); - pass = 0; - } - - bu_vls_free(a); - bu_bitv_free(res_bitv); - - return pass; -} - - -int -test_bu_bitv_or(char *inp1 , char *inp2 , char *exp) -{ - struct bu_bitv *res_bitv , *res_bitv1 , *result; - struct bu_vls *a , *b; - int pass; - - a = bu_vls_vlsinit(); - b = bu_vls_vlsinit(); - - res_bitv1 = bu_hex_to_bitv(inp1); - res_bitv = bu_hex_to_bitv(inp2); - result = bu_hex_to_bitv(exp); - - bu_bitv_or(res_bitv1, res_bitv); - bu_bitv_vls(a, res_bitv1); - bu_bitv_vls(b, result); - - if (!bu_strcmp(a->vls_str, b->vls_str)) { - printf("\nbu_bitv_or test PASSED Input1:%s Input2:%s Output:%s", inp1, inp2, exp); - pass = 1; - } else { - printf("\nbu_bitv_or test FAILED Input1:%s Input2:%s Expected:%s", inp1, inp2, exp); - pass = 0; - } - - bu_bitv_free(res_bitv); - bu_bitv_free(res_bitv1); - bu_bitv_free(result); - - return pass; -} - - -int -test_bu_bitv_and(char *inp1 , char *inp2 , char *exp) -{ - struct bu_bitv *res_bitv , *res_bitv1 , *result; - struct bu_vls *a , *b; - int pass; - - a = bu_vls_vlsinit(); - b = bu_vls_vlsinit(); - - res_bitv1 = bu_hex_to_bitv(inp1); - res_bitv = bu_hex_to_bitv(inp2); - result = bu_hex_to_bitv(exp); - - bu_bitv_and(res_bitv1,res_bitv); - bu_bitv_vls(a,res_bitv1); - bu_bitv_vls(b,result); - - if (!bu_strcmp(a->vls_str , b->vls_str)) { - printf("\nbu_bitv_and test PASSED Input1:%s Input2:%s Output:%s", inp1, inp2, exp); - pass = 1; - } else { - printf("\nbu_bitv_and test FAILED Input1:%s Input2:%s Expected:%s", inp1, inp2, exp); - pass = 0; - } - - bu_bitv_free(res_bitv); - bu_bitv_free(res_bitv1); - bu_bitv_free(result); - - return pass; -} - - -int -main(int ac , char **av) -{ - int res , pass = 1; - - /* unused variables generate warnings, and sometimes warnings are treated as errors*/ - if (ac) {}; - if (av) {}; - - /*test bu_bitv_shift*/ - res = bu_bitv_shift(); - - printf("\nTesting bu_bitv_shift..."); - if (power(2, res) <= (sizeof(bitv_t) * 8) && power(2, res + 1) > (sizeof(bitv_t) * 8)) { - printf("\nPASSED: bu_bitv_shift working"); - } else { - printf("\nFAILED: bu_bitv_shift incorrect"); - pass = 0; - } - - printf("\n\n"); - - /*testing bu_hex_to_bitv*/ - printf("Testing bu_hex_to_bitv..."); - test_bu_hex_to_bitv("33323130", "0123", 0); - test_bu_hex_to_bitv("30", "0", 0); - printf("\n(Intentionally invoked an error here; a message about it is normal!)"); - test_bu_hex_to_bitv("303", "", 1); - printf("\n\n"); - - /*testing bu_bitv_to_hex*/ - printf("Testing bu_bitv_to_hex..."); - pass *= test_bu_bitv_to_hex("0123", "33323130", 32); - pass *= test_bu_bitv_to_hex("12", "3231", 16); - printf("\n\n"); - - /* testing bu_bitv_vls */ - printf("Testing bu_bitv_vls..."); - pass *= test_bu_bitv_vls("00000000", "() "); - pass *= test_bu_bitv_vls("f0f0f0f0", "(4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31) "); - printf("\n\n"); - - /*test bu_bitv_or*/ - printf("Testing bu_bitv_or..."); - pass *= test_bu_bitv_or("ffffffff", "00000000", "ffffffff"); - pass *= test_bu_bitv_or("ab00", "1200", "bb00"); - printf("\n\n"); - - /*test bu_bitv_and*/ - printf("Testing bu_bitv_and..."); - pass *= test_bu_bitv_and("ffffffff", "00000000", "00000000"); - pass *= test_bu_bitv_and("ab00", "1200", "0200"); - printf("\n\n"); - - return (1 - pass); -} - - -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Modified: brlcad/branches/STABLE/src/libbu/test_booleanize.c =================================================================== --- brlcad/branches/STABLE/src/libbu/test_booleanize.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/test_booleanize.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -17,7 +17,7 @@ * License along with this file; see the file named COPYING for more * information. */ - + #include "common.h" #include "bu.h" @@ -31,58 +31,58 @@ int buf_len, check, res, ans; if (input) { - bu_strlcpy(buf_input, input, strlen(input)+1); + bu_strlcpy(buf_input, input, strlen(input)+1); - buf_len = strlen(buf_input); + buf_len = strlen(buf_input); - /* Remove ending white space */ - while ((buf_len > 0) && (buf_input[buf_len-1] == ' ')) { - buf_input[buf_len-1] = '\0'; - buf_len = strlen(buf_input); - } + /* Remove ending white space */ + while ((buf_len > 0) && (buf_input[buf_len-1] == ' ')) { + buf_input[buf_len-1] = '\0'; + buf_len = strlen(buf_input); + } - /* Remove leading white space */ - while ((buf_len > 0) && (buf_input[0] == ' ')) { - bu_strlcpy(buf_aux, buf_input + 1, buf_len); - bu_strlcpy(buf_input, buf_aux, buf_len); - buf_len = strlen(buf_input); - } - res = bu_str_true(buf_input); + /* Remove leading white space */ + while ((buf_len > 0) && (buf_input[0] == ' ')) { + bu_strlcpy(buf_aux, buf_input + 1, buf_len); + bu_strlcpy(buf_input, buf_aux, buf_len); + buf_len = strlen(buf_input); + } + res = bu_str_true(buf_input); - /* empty/'n'/'N' as first character for buf_input string */ - if ((buf_len == 0) || (buf_input[0] == 'n') || (buf_input[0] == 'N') || - (bu_strcmp(buf_input, "(null)") == 0)) { - ans = 0; - check = (res == ans); - } else { - /* true value comes from here on */ - /* 'y'/'Y' as first character/"1" or variants of 1 for buf_input string */ - if ((buf_input[0] == 'y') || (buf_input[0] == 'Y') || (atol(buf_input) == 1)) { - ans = 1; - check = (res == ans); - } else { - /* "0" or variants of 0 */ - if ((buf_input[0] == '0') && (atol(buf_input) == 0)) { - ans = 0; - check = (res == ans); - } else { - ans = (int)buf_input[0]; - check = (res == ans); - } - } - } + /* empty/'n'/'N' as first character for buf_input string */ + if ((buf_len == 0) || (buf_input[0] == 'n') || (buf_input[0] == 'N') || + (bu_strcmp(buf_input, "(null)") == 0)) { + ans = 0; + check = (res == ans); + } else { + /* true value comes from here on */ + /* 'y'/'Y' as first character/"1" or variants of 1 for buf_input string */ + if ((buf_input[0] == 'y') || (buf_input[0] == 'Y') || (atol(buf_input) == 1)) { + ans = 1; + check = (res == ans); + } else { + /* "0" or variants of 0 */ + if ((buf_input[0] == '0') && (atol(buf_input) == 0)) { + ans = 0; + check = (res == ans); + } else { + ans = (int)buf_input[0]; + check = (res == ans); + } + } + } } if (!input) { - ans = 0; - res = bu_str_true(NULL); - check = (res == ans); + ans = 0; + res = bu_str_true(NULL); + check = (res == ans); } if (check) { - printf("%24s -> %d [PASSED]\n", buf_input, res); + printf("%24s -> %d [PASSED]\n", buf_input, res); } else { - printf("%24s -> %d (should be: %d) [FAIL]\n", buf_input, res, ans); + printf("%24s -> %d (should be: %d) [FAIL]\n", buf_input, res, ans); } } @@ -113,18 +113,18 @@ /* user tests */ if (ac > 1) { - printf("Enter a string:\n"); - bu_fgets(input, 1000, stdin); - if (strlen(input) > 0) - input[strlen(input)-1] = '\0'; - automatic_test(input); + printf("Enter a string:\n"); + bu_fgets(input, 1000, stdin); + if (strlen(input) > 0) + input[strlen(input)-1] = '\0'; + automatic_test(input); } printf("%s: testing complete\n", av[0]); return 0; } + - /* * Local Variables: * mode: C Deleted: brlcad/branches/STABLE/src/libbu/test_ctype.c =================================================================== (Binary files differ) Modified: brlcad/branches/STABLE/src/libbu/test_quote.c =================================================================== --- brlcad/branches/STABLE/src/libbu/test_quote.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/test_quote.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -48,30 +48,30 @@ len_d = bu_vls_strlen(&decoded); if (f_wid < len_s) - f_wid = len_s + 1; + f_wid = len_s + 1; if (f_wid < len_d) - f_wid = len_d + 1; + f_wid = len_d + 1; if (BU_STR_EQUAL(str, bu_vls_addr(&decoded)) - /* && !BU_STR_EQUAL(str, bu_vls_addr(&encoded)) */ - ) { - /* a hack for str showing '(null)' in printf if zero length */ - if (len_s == 0) - len_s = 6; + /* && !BU_STR_EQUAL(str, bu_vls_addr(&encoded)) */ + ) { + /* a hack for str showing '(null)' in printf if zero length */ + if (len_s == 0) + len_s = 6; printf("{%*s}%*s -> {%*s}%*s [PASS]\n", - len_s, str, f_wid - len_s, " ", - len_d, bu_vls_addr(&decoded), f_wid - len_d, " " - ); + len_s, str, f_wid - len_s, " ", + len_d, bu_vls_addr(&decoded), f_wid - len_d, " " + ); } else { - /* a hack for str showing '(null)' in printf if zero length */ - if (len_s == 0) - len_s = 6; + /* a hack for str showing '(null)' in printf if zero length */ + if (len_s == 0) + len_s = 6; printf("{%*s}%*s -> {%*s}%*s [FAIL] (should be: {%s})\n", - len_s, str, f_wid - len_s, " ", - len_d, bu_vls_addr(&decoded), f_wid - len_d, " ", - str - ); - status = 1; + len_s, str, f_wid - len_s, " ", + len_d, bu_vls_addr(&decoded), f_wid - len_d, " ", + str + ); + status = 1; } bu_vls_free(&encoded); Added: brlcad/branches/STABLE/src/libbu/test_vls.c =================================================================== --- brlcad/branches/STABLE/src/libbu/test_vls.c (rev 0) +++ brlcad/branches/STABLE/src/libbu/test_vls.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -0,0 +1,239 @@ +/* T E S T _ V L S . C + * BRL-CAD + * + * Copyright (c) 2011-2012 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +#include "common.h" + +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> +#include <signal.h> +#include <string.h> + +#include "bu.h" + +/* Test against sprintf */ +int +test_vls(const char *fmt, ...) +{ + int status = 0; + struct bu_vls vls = BU_VLS_INIT_ZERO; + char output[80] = {0}; + char buffer[1024] = {0}; + va_list ap; + + va_start(ap, fmt); + /* use the libc version */ + vsprintf(buffer, fmt, ap); + va_end(ap); + + va_start(ap, fmt); + /* use BRL-CAD bu_vls version for comparison */ + bu_vls_vprintf(&vls, fmt, ap); + + va_end(ap); + + snprintf(output, sizeof(output), "%-24s -> '%s'", fmt, bu_vls_addr(&vls)); + if (BU_STR_EQUAL(buffer, bu_vls_addr(&vls)) + && strlen(buffer) == bu_vls_strlen(&vls)) + { + printf("%-*s[PASS]\n", 60, output); + } else { + printf("%-*s[FAIL] (should be: '%s')\n", 60, output, buffer); + status = 1; + } + + bu_vls_free(&vls); + + return status; +} + +int +main(int ac, char *av[]) +{ + int fails = 0; /* track unexpected failures */ + int expfails = 0; /* track expected failures */ + int f = 0; + int p = 0; + const char *word = "Lawyer"; + + printf("Testing vls...\n"); + + /* ======================================================== */ + /* TESTS EXPECTED TO PASS + * + * (see expected failures section below) + */ + /* ======================================================== */ + /* various types */ + printf("An empty string (\"\"):\n"); + fails += test_vls(""); + + printf("A newline (\"\\n\"):\n"); + fails += test_vls("\n"); + + fails += test_vls("hello"); + fails += test_vls("%s", "hello"); + fails += test_vls("%d", 123); + fails += test_vls("%u", -123); + fails += test_vls("%e %E", 1.23, -3.21); + fails += test_vls("%g %G", 1.23, -3.21); + fails += test_vls("%x %X", 1.23, -3.21); + fails += test_vls("%o", 1.23); + fails += test_vls("%c%c%c", '1', '2', '3'); + fails += test_vls("%p", (void *)av); + fails += test_vls("%%%d%%", ac); + + /* various lengths */ + fails += test_vls("%zu %zd", (size_t)123, (ssize_t)-123); + fails += test_vls("%jd %td", (intmax_t)123, (ptrdiff_t)-123); + + /* various widths */ + fails += test_vls("he%*so", 2, "ll"); + fails += test_vls("he%*so", 2, "llll"); + fails += test_vls("he%*so", 4, "ll"); + + /* various precisions */ + fails += test_vls("he%.*so", 2, "ll"); + fails += test_vls("he%.-1-o", 123); + fails += test_vls("%6.-3f", 123); + + /* various flags */ + fails += test_vls("%010d", 123); + fails += test_vls("%#-.10lx", 123); + fails += test_vls("%#lf", 123.0); + + /* two-character length modifiers */ + fails += test_vls("he%10dllo", 123); + fails += test_vls("he%-10ullo", 123); + fails += test_vls("he%#-12.10tullo", (ptrdiff_t)0x1234); + fails += test_vls("he%+-6.3ld%-+3.6dllo", 123, 321); + fails += test_vls("he%.10dllo", 123); + fails += test_vls("he%.-10ullo", 123); + fails += test_vls("%hd %hhd", 123, -123); + + /* combinations, e.g., bug ID 3475562, fixed at rev 48958 */ + /* left justify, right justify, in wider fields than the strings */ + f = p = 2; + fails += test_vls("|%-*.*s|%*.*s|", f, p, "t", f, p, "t"); + fails += test_vls("|%*s|%-*s|", f, "test", f, "test"); + fails += test_vls("|%*s|%-*s|", f, word, f, word); + + /* min field width; max string length ('precision'); string */ + f = 2; p = 4; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%*.*s", f, p, word); + + f = 4; p = 2; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%*.*s", f, p, word); + + f = 4; p = 8; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%*.*s", f, p, word); + + f = 0; p = 8; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%*.*s", f, p, word); + + f = 8; p = 0; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%*.*s", f, p, word); + + /* mged bug at rev 48989 */ + f = 8; p = 0; + printf("fw=%d, '%s': '%%%ds'\n", f, word, f); + fails += test_vls("%*s", f, word); + + /* same but left justify */ + + f = 2; p = 4; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%-*.*s", f, p, word); + + f = 4; p = 2; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%-*.*s", f, p, word); + + f = 4; p = 8; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%-*.*s", f, p, word); + + f = 0; p = 8; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%-*.*s", f, p, word); + + f = 8; p = 0; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + fails += test_vls("%-*.*s", f, p, word); + + /* from "various types" */ + fails += test_vls("%f %F", 1.23, -3.21); + + /* from "two-character length modifiers" */ + fails += test_vls("%ld %lld", 123, -123); + + /* unsigned variant */ + fails += test_vls("%lu %llu", 123, 123); + + /* ======================================================== */ + /* EXPECTED FAILURES ONLY BELOW HERE */ + /* ======================================================== */ + /* EXPECTED FAILURES: + * + * Notes: + * + * 1. For these tests have the return value increment 'expfails'. + * 2. Test with both 'make vsl-regress' and 'make regress' because + * some other tests use this function in unpredictable ways. + * 3. After a test is fixed, change the return value to increment + * 'fails', move it to the EXPECTED PASS group above, and add + * some info about it as necessary to help those who may be + * forced to revisit this. + * + */ + + printf("\nExpected failures (don't use in production code):\n"); + + printf(" NONE AT THIS TIME\n"); + + /* report results */ + fprintf(stderr, "%d", expfails); + + printf("\n%s: testing complete\n", av[0]); + + if (fails != 0) { + /* as long as fails is < 127 the STATUS will be the number of unexpected failures */ + return fails; + } + + return 0; + +} + + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/branches/STABLE/src/libbu/test_vls.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Deleted: brlcad/branches/STABLE/src/libbu/test_vls_vprintf.c =================================================================== --- brlcad/branches/STABLE/src/libbu/test_vls_vprintf.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/test_vls_vprintf.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -1,327 +0,0 @@ -/* T E S T _ V L S _ V P R I N T F. C - * BRL-CAD - * - * Copyright (c) 2011-2012 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ - -#include "common.h" - -#include <stdlib.h> -#include <stdarg.h> -#include <stdio.h> -#include <signal.h> -#include <string.h> -#include <ctype.h> - -#include "bu.h" - -#include "./vls_internals.h" - -/* Test against sprintf */ -int -test_vls(const char *fmt, ...) -{ - int status = 0; /* okay */ - struct bu_vls vls = BU_VLS_INIT_ZERO; - char output[80] = {0}; - char buffer[1024] = {0}; - va_list ap; - - va_start(ap, fmt); - /* use the libc version */ - vsprintf(buffer, fmt, ap); - va_end(ap); - - va_start(ap, fmt); - /* use BRL-CAD bu_vls version for comparison */ - bu_vls_vprintf(&vls, fmt, ap); - va_end(ap); - - snprintf(output, sizeof(output), "%-24s -> '%s'", fmt, bu_vls_addr(&vls)); - if (BU_STR_EQUAL(buffer, bu_vls_addr(&vls)) - && strlen(buffer) == bu_vls_strlen(&vls)) { - printf("%-*s[PASS]\n", 60, output); - } else { - printf("%-*s[FAIL] (should be: '%s')\n", 60, output, buffer); - status = 1; - } - - bu_vls_free(&vls); - - return status; -} - -int -check_format_chars() -{ - int status = 0; /* assume okay */ - int i, flags; - vflags_t f; - - for (i = 0; i < 255; ++i) { - unsigned char c = (unsigned char)i; - if (!isprint(c)) - continue; - flags = format_part_status(c); - if (flags & VP_VALID) { - /* we need a valid part handler */ - int vp_part = flags & VP_PARTS; - - /* for the moment we only have one such handler */ - if (vp_part ^ VP_LENGTH_MOD) /* same as !(vp_part & VP_LENGTH_MOD) */ - continue; - - if (!handle_format_part(vp_part, &f, c, VP_NOPRINT)) { - /* tell user */ - printf("Unhandled valid char '%c' [FAIL]\n", c); - status = 1; - } - } else if (flags & VP_OBSOLETE) { - /* we need an obsolete part handler */ - if (!handle_obsolete_format_char(c, VP_NOPRINT)) { - /* tell user */ - printf("Unhandled obsolete char '%c' [FAIL]\n", c); - status = 1; - } - } - } - - return status; -} - -int -main(int ac, char *av[]) -{ - int fails = 0; /* track unexpected failures */ - int expfails = 0; /* track expected failures */ - - int f = 0; - int p = 0; - const char *word = "Lawyer"; - - printf("Testing bu_vls_vprintf...\n"); - - /* ======================================================== */ - /* TESTS EXPECTED TO PASS - * - * (see expected failures section below) - */ - /* ======================================================== */ - - /* first check that we handle all known format chars */ - printf("\n"); - printf("Testing format char handlers...\n\n"); - fails += check_format_chars(); - - printf("\n"); - printf("Testing format conversions ...\n\n"); - - /* various types */ - printf("An empty string (\"\"):\n"); - fails += test_vls(""); - - printf("A newline (\"\\n\"):\n"); - fails += test_vls("\n"); - - fails += test_vls("hello"); - fails += test_vls("%s", "hello"); - fails += test_vls("%d", 123); - fails += test_vls("%u", -123); - fails += test_vls("%e %E", 1.23, -3.21); - fails += test_vls("%g %G", 1.23, -3.21); - fails += test_vls("%x %X", 1.23, -3.21); - fails += test_vls("%o", 1.23); - fails += test_vls("%c%c%c", '1', '2', '3'); - fails += test_vls("%p", (void *)av); - fails += test_vls("%%%d%%", ac); - - /* various lengths */ - fails += test_vls("%zu %zd", (size_t)123, (ssize_t)-123); - fails += test_vls("%jd %td", (intmax_t)123, (ptrdiff_t)-123); - - /* various widths */ - fails += test_vls("he%*so", 2, "ll"); - fails += test_vls("he%*so", 2, "llll"); - fails += test_vls("he%*so", 4, "ll"); - - /* various precisions */ - fails += test_vls("he%.*so", 2, "ll"); - fails += test_vls("he%.-1-o", 123); - fails += test_vls("%6.-3f", 123); - - /* various flags */ - fails += test_vls("%010d", 123); - fails += test_vls("%#-.10lx", 123); - fails += test_vls("%#lf", 123.0); - - /* two-character length modifiers */ - fails += test_vls("he%10dllo", 123); - fails += test_vls("he%-10ullo", 123); - fails += test_vls("he%#-12.10tullo", (ptrdiff_t)0x1234); - fails += test_vls("he%+-6.3ld%-+3.6dllo", 123, 321); - fails += test_vls("he%.10dllo", 123); - fails += test_vls("he%.-10ullo", 123); - fails += test_vls("%hd %hhd", 123, -123); - - /* combinations, e.g., bug ID 3475562, fixed at rev 48958 */ - /* left justify, right justify, in wider fields than the strings */ - f = p = 2; - fails += test_vls("|%-*.*s|%*.*s|", f, p, "t", f, p, "t"); - fails += test_vls("|%*s|%-*s|", f, "test", f, "test"); - fails += test_vls("|%*s|%-*s|", f, word, f, word); - - /* min field width; max string length ('precision'); string */ - f = 2; p = 4; - printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%*.*s", f, p, word); - - f = 4; p = 2; - printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%*.*s", f, p, word); - - f = 4; p = 8; - printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%*.*s", f, p, word); - - f = 0; p = 8; - printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%*.*s", f, p, word); - - f = 8; p = 0; - printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%*.*s", f, p, word); - - /* mged bug at rev 48989 */ - f = 8; p = 0; - printf("fw=%d, '%s': '%%%ds'\n", f, word, f); - fails += test_vls("%*s", f, word); - - /* same but left justify */ - - f = 2; p = 4; - printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%-*.*s", f, p, word); - - f = 4; p = 2; - printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%-*.*s", f, p, word); - - f = 4; p = 8; - printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%-*.*s", f, p, word); - - f = 0; p = 8; - printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%-*.*s", f, p, word); - - f = 8; p = 0; - printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); - fails += test_vls("%-*.*s", f, p, word); - - /* from "various types" */ - fails += test_vls("%f %F", 1.23, -3.21); - - /* from "two-character length modifiers" */ - fails += test_vls("%ld %lld", 123, -123LL); - - /* unsigned variant */ - fails += test_vls("%lu %llu", 123, 123ULL); - - /* from "two-character length modifiers" */ - fails += test_vls("%ld %lld", 123, -123); - - /* unsigned variant */ - fails += test_vls("%lu %llu", 123, 123); - - fails += test_vls("%hd %hhd", 123, -123); - - /* misc */ - fails += test_vls("% d % d", 123, -123); - - fails += test_vls("% 05d % d", 123, -123); - - fails += test_vls("%'d", 123000); - - fails += test_vls("%c", 'r'); - - /* obsolete but usable */ -/* - fails += test_vls("%S", (wchar_t *)"hello"); -*/ -/* - fails += test_vls("%qd %qd", 123, -123); -*/ - - /* other */ - - /* ======================================================== */ - /* EXPECTED FAILURES ONLY BELOW HERE */ - /* ======================================================== */ - /* EXPECTED FAILURES: - * - * Notes: - * - * 1. For these tests have the return value increment 'expfails'. - * 2. Test with both 'make vsl-regress' and 'make regress' because - * some other tests use this function in unpredictable ways. - * 3. After a test is fixed, change the return value to increment - * 'fails', move it to the EXPECTED PASS group above, and add - * some info about it as necessary to help those who may be - * forced to revisit this. - * - */ - -/* uncomment if using expected failures */ -/* #define EXP_FAILS */ - - printf("\nExpected failures (don't use in production code):\n"); - -#if defined (EXP_FAILS) - /* obsolete - expected failures */ - expfails += test_vls("%C", 'N'); - expfails += test_vls("%D %D", 123, -123); - expfails += test_vls("%O %O", 123, -123); - expfails += test_vls("%U %U", 123, -123); -#else - printf(" NONE AT THIS TIME\n"); -#endif - - /* report results */ - fprintf(stderr, "%d", expfails); - - - printf("\n%s: testing complete\n", av[0]); - - if (fails != 0) { - /* as long as fails is < 127 the STATUS will be the number of unexpected failures */ - return fails; - } - - return 0; - -} - - -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Modified: brlcad/branches/STABLE/src/libbu/vls.c =================================================================== --- brlcad/branches/STABLE/src/libbu/vls.c 2012-05-30 23:23:30 UTC (rev 50774) +++ brlcad/branches/STABLE/src/libbu/vls.c 2012-05-31 02:11:54 UTC (rev 50775) @@ -34,7 +34,6 @@ #include "bu.h" -#include "./vls_internals.h" /* non-published globals */ extern const char bu_vls_message[]; @@ -45,9 +44,13 @@ /* minimum initial allocation size */ static const unsigned int _VLS_ALLOC_MIN = 32; +/* minimum vls allocation increment size */ +static const size_t _VLS_ALLOC_STEP = 128; + /* minimum vls buffer allocation size */ static const unsigned int _VLS_ALLOC_READ = 4096; + void bu_vls_init(struct bu_vls *vp) { @@ -619,6 +622,7 @@ return endlen; } + void bu_vls_putc(struct bu_vls *vp, int c) { @@ -631,6 +635,7 @@ vp->vls_str[vp->vls_offset + vp->vls_len] = '\0'; /* force null termination */ } + void bu_vls_trimspace(struct bu_vls *vp) { @@ -648,6 +653,521 @@ } void +bu_vls_vprintf(struct bu_vls *vls, const char *fmt, va_list ap) +{ + const char *sp; /* start pointer */ + const char *ep; /* end pointer */ + int len; + +/* flags for fmt specifier attributes */ +/* short (char) length modifiers */ +#define SHORTINT 0x0001 +#define SHHRTINT 0x0002 +/* integer length modifiers */ +#define LONG_INT 0x0004 +#define LLONGINT 0x0008 +/* double length modifiers */ +#define LONGDBLE 0x0010 +/* misc */ +#define FIELDLEN 0x0020 +#define INTMAX_T 0x0040 +#define PTRDIFFT 0x0080 +#define SIZETINT 0x0100 +#define PRECISION 0x0200 + +/* groups */ +#define SHORTINTMODS (SHORTINT & SHHRTINT) +#define LONGINTMODS (LONG_INT & LLONGINT) +#define ALL_INTMODS (SHORTINTMODS & LONGINTMODS) +#define ALL_DOUBLEMODS (LONGDBLE) +#define ALL_LENGTHMODS (ALL_INTMODS & ALL_DOUBLEMODS) + + /* variables reset for each fmt specifier */ + int flags; + int fieldlen = -1; + int left_justify = 0; + int have_dot = 0; + int have_digit = 0; + int precision = 0; + + char buf[BUFSIZ] = {0}; + + struct bu_vls fbuf = BU_VLS_INIT_ZERO; /* % format buffer */ + const char *fbufp = NULL; + + if (UNLIKELY(!vls || !fmt || fmt[0] == '\0')) { + /* nothing to print to or from */ + return; + } + + BU_CK_VLS(vls); + + bu_vls_extend(vls, (unsigned int)_VLS_ALLOC_STEP); + + sp = fmt; + while (*sp) { + /* Initial state: just printing chars */ + fmt = sp; + while (*sp != '%' && *sp) + sp++; + + if (sp != fmt) + bu_vls_strncat(vls, fmt, (size_t)(sp-fmt)); + + if (*sp == '\0') + break; + + /* Saw a percent sign, now need to find end of fmt specifier */ + /* All gets reset for this fmt specifier */ + flags = 0; + fieldlen = -1; + left_justify = 0; + have_dot = 0; + have_digit = 0; + precision = 0; + + ep = sp; + while (*ep) { + ++ep; + if (*ep == ' ' || *ep == '#' || *ep == '+' || *ep == '.' || isdigit(*ep)) { + if (*ep == '.') + have_dot = 1; + if (isdigit(*ep)) { + /* set flag for later error checks */ + have_digit = 1; + } + continue; + } else if (*ep == '-') { + /* the first occurrence before a dot is the + left-justify flag, but the occurrence AFTER a dot is + taken to be zero precision */ + if (have_dot) { + precision = 0; + have_digit = 0; + } else if (have_digit) { + /* FIXME: ERROR condition?: invalid format string + (e.g., '%7.8-f') */ + /* seems as if the man page is indefinite here, + looks like the '-' is passed through and + appears in output */ + ; + } else { + left_justify = 1; + } + } else if (*ep == 'l' || *ep == 'U' || *ep == 'O') { + /* clear all length modifiers first */ + flags ^= ALL_LENGTHMODS; + if (flags & LONG_INT) { + /* 'l' can be doubled, this step recognizes that */ + flags |= LLONGINT; + } else { + /* set the new flag */ + flags |= LONG_INT; + } + } else if (*ep == '*') { + /* the first occurrence is the field width, but the + second occurrence is the precision specifier */ + if (!have_dot) { + fieldlen = va_arg(ap, int); + flags |= FIELDLEN; + } + else { + precision = va_arg(ap, int); + flags |= PRECISION; + } + } else if (*ep == 'h') { + /* clear all length modifiers first */ + flags ^= ALL_LENGTHMODS; + if (flags & SHORTINT) { + /* 'h' can be doubled, this step recognizes that */ + flags |= SHHRTINT; + } else { + /* set the new flag */ + flags |= SHORTINT; + } + } else if (*ep == 'j') { + flags |= INTMAX_T; + } else if (*ep == 't') { + flags |= PTRDIFFT; + } else if (*ep == 'z') { + flags |= SIZETINT; + } else if (*ep == 'L') { + /* a length modifier for doubles */ + /* clear all length modifiers first */ + flags ^= ALL_LENGTHMODS; + /* set the new flag */ + flags |= LONGDBLE; + } else + /* Anything else must be the end of the fmt specifier */ + break; + } + + /* libc left-justifies if there's a '-' char, even if the + * value is already negative so no need to check current value + * of left_justify. + */ + if (fieldlen < 0) { + fieldlen = -fieldlen; + left_justify = 1; + } + + /* Copy off the entire format string */ + len = ep-sp+1; + + /* intentionally avoid bu_strlcpy here since the source field + * may be legitimately truncated. + */ + bu_vls_strncpy(&fbuf, sp, (size_t)len); + fbufp = bu_vls_addr(&fbuf); + +#ifndef HAVE_C99_FORMAT_SPECIFIERS + /* if the format string uses the %z width specifier, we need + * to replace it with something more palatable to this busted + * compiler. + */ + + if (flags & SIZETINT) { + char *fp = fbufp; + while (*fp) { + if (*fp == '%') { + /* found the next format specifier */ + while (*fp) { + fp++; + /* possible characters that can preceed the + * field length character (before the type). + */ + if (isdigit(*fp) + || *fp == '$' + || *fp == '#' + || *fp == '+' + || *fp == '.' + || *fp == '-' + || *fp == '*') + { + continue; + } + if (*fp == 'z') { + /* assume MSVC replacing instances of %z + * with %I (capital i) until we encounter + * anything different. + */ + *fp = 'I'; + } + + break; + } + if (*fp == '\0') { + break; + } + } + fp++; + } + } +#endif + + /* Grab parameter from arg list, and print it */ + switch (*ep) { + case 's': + { + /* variables used to determine final effects of + field length and precision (different for + strings versus numbers) */ + int minfldwid = -1; + int maxstrlen = -1; + + char *str = va_arg(ap, char *); + + /* for strings only */ + /* field length is a minimum size and precision is + max length of string to be printed */ + if (flags & FIELDLEN) { + minfldwid = fieldlen; + } + if (flags & PRECISION) { + maxstrlen = precision; + } + if (str) { + int stringlen = (int)strlen(str); + struct bu_vls tmpstr = BU_VLS_INIT_ZERO; + + /* use a copy of the string */ + bu_vls_strcpy(&tmpstr, str); + + /* handle a non-empty string */ + /* strings may be truncated */ + if (maxstrlen >= 0) { + if (maxstrlen < stringlen) { + /* have to truncate */ + bu_vls_trunc(&tmpstr, maxstrlen); + stringlen = maxstrlen; + } else { + maxstrlen = stringlen; + } + } + minfldwid = minfldwid < maxstrlen ? maxstrlen : minfldwid; + + if (stringlen < minfldwid) { + /* padding spaces needed */ + /* start a temp string to deal with padding */ + struct bu_vls padded = BU_VLS_INIT_ZERO; + int i; + + if (left_justify) { + /* string goes before padding spaces */ + bu_vls_vlscat(&padded, &tmpstr); + } + /* now put in padding spaces in all cases */ + for (i = 0; i < minfldwid - stringlen; ++i) { + bu_vls_putc(&padded, ' '); + } + if (!left_justify) { + /* string follows the padding spaces */ + bu_vls_vlscat(&padded, &tmpstr); + } + /* now we can send the padded string to the tmp string */ + /* have to truncate it to zero length first */ + bu_vls_trunc(&tmpstr, 0); + bu_vls_vlscat(&tmpstr, &padded); + + bu_vls_free(&padded); + } + /* now take string as is */ + bu_vls_vlscat(vls, &tmpstr); + + bu_vls_free(&tmpstr); + } else { + /* handle an empty string */ + /* FIXME: should we trunc to precision if > fieldlen? */ + if (flags & FIELDLEN) { + bu_vls_strncat(vls, "(null)", (size_t)fieldlen); + } else { + bu_vls_strcat(vls, "(null)"); + } + } + } + break; + case 'S': /* XXX - DEPRECATED [7.14] */ + printf("DEVELOPER DEPRECATION NOTICE: Using %%S for string printing is deprecated, use %%V instead\n"); + /* fall through */ + case 'V': + { + struct bu_vls *vp; ... [truncated message content] |