Thread: [brlcad-commits] SF.net SVN: brlcad:[51615] brlcad/trunk/src/libbu/tests
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2012-07-20 02:21:17
|
Revision: 51615 http://brlcad.svn.sourceforge.net/brlcad/?rev=51615&view=rev Author: starseeker Date: 2012-07-20 02:21:10 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Add bu_hex_to_bitv tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_hex_to_bitv.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 01:46:32 UTC (rev 51614) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 02:21:10 UTC (rev 51615) @@ -1,4 +1,5 @@ BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_ctype bu_ctype.c libbu NO_INSTALL LOCAL) @@ -10,9 +11,9 @@ BRLCAD_ADDEXEC(tester_bu_timer bu_timer.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL LOCAL) -############################ -# basename testing # -############################ +############################### +# bu_basename testing # +############################### add_test(bu_basename_empty tester_bu_basename) # tests NULL and "" add_test(bu_basename_sl_usr_sl_dir_sl_file tester_bu_basename "/usr/dir/file") add_test(bu_basename_sl_usr_sl_dir_sl_ tester_bu_basename "/usr/dir/") @@ -35,6 +36,12 @@ add_test(bu_basename_p__p__p_ tester_bu_basename "...") add_test(bu_basename_sp__sp__sp_ tester_bu_basename " ") +################################## +# bu_hex_to_bitv testing # +################################## +add_test(bu_hex_to_bitv_test1 tester_bu_hex_to_bitv "33323130" "0123" 0) +add_test(bu_hex_to_bitv_test2 tester_bu_hex_to_bitv "30" "0" 0) +add_test(bu_hex_to_bitv_error tester_bu_hex_to_bitv "303" "" 1) # Local Variables: # tab-width: 8 Added: brlcad/trunk/src/libbu/tests/bu_hex_to_bitv.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_hex_to_bitv.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_hex_to_bitv.c 2012-07-20 02:21:10 UTC (rev 51615) @@ -0,0 +1,82 @@ +/* B U _ H E X _ T O _ 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" + + +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 1; + } + + 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 +main(int argc , char *argv[]) +{ + int error_code = 0; + int ret; + + if(argc < 4) + return -1; + + sscanf(argv[3], "%d", &error_code); + + ret = test_bu_hex_to_bitv(argv[1], argv[2], error_code); + return !ret; +} + + +/* + * 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/trunk/src/libbu/tests/bu_hex_to_bitv.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 02:33:09
|
Revision: 51616 http://brlcad.svn.sourceforge.net/brlcad/?rev=51616&view=rev Author: starseeker Date: 2012-07-20 02:33:03 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Add bu_bitv_and tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_bitv_and.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 02:21:10 UTC (rev 51615) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 02:33:03 UTC (rev 51616) @@ -1,4 +1,5 @@ BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) @@ -36,6 +37,12 @@ add_test(bu_basename_p__p__p_ tester_bu_basename "...") add_test(bu_basename_sp__sp__sp_ tester_bu_basename " ") +############################### +# bu_bitv_and testing # +############################### +add_test(bu_bitv_and_test1 tester_bu_bitv_and "ffffffff" "00000000" "00000000") +add_test(bu_bitv_and_test2 tester_bu_bitv_and "ab00" "1200" "0200") + ################################## # bu_hex_to_bitv testing # ################################## Added: brlcad/trunk/src/libbu/tests/bu_bitv_and.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv_and.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_bitv_and.c 2012-07-20 02:33:03 UTC (rev 51616) @@ -0,0 +1,86 @@ +/* B U _ B I T V _ A N D . 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" + +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 argc , char *argv[]) +{ + int ret; + + if(argc < 4) + return -1; + + ret = test_bu_bitv_and(argv[1], argv[2], argv[3]); + return !ret; +} + + +/* + * 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/trunk/src/libbu/tests/bu_bitv_and.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 15:26:37
|
Revision: 51619 http://brlcad.svn.sourceforge.net/brlcad/?rev=51619&view=rev Author: starseeker Date: 2012-07-20 15:26:28 +0000 (Fri, 20 Jul 2012) Log Message: ----------- tweak basename test Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_basename.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:19:27 UTC (rev 51618) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:26:28 UTC (rev 51619) @@ -15,7 +15,8 @@ ############################### # bu_basename testing # ############################### -add_test(bu_basename_empty tester_bu_basename) # tests NULL and "" +add_test(bu_basename_null tester_bu_basename) # tests NULL +add_test(bu_basename_empty tester_bu_basename "") add_test(bu_basename_sl_usr_sl_dir_sl_file tester_bu_basename "/usr/dir/file") add_test(bu_basename_sl_usr_sl_dir_sl_ tester_bu_basename "/usr/dir/") add_test(bu_basename_sl_usr_bsl__sl_dir tester_bu_basename "/usr\\\\/dir") Modified: brlcad/trunk/src/libbu/tests/bu_basename.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_basename.c 2012-07-20 15:19:27 UTC (rev 51618) +++ brlcad/trunk/src/libbu/tests/bu_basename.c 2012-07-20 15:26:28 UTC (rev 51619) @@ -69,15 +69,14 @@ int main(int argc, char *argv[]) { - /* If we don't have any args at all, test NULL and "" */ + /* If we don't have any args at all, test NULL */ if (argc == 1) { - automatic_test(""); automatic_test(NULL); } /* If we have something, print it and test it */ if (argc > 1) { - printf("Testing string %s\n", argv[1]); + printf("Testing string \"%s\"\n", argv[1]); automatic_test(argv[1]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 15:37:44
|
Revision: 51620 http://brlcad.svn.sourceforge.net/brlcad/?rev=51620&view=rev Author: starseeker Date: 2012-07-20 15:37:33 +0000 (Fri, 20 Jul 2012) Log Message: ----------- add bu_bitv_or tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_bitv_or.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:26:28 UTC (rev 51619) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:37:33 UTC (rev 51620) @@ -1,5 +1,6 @@ BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) @@ -44,6 +45,13 @@ add_test(bu_bitv_and_test1 tester_bu_bitv_and "ffffffff" "00000000" "00000000") add_test(bu_bitv_and_test2 tester_bu_bitv_and "ab00" "1200" "0200") +############################### +# bu_bitv_or testing # +############################### +add_test(bu_bitv_or_test1 tester_bu_bitv_or "ffffffff" "00000000" "ffffffff") +add_test(bu_bitv_or_test2 tester_bu_bitv_or "ab00" "1200" "bb00") + + ################################## # bu_hex_to_bitv testing # ################################## Added: brlcad/trunk/src/libbu/tests/bu_bitv_or.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv_or.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_bitv_or.c 2012-07-20 15:37:33 UTC (rev 51620) @@ -0,0 +1,88 @@ +/* B U _ B I T V _ O R . 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" + + + +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 +main(int argc , char *argv[]) +{ + int ret; + + if(argc < 4) + return -1; + + ret = test_bu_bitv_or(argv[1], argv[2], argv[3]); + return !ret; +} + + +/* + * 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/trunk/src/libbu/tests/bu_bitv_or.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 15:48:09
|
Revision: 51621 http://brlcad.svn.sourceforge.net/brlcad/?rev=51621&view=rev Author: starseeker Date: 2012-07-20 15:48:00 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Add bu_bitv_to_hex tests (these fail when run with bu_bitv too) Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_bitv_to_hex.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:37:33 UTC (rev 51620) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:48:00 UTC (rev 51621) @@ -1,6 +1,7 @@ -BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_to_hex bu_bitv_to_hex.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) @@ -51,6 +52,11 @@ add_test(bu_bitv_or_test1 tester_bu_bitv_or "ffffffff" "00000000" "ffffffff") add_test(bu_bitv_or_test2 tester_bu_bitv_or "ab00" "1200" "bb00") +################################## +# bu_bitv_to_hex testing # +################################## +add_test(bu_bitv_to_hex_test1 tester_bu_bitv_to_hex "0123" "33323130" 32) +add_test(bu_bitv_to_hex_test2 tester_bu_bitv_to_hex "12" "3231" 16) ################################## # bu_hex_to_bitv testing # Added: brlcad/trunk/src/libbu/tests/bu_bitv_to_hex.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv_to_hex.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_bitv_to_hex.c 2012-07-20 15:48:00 UTC (rev 51621) @@ -0,0 +1,89 @@ +/* B U _ B I T V _ T O _ H E X . 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" + + +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 +main(int argc , char *argv[]) +{ + int length = 0; + int ret; + + if(argc < 4) + return -1; + + sscanf(argv[3], "%d", &length); + + ret = test_bu_bitv_to_hex(argv[1], argv[2], length); + return !ret; +} + + +/* + * 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/trunk/src/libbu/tests/bu_bitv_to_hex.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 16:00:30
|
Revision: 51622 http://brlcad.svn.sourceforge.net/brlcad/?rev=51622&view=rev Author: starseeker Date: 2012-07-20 16:00:19 +0000 (Fri, 20 Jul 2012) Log Message: ----------- add bu_bitv_vls tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_bitv_vls.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 15:48:00 UTC (rev 51621) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 16:00:19 UTC (rev 51622) @@ -2,6 +2,7 @@ BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_to_hex bu_bitv_to_hex.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_vls bu_bitv_vls.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) @@ -40,6 +41,10 @@ add_test(bu_basename_p__p__p_ tester_bu_basename "...") add_test(bu_basename_sp__sp__sp_ tester_bu_basename " ") +# +# ************ bitv.c tests ************* +# + ############################### # bu_bitv_and testing # ############################### @@ -58,6 +63,12 @@ add_test(bu_bitv_to_hex_test1 tester_bu_bitv_to_hex "0123" "33323130" 32) add_test(bu_bitv_to_hex_test2 tester_bu_bitv_to_hex "12" "3231" 16) +################################ +# bu_bitv_vls testing # +################################ +add_test(bu_bitv_vls_test1 tester_bu_bitv_vls "00000000" "() ") +add_test(bu_bitv_vls_test2 tester_bu_bitv_vls "f0f0f0f0" "(4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31) ") + ################################## # bu_hex_to_bitv testing # ################################## Added: brlcad/trunk/src/libbu/tests/bu_bitv_vls.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv_vls.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_bitv_vls.c 2012-07-20 16:00:19 UTC (rev 51622) @@ -0,0 +1,79 @@ +/* B U _ B I T V _ V L S . 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" + + +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 +main(int argc , char *argv[]) +{ + int ret; + + if(argc < 3) + return -1; + + ret = test_bu_bitv_vls(argv[1], argv[2]); + return !ret; +} + + +/* + * 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/trunk/src/libbu/tests/bu_bitv_vls.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-20 16:07:48
|
Revision: 51624 http://brlcad.svn.sourceforge.net/brlcad/?rev=51624&view=rev Author: starseeker Date: 2012-07-20 16:07:37 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Add bu_bitv_shift test Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_bitv_shift.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 16:01:05 UTC (rev 51623) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-20 16:07:37 UTC (rev 51624) @@ -1,6 +1,7 @@ BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) +BRLCAD_ADDEXEC(tester_bu_bitv_shift bu_bitv_shift.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_to_hex bu_bitv_to_hex.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_bitv_vls bu_bitv_vls.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) @@ -58,6 +59,11 @@ add_test(bu_bitv_or_test2 tester_bu_bitv_or "ab00" "1200" "bb00") ################################## +# bu_bitv_shift testing # +################################## +add_test(bu_bitv_shift tester_bu_bitv_shift) + +################################## # bu_bitv_to_hex testing # ################################## add_test(bu_bitv_to_hex_test1 tester_bu_bitv_to_hex "0123" "33323130" 32) Added: brlcad/trunk/src/libbu/tests/bu_bitv_shift.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv_shift.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_bitv_shift.c 2012-07-20 16:07:37 UTC (rev 51624) @@ -0,0 +1,74 @@ +/* B U _ B I T V _ S H I F T . 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 +main(int UNUSED(argc), char **UNUSED(argv)) +{ + int res = 1; + int pass = 1; + + printf("\nTesting bu_bitv_shift..."); + + /*test bu_bitv_shift*/ + res = 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; + } + + return !pass; +} + + +/* + * 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/trunk/src/libbu/tests/bu_bitv_shift.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 12:57:42
|
Revision: 51632 http://brlcad.svn.sourceforge.net/brlcad/?rev=51632&view=rev Author: starseeker Date: 2012-07-23 12:57:32 +0000 (Mon, 23 Jul 2012) Log Message: ----------- reorganize libbu tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Removed Paths: ------------- brlcad/trunk/src/libbu/tests/bu_bitv.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 09:05:20 UTC (rev 51631) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 12:57:32 UTC (rev 51632) @@ -1,11 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_shift bu_bitv_shift.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_to_hex bu_bitv_to_hex.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv_vls bu_bitv_vls.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_bitv bu_bitv.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_ctype bu_ctype.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_dirname bu_dirname.c libbu NO_INSTALL LOCAL) @@ -16,9 +8,14 @@ BRLCAD_ADDEXEC(tester_bu_timer bu_timer.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL LOCAL) +# +# ************ basename.c tests ************* +# + ############################### # bu_basename testing # ############################### +BRLCAD_ADDEXEC(tester_bu_basename bu_basename.c libbu NO_INSTALL LOCAL) add_test(bu_basename_null tester_bu_basename) # tests NULL add_test(bu_basename_empty tester_bu_basename "") add_test(bu_basename_sl_usr_sl_dir_sl_file tester_bu_basename "/usr/dir/file") @@ -49,38 +46,44 @@ ############################### # bu_bitv_and testing # ############################### -add_test(bu_bitv_and_test1 tester_bu_bitv_and "ffffffff" "00000000" "00000000") -add_test(bu_bitv_and_test2 tester_bu_bitv_and "ab00" "1200" "0200") +BRLCAD_ADDEXEC(tester_bu_bitv_and bu_bitv_and.c libbu NO_INSTALL LOCAL) +add_test(bu_bitv_and_test1 tester_bu_bitv_and "ffffffff" "00000000" "00000000") +add_test(bu_bitv_and_test2 tester_bu_bitv_and "ab00" "1200" "0200") ############################### # bu_bitv_or testing # ############################### -add_test(bu_bitv_or_test1 tester_bu_bitv_or "ffffffff" "00000000" "ffffffff") -add_test(bu_bitv_or_test2 tester_bu_bitv_or "ab00" "1200" "bb00") +BRLCAD_ADDEXEC(tester_bu_bitv_or bu_bitv_or.c libbu NO_INSTALL LOCAL) +add_test(bu_bitv_or_test1 tester_bu_bitv_or "ffffffff" "00000000" "ffffffff") +add_test(bu_bitv_or_test2 tester_bu_bitv_or "ab00" "1200" "bb00") ################################## # bu_bitv_shift testing # ################################## -add_test(bu_bitv_shift tester_bu_bitv_shift) +BRLCAD_ADDEXEC(tester_bu_bitv_shift bu_bitv_shift.c libbu NO_INSTALL LOCAL) +add_test(bu_bitv_shift tester_bu_bitv_shift) ################################## # bu_bitv_to_hex testing # ################################## -add_test(bu_bitv_to_hex_test1 tester_bu_bitv_to_hex "0123" "33323130" 32) -add_test(bu_bitv_to_hex_test2 tester_bu_bitv_to_hex "12" "3231" 16) +BRLCAD_ADDEXEC(tester_bu_bitv_to_hex bu_bitv_to_hex.c libbu NO_INSTALL LOCAL) +add_test(bu_bitv_to_hex_test1 tester_bu_bitv_to_hex "0123" "33323130" 32) +add_test(bu_bitv_to_hex_test2 tester_bu_bitv_to_hex "12" "3231" 16) ################################ # bu_bitv_vls testing # ################################ -add_test(bu_bitv_vls_test1 tester_bu_bitv_vls "00000000" "() ") -add_test(bu_bitv_vls_test2 tester_bu_bitv_vls "f0f0f0f0" "(4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31) ") +BRLCAD_ADDEXEC(tester_bu_bitv_vls bu_bitv_vls.c libbu NO_INSTALL LOCAL) +add_test(bu_bitv_vls_test1 tester_bu_bitv_vls "00000000" "() ") +add_test(bu_bitv_vls_test2 tester_bu_bitv_vls "f0f0f0f0" "(4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31) ") ################################## # bu_hex_to_bitv testing # ################################## -add_test(bu_hex_to_bitv_test1 tester_bu_hex_to_bitv "33323130" "0123" 0) -add_test(bu_hex_to_bitv_test2 tester_bu_hex_to_bitv "30" "0" 0) -add_test(bu_hex_to_bitv_error tester_bu_hex_to_bitv "303" "" 1) +BRLCAD_ADDEXEC(tester_bu_hex_to_bitv bu_hex_to_bitv.c libbu NO_INSTALL LOCAL) +add_test(bu_hex_to_bitv_test1 tester_bu_hex_to_bitv "33323130" "0123" 0) +add_test(bu_hex_to_bitv_test2 tester_bu_hex_to_bitv "30" "0" 0) +add_test(bu_hex_to_bitv_error tester_bu_hex_to_bitv "303" "" 1) # Local Variables: # tab-width: 8 Deleted: brlcad/trunk/src/libbu/tests/bu_bitv.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_bitv.c 2012-07-23 09:05:20 UTC (rev 51631) +++ brlcad/trunk/src/libbu/tests/bu_bitv.c 2012-07-23 12:57:32 UTC (rev 51632) @@ -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 - */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 13:14:21
|
Revision: 51633 http://brlcad.svn.sourceforge.net/brlcad/?rev=51633&view=rev Author: starseeker Date: 2012-07-23 13:14:15 +0000 (Mon, 23 Jul 2012) Log Message: ----------- add booleanize tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_booleanize.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 12:57:32 UTC (rev 51632) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:14:15 UTC (rev 51633) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_ctype bu_ctype.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_dirname bu_dirname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_escape bu_escape.c libbu NO_INSTALL LOCAL) @@ -85,6 +84,34 @@ add_test(bu_hex_to_bitv_test2 tester_bu_hex_to_bitv "30" "0" 0) add_test(bu_hex_to_bitv_error tester_bu_hex_to_bitv "303" "" 1) +# +# ************ booleanize.c tests ************* +# + +################################# +# bu_booleanize testing # +################################# +BRLCAD_ADDEXEC(tester_bu_booleanize bu_booleanize.c libbu NO_INSTALL LOCAL) +add_test(bu_booleanize_null tester_bu_booleanize) # tests NULL +add_test(bu_booleanize_empty tester_bu_booleanize "") +add_test(bu_booleanize_n tester_bu_booleanize "n") +add_test(bu_booleanize_nabcd tester_bu_booleanize "nabcd") +add_test(bu_booleanize_N tester_bu_booleanize "N") +add_test(bu_booleanize_Nabcd tester_bu_booleanize "Nabcd") +add_test(bu_booleanize__sp__sp_abcd tester_bu_booleanize " abcd") +add_test(bu_booleanize_0 tester_bu_booleanize "0") +add_test(bu_booleanize_0000 tester_bu_booleanize "0000") +add_test(bu_booleanize__lp_null_rp_ tester_bu_booleanize "(null)") +add_test(bu_booleanize_y tester_bu_booleanize "y") +add_test(bu_booleanize_yabcd tester_bu_booleanize "yabcd") +add_test(bu_booleanize_Y tester_bu_booleanize "Y") +add_test(bu_booleanize_Yabcd tester_bu_booleanize "Yabcd") +add_test(bu_booleanize_1 tester_bu_booleanize "1") +add_test(bu_booleanize_0001 tester_bu_booleanize "0001") +add_test(bu_booleanize_abcd tester_bu_booleanize "abcd") + + + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_booleanize.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_booleanize.c 2012-07-23 12:57:32 UTC (rev 51632) +++ brlcad/trunk/src/libbu/tests/bu_booleanize.c 2012-07-23 13:14:15 UTC (rev 51633) @@ -23,7 +23,7 @@ #include <string.h> -void +int automatic_test(const char *input) { @@ -84,44 +84,29 @@ } else { printf("%24s -> %d (should be: %d) [FAIL]\n", buf_input, res, ans); } + + return check; } -int main(int ac, char *av[]) +int main(int argc, char *argv[]) { - char input[1000] = {0}; + int pass = 0; - /* pre-defined tests */ - printf("Performing pre-defined tests:\n"); - automatic_test(NULL); - automatic_test(""); - automatic_test("n"); - automatic_test("nabcd"); - automatic_test("N"); - automatic_test("Nabcd"); - automatic_test(" abcd"); - automatic_test("0"); - automatic_test("0000"); - automatic_test("(null)"); - automatic_test("y"); - automatic_test("yabcd"); - automatic_test("Y"); - automatic_test("Yabcd"); - automatic_test("1"); - automatic_test("0001"); - automatic_test("abcd"); + if (argc > 2) { + printf("Usage: %s test_string\n", argv[0]); + } - /* 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); + if (argc == 1) { + pass = automatic_test(NULL); + return !pass; } + + if (argc > 1) { + pass = automatic_test(argv[1]); + } - printf("%s: testing complete\n", av[0]); - return 0; + return !pass; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 13:18:32
|
Revision: 51634 http://brlcad.svn.sourceforge.net/brlcad/?rev=51634&view=rev Author: starseeker Date: 2012-07-23 13:18:25 +0000 (Mon, 23 Jul 2012) Log Message: ----------- rename bu_ctype.c Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_str_isprint.c Removed Paths: ------------- brlcad/trunk/src/libbu/tests/bu_ctype.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:14:15 UTC (rev 51633) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:18:25 UTC (rev 51634) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_ctype bu_ctype.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_dirname bu_dirname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_escape bu_escape.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) @@ -110,8 +109,17 @@ add_test(bu_booleanize_0001 tester_bu_booleanize "0001") add_test(bu_booleanize_abcd tester_bu_booleanize "abcd") +# +# ************ ctype.c tests ************* +# +################################## +# bu_str_isprint testing # +################################## +BRLCAD_ADDEXEC(tester_bu_str_isprint bu_str_isprint.c libbu NO_INSTALL LOCAL) + + # Local Variables: # tab-width: 8 # mode: cmake Deleted: brlcad/trunk/src/libbu/tests/bu_ctype.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_ctype.c 2012-07-23 13:14:15 UTC (rev 51633) +++ brlcad/trunk/src/libbu/tests/bu_ctype.c 2012-07-23 13:18:25 UTC (rev 51634) @@ -1,77 +0,0 @@ -/* T E S T _ C T Y P E . C - * BRL-CAD - * - * Copyright (c) 2007-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 <string.h> -#include <ctype.h> - -#include "bu.h" - - -int -test_str_isprint(char *inp , int exp) -{ - int res; - res = bu_str_isprint(inp); - if (res == exp) { - if (res) { - printf("Testing with string : %10s is printable->PASSED!\n", inp); - return 1; - } else { - printf("Given string not printable->PASSED!\n"); - return 1; - } - } else { - printf("Failed\n"); - return 0; - } -} - - -int -main(int UNUSED(ac) , char **UNUSED(av)) -{ - int pass = 1; - - printf("\nStarting Tests For ctype.c....\n"); - - pass *= test_str_isprint("abc", 1); - pass *= test_str_isprint("abc123\n", 0); /* \n is end of line -not printable */ - pass *= test_str_isprint("abc123\\n1!", 1); - pass *= test_str_isprint("123\txyz", 0); /* \t is horizontal tab - not printable */ - pass *= test_str_isprint("#$%\n 748", 0); /* \n is end of line -not printable */ - pass *= test_str_isprint("#$ ab12", 1); - pass *= test_str_isprint("#$^\ry", 0); /* \r is carriage return - not printable */ - - return (1-pass); -} - - -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Copied: brlcad/trunk/src/libbu/tests/bu_str_isprint.c (from rev 51631, brlcad/trunk/src/libbu/tests/bu_ctype.c) =================================================================== --- brlcad/trunk/src/libbu/tests/bu_str_isprint.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_str_isprint.c 2012-07-23 13:18:25 UTC (rev 51634) @@ -0,0 +1,77 @@ +/* T E S T _ C T Y P E . C + * BRL-CAD + * + * Copyright (c) 2007-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 <string.h> +#include <ctype.h> + +#include "bu.h" + + +int +test_str_isprint(char *inp , int exp) +{ + int res; + res = bu_str_isprint(inp); + if (res == exp) { + if (res) { + printf("Testing with string : %10s is printable->PASSED!\n", inp); + return 1; + } else { + printf("Given string not printable->PASSED!\n"); + return 1; + } + } else { + printf("Failed\n"); + return 0; + } +} + + +int +main(int UNUSED(ac) , char **UNUSED(av)) +{ + int pass = 1; + + printf("\nStarting Tests For ctype.c....\n"); + + pass *= test_str_isprint("abc", 1); + pass *= test_str_isprint("abc123\n", 0); /* \n is end of line -not printable */ + pass *= test_str_isprint("abc123\\n1!", 1); + pass *= test_str_isprint("123\txyz", 0); /* \t is horizontal tab - not printable */ + pass *= test_str_isprint("#$%\n 748", 0); /* \n is end of line -not printable */ + pass *= test_str_isprint("#$ ab12", 1); + pass *= test_str_isprint("#$^\ry", 0); /* \r is carriage return - not printable */ + + return (1-pass); +} + + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 13:54:43
|
Revision: 51635 http://brlcad.svn.sourceforge.net/brlcad/?rev=51635&view=rev Author: starseeker Date: 2012-07-23 13:54:32 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add bu_str_isprint tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_str_isprint.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:18:25 UTC (rev 51634) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:54:32 UTC (rev 51635) @@ -116,10 +116,20 @@ ################################## # bu_str_isprint testing # ################################## +# Note - because of the special characters needed in these tests, the strings +# don't work well when fed in from the command line. BRLCAD_ADDEXEC(tester_bu_str_isprint bu_str_isprint.c libbu NO_INSTALL LOCAL) +add_test(bu_str_isprint_basic tester_bu_str_isprint 1) +add_test(bu_str_isprint_eol tester_bu_str_isprint 2) +add_test(bu_str_isprint_double_slash tester_bu_str_isprint 3) +add_test(bu_str_isprint_horiz_tab tester_bu_str_isprint 4) +add_test(bu_str_isprint_non-alphanumeric tester_bu_str_isprint 5) +add_test(bu_str_isprint_eol_non-alphanumeric tester_bu_str_isprint 6) +add_test(bu_str_isprint_carriage_return tester_bu_str_isprint 7) + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_str_isprint.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_str_isprint.c 2012-07-23 13:18:25 UTC (rev 51634) +++ brlcad/trunk/src/libbu/tests/bu_str_isprint.c 2012-07-23 13:54:32 UTC (rev 51635) @@ -48,21 +48,35 @@ int -main(int UNUSED(ac) , char **UNUSED(av)) +main(int argc, char **argv) { - int pass = 1; + int test_num = 0; - printf("\nStarting Tests For ctype.c....\n"); + if (argc < 2) { + printf("Usage: %s test_num\n", argv[0]); + return 1; + } + + sscanf(argv[1], "%d", &test_num); - pass *= test_str_isprint("abc", 1); - pass *= test_str_isprint("abc123\n", 0); /* \n is end of line -not printable */ - pass *= test_str_isprint("abc123\\n1!", 1); - pass *= test_str_isprint("123\txyz", 0); /* \t is horizontal tab - not printable */ - pass *= test_str_isprint("#$%\n 748", 0); /* \n is end of line -not printable */ - pass *= test_str_isprint("#$ ab12", 1); - pass *= test_str_isprint("#$^\ry", 0); /* \r is carriage return - not printable */ + switch (test_num) { + case 1: + return !test_str_isprint("abc", 1); + case 2: + return !test_str_isprint("abc123\n", 0); /* \n is end of line -not printable */ + case 3: + return !test_str_isprint("abc123\\n1!", 1); + case 4: + return !test_str_isprint("123\txyz", 0); /* \t is horizontal tab - not printable */ + case 5: + return !test_str_isprint("#$%\n 748", 0); /* \n is end of line -not printable */ + case 6: + return !test_str_isprint("#$ ab12", 1); + case 7: + return !test_str_isprint("#$^\ry", 0); /* \r is carriage return - not printable */ + } - return (1-pass); + return 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 14:16:59
|
Revision: 51637 http://brlcad.svn.sourceforge.net/brlcad/?rev=51637&view=rev Author: starseeker Date: 2012-07-23 14:16:47 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add bu_dirname tests - failing set seems to match the failures seen in previous testing Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_dirname.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 13:55:25 UTC (rev 51636) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 14:16:47 UTC (rev 51637) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_dirname bu_dirname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_escape bu_escape.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_quote bu_quote.c libbu NO_INSTALL LOCAL) @@ -127,7 +126,36 @@ add_test(bu_str_isprint_eol_non-alphanumeric tester_bu_str_isprint 6) add_test(bu_str_isprint_carriage_return tester_bu_str_isprint 7) +# +# ************ dirname.c tests ************* +# +############################## +# bu_dirname testing # +############################## +BRLCAD_ADDEXEC(tester_bu_dirname bu_dirname.c libbu NO_INSTALL LOCAL) +add_test(bu_dirname__usr_dir_file tester_bu_dirname "/usr/dir/file") +add_test(bu_dirname__usr_dir_ tester_bu_dirname "/usr/dir/") +add_test(bu_dirname__usr__bsl__dir tester_bu_dirname "/usr\\\\/dir") +add_test(bu_dirname__usr_period tester_bu_dirname "/usr/.") +add_test(bu_dirname__usr_ tester_bu_dirname "/usr/") +add_test(bu_dirname__usr tester_bu_dirname "/usr") +add_test(bu_dirname_usr tester_bu_dirname "usr") +add_test(bu_dirname__usr_some_sp_long_file tester_bu_dirname "/usr/some long/file") +add_test(bu_dirname__usr_some_sp_file tester_bu_dirname "/usr/some file") +add_test(bu_dirname__usr_some__bsl__sp_drivepath tester_bu_dirname "C:/usr/some\\\\ drivepath") +add_test(bu_dirname__a_sp_test_file tester_bu_dirname "/a test file") +add_test(bu_dirname_another_file tester_bu_dirname "another file") +add_test(bu_dirname_C_colon__bsl_Temp tester_bu_dirname "C:\\\\Temp") +add_test(bu_dirname_C_colon__Temp tester_bu_dirname "C:/Temp") +add_test(bu_dirname__ tester_bu_dirname "/") +add_test(bu_dirname______ tester_bu_dirname "/////") +add_test(bu_dirname__period_ tester_bu_dirname ".") +add_test(bu_dirname__period__period_ tester_bu_dirname "..") +add_test(bu_dirname__period__period__period_ tester_bu_dirname "...") +add_test(bu_dirname__sp__sp__sp_ tester_bu_dirname " ") +add_test(bu_dirname_empty tester_bu_dirname "") +add_test(bu_dirname_null tester_bu_dirname) # Local Variables: Modified: brlcad/trunk/src/libbu/tests/bu_dirname.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_dirname.c 2012-07-23 13:55:25 UTC (rev 51636) +++ brlcad/trunk/src/libbu/tests/bu_dirname.c 2012-07-23 14:16:47 UTC (rev 51637) @@ -31,80 +31,57 @@ /* Test against basename UNIX tool */ -void +int automatic_test(const char *input) { - +#ifdef HAVE_DIRNAME char *ans = NULL; char buf_input[1000]; char *res = NULL; + int pass = 0; if (input) bu_strlcpy(buf_input, input, strlen(input)+1); -#ifdef HAVE_DIRNAME /* build UNIX 'dirname' command */ if (!input) ans = dirname(NULL); else ans = dirname(buf_input); -#endif if (!input) res = bu_dirname(NULL); else res = bu_dirname(buf_input); - if (BU_STR_EQUAL(res, ans)) + if (BU_STR_EQUAL(res, ans)) { printf("%24s -> %24s [PASSED]\n", input, res); - else + pass = 1; + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", input, res, ans); + } bu_free(res, NULL); + return pass; +#else + printf("%s untested - dirname not implemented on this platform\n", input); + return 1; +#endif } int -main(int ac, char *av[]) +main(int argc, char *argv[]) { - char input[1000] = {0}; + if (argc == 1) { + return !automatic_test(NULL); + } - /* pre-define tests */ - printf("Performing pre-defined tests:\n"); - automatic_test("/usr/dir/file"); - automatic_test("/usr/dir/"); - automatic_test("/usr\\/dir"); - automatic_test("/usr/."); - automatic_test("/usr/"); - automatic_test("/usr"); - automatic_test("usr"); - automatic_test("/usr/some long/file"); - automatic_test("/usr/some file"); - automatic_test("C:/usr/some\\ drivepath"); - automatic_test("/a test file"); - automatic_test("another file"); - automatic_test("C:\\Temp"); - automatic_test("C:/Temp"); - automatic_test("/"); - automatic_test("/////"); - automatic_test("."); - automatic_test(".."); - automatic_test("..."); - automatic_test(" "); - automatic_test(""); - automatic_test(NULL); - - /* 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); + if (argc > 2) { + printf("Usage %s test_string\n", argv[0]); } - printf("%s: testing complete\n", av[0]); - return 0; + return !automatic_test(argv[1]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 14:45:21
|
Revision: 51638 http://brlcad.svn.sourceforge.net/brlcad/?rev=51638&view=rev Author: starseeker Date: 2012-07-23 14:45:10 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add escape tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_escape.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 14:16:47 UTC (rev 51637) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 14:45:10 UTC (rev 51638) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_escape bu_escape.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_quote bu_quote.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_sscanf bu_sscanf.c libbu NO_INSTALL LOCAL) @@ -157,7 +156,85 @@ add_test(bu_dirname_empty tester_bu_dirname "") add_test(bu_dirname_null tester_bu_dirname) +# +# ************ escape.c tests ************* +# +# Note - because of the quoting needed in these tests, it is simpler +# to leave the input strings in the C code. Individual tests are triggered +# by number +BRLCAD_ADDEXEC(tester_bu_escape bu_escape.c libbu NO_INSTALL LOCAL) +################################### +# bu_str_unescape testing # +################################### +add_test(bu_str_unescape_1 tester_bu_escape 1 1) +add_test(bu_str_unescape_2 tester_bu_escape 1 2) +add_test(bu_str_unescape_3 tester_bu_escape 1 3) +add_test(bu_str_unescape_4 tester_bu_escape 1 4) +add_test(bu_str_unescape_5 tester_bu_escape 1 5) +add_test(bu_str_unescape_6 tester_bu_escape 1 6) +add_test(bu_str_unescape_7 tester_bu_escape 1 7) +add_test(bu_str_unescape_8 tester_bu_escape 1 8) +add_test(bu_str_unescape_9 tester_bu_escape 1 9) +add_test(bu_str_unescape_10 tester_bu_escape 1 10) +add_test(bu_str_unescape_11 tester_bu_escape 1 11) +add_test(bu_str_unescape_12 tester_bu_escape 1 12) +add_test(bu_str_unescape_13 tester_bu_escape 1 13) +add_test(bu_str_unescape_14 tester_bu_escape 1 14) +add_test(bu_str_unescape_15 tester_bu_escape 1 15) +add_test(bu_str_unescape_16 tester_bu_escape 1 16) +add_test(bu_str_unescape_17 tester_bu_escape 1 17) +add_test(bu_str_unescape_18 tester_bu_escape 1 18) +add_test(bu_str_unescape_19 tester_bu_escape 1 19) +add_test(bu_str_unescape_20 tester_bu_escape 1 20) +add_test(bu_str_unescape_21 tester_bu_escape 1 21) +add_test(bu_str_unescape_22 tester_bu_escape 1 22) +add_test(bu_str_unescape_23 tester_bu_escape 1 23) + +################################# +# bu_str_escape testing # +################################# +add_test(bu_str_escape_1 tester_bu_escape 2 1) +add_test(bu_str_escape_2 tester_bu_escape 2 2) +add_test(bu_str_escape_3 tester_bu_escape 2 3) +add_test(bu_str_escape_4 tester_bu_escape 2 4) +add_test(bu_str_escape_5 tester_bu_escape 2 5) +add_test(bu_str_escape_6 tester_bu_escape 2 6) +add_test(bu_str_escape_7 tester_bu_escape 2 7) +add_test(bu_str_escape_8 tester_bu_escape 2 8) +add_test(bu_str_escape_9 tester_bu_escape 2 9) +add_test(bu_str_escape_10 tester_bu_escape 2 10) +add_test(bu_str_escape_11 tester_bu_escape 2 11) +add_test(bu_str_escape_12 tester_bu_escape 2 12) +add_test(bu_str_escape_13 tester_bu_escape 2 13) +add_test(bu_str_escape_14 tester_bu_escape 2 14) +add_test(bu_str_escape_15 tester_bu_escape 2 15) +add_test(bu_str_escape_16 tester_bu_escape 2 16) +add_test(bu_str_escape_17 tester_bu_escape 2 17) +add_test(bu_str_escape_18 tester_bu_escape 2 18) +add_test(bu_str_escape_19 tester_bu_escape 2 19) +add_test(bu_str_escape_20 tester_bu_escape 2 20) +add_test(bu_str_escape_21 tester_bu_escape 2 21) +add_test(bu_str_escape_22 tester_bu_escape 2 22) +add_test(bu_str_escape_23 tester_bu_escape 2 23) +add_test(bu_str_escape_24 tester_bu_escape 2 24) +add_test(bu_str_escape_25 tester_bu_escape 2 25) +add_test(bu_str_escape_26 tester_bu_escape 2 26) +add_test(bu_str_escape_27 tester_bu_escape 2 27) +add_test(bu_str_escape_28 tester_bu_escape 2 28) +add_test(bu_str_escape_29 tester_bu_escape 2 29) +add_test(bu_str_escape_30 tester_bu_escape 2 30) +add_test(bu_str_escape_31 tester_bu_escape 2 31) + +############################################## +# escape/unescape round trip testing # +############################################## +add_test(bu_escape_roundtrip_1 tester_bu_escape 3 1) +add_test(bu_escape_roundtrip_2 tester_bu_escape 3 2) +add_test(bu_escape_roundtrip_3 tester_bu_escape 3 3) +add_test(bu_escape_roundtrip_4 tester_bu_escape 3 4) + + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_escape.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_escape.c 2012-07-23 14:16:47 UTC (rev 51637) +++ brlcad/trunk/src/libbu/tests/bu_escape.c 2012-07-23 14:45:10 UTC (rev 51638) @@ -24,14 +24,15 @@ #include "bu.h" - -static void +static int compare(const char *input, const char *output, const char *correct) { if (BU_STR_EQUAL(output, correct)) { printf("%24s -> %28s [PASS]\n", input, output); + return 1; } else { printf("%24s -> %28s [FAIL] (should be '%s')\n", input, output, correct); + return 0; } } @@ -39,94 +40,165 @@ int main(int ac, char *av[]) { + int function_num = 0; + int test_num = 0; char *bufp; char buffer[32]; - if (ac > 1) - printf("Usage: %s\n", av[0]); + if (ac < 3) + printf("Usage: %s function_to_test test_number\n", av[0]); - printf("Testing unescape:\n"); + sscanf(av[1], "%d", &function_num); + sscanf(av[2], "%d", &test_num); + if (function_num == 1) { #define CMP_UNESC(in, out) compare((in), bu_str_unescape((in), buffer, 32), (out)) - CMP_UNESC(NULL, ""); - CMP_UNESC("", ""); - CMP_UNESC(" ", " "); - CMP_UNESC("hello", "hello"); - CMP_UNESC("\"", "\""); - CMP_UNESC("\'", "\'"); - CMP_UNESC("\\", ""); - CMP_UNESC("\\\"", "\""); - CMP_UNESC("\\\\", "\\"); - CMP_UNESC("\"hello\"", "\"hello\""); - CMP_UNESC("\'hello\'", "'hello'"); - CMP_UNESC("\\hello", "hello"); - CMP_UNESC("\\hello\"", "hello\""); - CMP_UNESC("hello\\\\", "hello\\"); - CMP_UNESC("\"hello\'\"", "\"hello'\""); - CMP_UNESC("\"hello\'", "\"hello'"); - CMP_UNESC("\'hello\'", "'hello'"); - CMP_UNESC("\'hello\"", "'hello\""); - CMP_UNESC("\"\"hello\"", "\"\"hello\""); - CMP_UNESC("\'\'hello\'\'", "''hello''"); - CMP_UNESC("\'\"hello\"\'", "'\"hello\"'"); - CMP_UNESC("\"\"hello\"\"", "\"\"hello\"\""); - CMP_UNESC("\\\"\\\"\\\"hello\\", "\"\"\"hello"); + switch (test_num) { + case 1: + return !CMP_UNESC(NULL, ""); + case 2: + return !CMP_UNESC("", ""); + case 3: + return !CMP_UNESC(" ", " "); + case 4: + return !CMP_UNESC("hello", "hello"); + case 5: + return !CMP_UNESC("\"", "\""); + case 6: + return !CMP_UNESC("\'", "\'"); + case 7: + return !CMP_UNESC("\\", ""); + case 8: + return !CMP_UNESC("\\\"", "\""); + case 9: + return !CMP_UNESC("\\\\", "\\"); + case 10: + return !CMP_UNESC("\"hello\"", "\"hello\""); + case 11: + return !CMP_UNESC("\'hello\'", "'hello'"); + case 12: + return !CMP_UNESC("\\hello", "hello"); + case 13: + return !CMP_UNESC("\\hello\"", "hello\""); + case 14: + return !CMP_UNESC("hello\\\\", "hello\\"); + case 15: + return !CMP_UNESC("\"hello\'\"", "\"hello'\""); + case 16: + return !CMP_UNESC("\"hello\'", "\"hello'"); + case 17: + return !CMP_UNESC("\'hello\'", "'hello'"); + case 18: + return !CMP_UNESC("\'hello\"", "'hello\""); + case 19: + return !CMP_UNESC("\"\"hello\"", "\"\"hello\""); + case 20: + return !CMP_UNESC("\'\'hello\'\'", "''hello''"); + case 21: + return !CMP_UNESC("\'\"hello\"\'", "'\"hello\"'"); + case 22: + return !CMP_UNESC("\"\"hello\"\"", "\"\"hello\"\""); + case 23: + return !CMP_UNESC("\\\"\\\"\\\"hello\\", "\"\"\"hello"); + } + return 1; + } - printf("Testing escape:\n"); - + if (function_num == 2) { #define CMP_ESC(in, c, out) compare((in), bu_str_escape((in), (c), buffer, 32), (out)) - CMP_ESC(NULL, NULL, ""); - CMP_ESC(NULL, "", ""); - CMP_ESC("", NULL, ""); - CMP_ESC("", "", ""); - CMP_ESC(" ", "", " "); - CMP_ESC("[ ]", " ", "[\\ ]"); - CMP_ESC("[ ]", " ", "[\\ \\ ]"); - CMP_ESC("h e l l o", " ", "h\\ e\\ l\\ l\\ o"); - CMP_ESC("h\\ ello", " ", "h\\\\ ello"); - CMP_ESC("[]", "\\", "[]"); - CMP_ESC("\\", "\\", "\\\\"); - CMP_ESC("\\\\", "\\", "\\\\\\\\"); - CMP_ESC("\\a\\b", "\\", "\\\\a\\\\b"); - CMP_ESC("abc", "a", "\\abc"); - CMP_ESC("abc", "b", "a\\bc"); - CMP_ESC("abc", "c", "ab\\c"); - CMP_ESC("abc", "ab", "\\a\\bc"); - CMP_ESC("abc", "bc", "a\\b\\c"); - CMP_ESC("abc", "abc", "\\a\\b\\c"); - CMP_ESC("aaa", "bc", "aaa"); - CMP_ESC("aaa", "a", "\\a\\a\\a"); - CMP_ESC("aaa", "aaa", "\\a\\a\\a"); - CMP_ESC("abc", "^a", "a\\b\\c"); - CMP_ESC("abc", "^b", "\\ab\\c"); - CMP_ESC("abc", "^c", "\\a\\bc"); - CMP_ESC("abc", "^ab", "ab\\c"); - CMP_ESC("abc", "^bc", "\\abc"); - CMP_ESC("abc", "^abc", "abc"); - CMP_ESC("aaa", "^bc", "\\a\\a\\a"); - CMP_ESC("aaa", "^a", "aaa"); - CMP_ESC("aaa", "^aaa", "aaa"); + switch (test_num) { + case 1: + return !CMP_ESC(NULL, NULL, ""); + case 2: + return !CMP_ESC(NULL, "", ""); + case 3: + return !CMP_ESC("", NULL, ""); + case 4: + return !CMP_ESC("", "", ""); + case 5: + return !CMP_ESC(" ", "", " "); + case 6: + return !CMP_ESC("[ ]", " ", "[\\ ]"); + case 7: + return !CMP_ESC("[ ]", " ", "[\\ \\ ]"); + case 8: + return !CMP_ESC("h e l l o", " ", "h\\ e\\ l\\ l\\ o"); + case 9: + return !CMP_ESC("h\\ ello", " ", "h\\\\ ello"); + case 10: + return !CMP_ESC("[]", "\\", "[]"); + case 11: + return !CMP_ESC("\\", "\\", "\\\\"); + case 12: + return !CMP_ESC("\\\\", "\\", "\\\\\\\\"); + case 13: + return !CMP_ESC("\\a\\b", "\\", "\\\\a\\\\b"); + case 14: + return !CMP_ESC("abc", "a", "\\abc"); + case 15: + return !CMP_ESC("abc", "b", "a\\bc"); + case 16: + return !CMP_ESC("abc", "c", "ab\\c"); + case 17: + return !CMP_ESC("abc", "ab", "\\a\\bc"); + case 18: + return !CMP_ESC("abc", "bc", "a\\b\\c"); + case 19: + return !CMP_ESC("abc", "abc", "\\a\\b\\c"); + case 20: + return !CMP_ESC("aaa", "bc", "aaa"); + case 21: + return !CMP_ESC("aaa", "a", "\\a\\a\\a"); + case 22: + return !CMP_ESC("aaa", "aaa", "\\a\\a\\a"); + case 23: + return !CMP_ESC("abc", "^a", "a\\b\\c"); + case 24: + return !CMP_ESC("abc", "^b", "\\ab\\c"); + case 25: + return !CMP_ESC("abc", "^c", "\\a\\bc"); + case 26: + return !CMP_ESC("abc", "^ab", "ab\\c"); + case 27: + return !CMP_ESC("abc", "^bc", "\\abc"); + case 28: + return !CMP_ESC("abc", "^abc", "abc"); + case 29: + return !CMP_ESC("aaa", "^bc", "\\a\\a\\a"); + case 30: + return !CMP_ESC("aaa", "^a", "aaa"); + case 31: + return !CMP_ESC("aaa", "^aaa", "aaa"); + } + return 1; + } - printf("Testing escape+unescape:\n"); + if (function_num == 3) { + int pass = 0; + switch (test_num) { + case 1: + bufp = bu_str_unescape(bu_str_escape("abc", "b", buffer, 32), NULL, 0); + pass = compare("abc", bufp, "abc"); + bu_free(bufp, NULL); - bufp = bu_str_unescape(bu_str_escape("abc", "b", buffer, 32), NULL, 0); - compare("abc", bufp, "abc"); - bu_free(bufp, NULL); + case 2: + bufp = bu_str_unescape(bu_str_escape("abc\\cba", "b", buffer, 32), NULL, 0); + pass = compare("abc\\cba", bufp, "abccba"); + bu_free(bufp, NULL); - bufp = bu_str_unescape(bu_str_escape("abc\\cba", "b", buffer, 32), NULL, 0); - compare("abc\\cba", bufp, "abccba"); - bu_free(bufp, NULL); + case 3: + bufp = bu_str_unescape(bu_str_escape("abc\\\\cba", "b", buffer, 32), NULL, 0); + pass = compare("abc\\\\cba", bufp, "abc\\cba"); + bu_free(bufp, NULL); - bufp = bu_str_unescape(bu_str_escape("abc\\\\cba", "b", buffer, 32), NULL, 0); - compare("abc\\\\cba", bufp, "abc\\cba"); - bu_free(bufp, NULL); - - bufp = bu_str_unescape(bu_str_escape("abc\\\\\\c\\ba\\", "b", buffer, 32), NULL, 0); - compare("abc\\\\\\c\\ba\\", bufp, "abc\\c\\ba"); - bu_free(bufp, NULL); - - printf("%s: testing complete\n", av[0]); - return 0; + case 4: + bufp = bu_str_unescape(bu_str_escape("abc\\\\\\c\\ba\\", "b", buffer, 32), NULL, 0); + pass = compare("abc\\\\\\c\\ba\\", bufp, "abc\\c\\ba"); + bu_free(bufp, NULL); + } + return !pass; + } + return 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 15:13:31
|
Revision: 51640 http://brlcad.svn.sourceforge.net/brlcad/?rev=51640&view=rev Author: starseeker Date: 2012-07-23 15:13:21 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add bu_progname test. Failures are the same as before. Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_progname.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 14:54:25 UTC (rev 51639) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 15:13:21 UTC (rev 51640) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_quote bu_quote.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_sscanf bu_sscanf.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_timer bu_timer.c libbu NO_INSTALL LOCAL) @@ -233,7 +232,18 @@ add_test(bu_escape_roundtrip_2 tester_bu_escape 3 2) # "abc\\cba", "b" add_test(bu_escape_roundtrip_3 tester_bu_escape 3 3) # "abc\\\\cba", "b" add_test(bu_escape_roundtrip_4 tester_bu_escape 3 4) # "abc\\\\\\c\\ba\\" +# +# ************ progname.c tests ************* +# +# Note - some of the test conditions for bu_progname require previous +# steps to be performed in the same executable context. Hence, in this +# case, multiple test cases are rolled into a single program execution. +############################### +# bu_progname testing # +############################### +BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) +add_test(bu_progname_tests tester_bu_progname) # Local Variables: # tab-width: 8 Modified: brlcad/trunk/src/libbu/tests/bu_progname.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_progname.c 2012-07-23 14:54:25 UTC (rev 51639) +++ brlcad/trunk/src/libbu/tests/bu_progname.c 2012-07-23 15:13:21 UTC (rev 51640) @@ -30,6 +30,7 @@ int main(int ac, char *av[]) { + int pass = 0; const char *label; const char *ans; const char *res; @@ -47,20 +48,24 @@ res = bu_getprogname(); ans = NULL; - if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) + if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) { printf("%s: %24s -> %24s [PASSED]\n", label, "unset", res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 1: try again unset */ label = "CASE 1"; res = bu_getprogname(); ans = NULL; - if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) + if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) { printf("%s: %24s -> %24s [PASSED]\n", label, "unset#2", res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 2: set NULL, then get */ label = "CASE 2"; @@ -68,10 +73,12 @@ res = bu_getprogname(); ans = NULL; - if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) + if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) { printf("%s: %24s -> %24s [PASSED]\n", label, "NULL", res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 3: set, then get */ label = "CASE 3"; @@ -79,10 +86,12 @@ res = bu_getprogname(); ans = av[0]; - if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) + if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(av[0]))) { printf("%s: %24s -> %24s [PASSED]\n", label, "av[0]", res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 4: set full, then get */ label = "CASE 4"; @@ -90,37 +99,42 @@ res = bu_getprogname(); ans = bu_argv0_full_path(); - if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(ans))) + if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, bu_basename(ans))) { printf("%s: %24s -> %24s [PASSED]\n", label, ans, res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 5: set 2x, then get */ label = "CASE 5"; bu_setprogname(av[0]); - bu_setprogname("monkey_see_monkey_poo"); + bu_setprogname("monkey_see_monkey_do"); res = bu_getprogname(); - ans = "monkey_see_monkey_poo"; + ans = "monkey_see_monkey_do"; - if (BU_STR_EQUAL(res, ans ? ans : "")) + if (BU_STR_EQUAL(res, ans ? ans : "")) { printf("%s: %24s -> %24s [PASSED]\n", label, ans, res); - else + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } /* CASE 5: set 2x full path, then get */ label = "CASE 6"; bu_setprogname(bu_argv0_full_path()); - bu_setprogname("/monkey/see/monkey/poo"); + bu_setprogname("/monkey/see/monkey/do"); res = bu_getprogname(); - ans = "poo"; + ans = "do"; - if (BU_STR_EQUAL(res, ans ? ans : "")) - printf("%s: %24s -> %24s [PASSED]\n", label, "/monkey/see/monkey/poo", res); - else + if (BU_STR_EQUAL(res, ans ? ans : "")) { + printf("%s: %24s -> %24s [PASSED]\n", label, "/monkey/see/monkey/do", res); + } else { printf("%24s -> %24s (should be: %s) [FAIL]\n", label, res, ans); + pass++; + } - printf("%s: testing complete\n", av[0]); - return 0; + return pass; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 15:32:36
|
Revision: 51641 http://brlcad.svn.sourceforge.net/brlcad/?rev=51641&view=rev Author: starseeker Date: 2012-07-23 15:32:26 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add quote tests - failures match previous failures. Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_quote.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 15:13:21 UTC (rev 51640) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 15:32:26 UTC (rev 51641) @@ -1,4 +1,3 @@ -BRLCAD_ADDEXEC(tester_bu_quote bu_quote.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_sscanf bu_sscanf.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_timer bu_timer.c libbu NO_INSTALL LOCAL) BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL LOCAL) @@ -232,6 +231,7 @@ add_test(bu_escape_roundtrip_2 tester_bu_escape 3 2) # "abc\\cba", "b" add_test(bu_escape_roundtrip_3 tester_bu_escape 3 3) # "abc\\\\cba", "b" add_test(bu_escape_roundtrip_4 tester_bu_escape 3 4) # "abc\\\\\\c\\ba\\" + # # ************ progname.c tests ************* # @@ -245,6 +245,38 @@ BRLCAD_ADDEXEC(tester_bu_progname bu_progname.c libbu NO_INSTALL LOCAL) add_test(bu_progname_tests tester_bu_progname) +# +# ************ quote.c tests ************* +# +# The testing of encoding and de-coding is tested at once in a "round trip" +# approach - the tests below all test both bu_vls_encode and bu_vls_decode. +# Like many string functions using escaped characters the input strings are +# left in C to minimize pass-through errors. +BRLCAD_ADDEXEC(tester_bu_quote bu_quote.c libbu NO_INSTALL LOCAL) +add_test(bu_quote_test_1 tester_bu_quote 1) # NULL +add_test(bu_quote_test_2 tester_bu_quote 2) # "" +add_test(bu_quote_test_3 tester_bu_quote 3) # " " +add_test(bu_quote_test_4 tester_bu_quote 4) # "hello" +add_test(bu_quote_test_5 tester_bu_quote 5) # "\"" +add_test(bu_quote_test_6 tester_bu_quote 6) # "\'" +add_test(bu_quote_test_7 tester_bu_quote 7) # "\\" +add_test(bu_quote_test_8 tester_bu_quote 8) # "\\\"" +add_test(bu_quote_test_9 tester_bu_quote 9) # "\\\\" +add_test(bu_quote_test_10 tester_bu_quote 10) # "\"hello\"" +add_test(bu_quote_test_11 tester_bu_quote 11) # "\'hello\'" +add_test(bu_quote_test_12 tester_bu_quote 12) # "\\hello" +add_test(bu_quote_test_13 tester_bu_quote 13) # "\\hello\"" +add_test(bu_quote_test_14 tester_bu_quote 14) # "hello\\\\" +add_test(bu_quote_test_15 tester_bu_quote 15) # "\"hello\'\"" +add_test(bu_quote_test_16 tester_bu_quote 16) # "\"hello\'" +add_test(bu_quote_test_17 tester_bu_quote 17) # "\'hello\'" +add_test(bu_quote_test_18 tester_bu_quote 18) # "\'hello\"" +add_test(bu_quote_test_19 tester_bu_quote 19) # "\"\"hello\"" +add_test(bu_quote_test_20 tester_bu_quote 20) # "\'\'hello\'\'" +add_test(bu_quote_test_21 tester_bu_quote 21) # "\'\"hello\"\'" +add_test(bu_quote_test_22 tester_bu_quote 22) # "\"\"hello\"\"" +add_test(bu_quote_test_23 tester_bu_quote 23) # "\"\"\"hello\"\"\"" + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_quote.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_quote.c 2012-07-23 15:13:21 UTC (rev 51640) +++ brlcad/trunk/src/libbu/tests/bu_quote.c 2012-07-23 15:32:26 UTC (rev 51641) @@ -84,70 +84,62 @@ int main(int ac, char *av[]) { - int fails = 0; /* track unexpected failures */ - int expfails = 0; /* track expected failures */ + int test_num = 0; + if (ac != 2) + printf("Usage: %s test_number\n", av[0]); - printf("Testing quote\n"); + sscanf(av[1], "%d", &test_num); - if (ac > 1) - printf("Usage: %s\n", av[0]); - - fails += test_quote(NULL); - fails += test_quote(""); - fails += test_quote(" "); - fails += test_quote("hello"); - fails += test_quote("\""); - fails += test_quote("\'"); - fails += test_quote("\\"); - fails += test_quote("\\\""); - fails += test_quote("\\\\"); - fails += test_quote("\"hello\""); - fails += test_quote("\'hello\'"); - fails += test_quote("\\hello"); - fails += test_quote("\\hello\""); - fails += test_quote("hello\\\\"); - fails += test_quote("\"hello\'\""); - fails += test_quote("\"hello\'"); - fails += test_quote("\'hello\'"); - fails += test_quote("\'hello\""); - fails += test_quote("\"\"hello\""); - fails += test_quote("\'\'hello\'\'"); - fails += test_quote("\'\"hello\"\'"); - fails += test_quote("\"\"hello\"\""); - fails += test_quote("\"\"\"hello\"\"\""); - - /* ======================================================== */ - /* 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("%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; + switch (test_num) { + case 1: + return test_quote(NULL); + case 2: + return test_quote(""); + case 3: + return test_quote(" "); + case 4: + return test_quote("hello"); + case 5: + return test_quote("\""); + case 6: + return test_quote("\'"); + case 7: + return test_quote("\\"); + case 8: + return test_quote("\\\""); + case 9: + return test_quote("\\\\"); + case 10: + return test_quote("\"hello\""); + case 11: + return test_quote("\'hello\'"); + case 12: + return test_quote("\\hello"); + case 13: + return test_quote("\\hello\""); + case 14: + return test_quote("hello\\\\"); + case 15: + return test_quote("\"hello\'\""); + case 16: + return test_quote("\"hello\'"); + case 17: + return test_quote("\'hello\'"); + case 18: + return test_quote("\'hello\""); + case 19: + return test_quote("\"\"hello\""); + case 20: + return test_quote("\'\'hello\'\'"); + case 21: + return test_quote("\'\"hello\"\'"); + case 22: + return test_quote("\"\"hello\"\""); + case 23: + return test_quote("\"\"\"hello\"\"\""); } - return 0; + return 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2012-07-23 18:09:34
|
Revision: 51643 http://brlcad.svn.sourceforge.net/brlcad/?rev=51643&view=rev Author: starseeker Date: 2012-07-23 18:09:27 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Add vls_vprintf tests Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_vls_vprintf.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 17:39:27 UTC (rev 51642) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-07-23 18:09:27 UTC (rev 51643) @@ -1,5 +1,4 @@ BRLCAD_ADDEXEC(tester_bu_sscanf bu_sscanf.c libbu NO_INSTALL LOCAL) -BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL LOCAL) # # ************ basename.c tests ************* @@ -282,6 +281,64 @@ BRLCAD_ADDEXEC(tester_bu_timer bu_timer.c libbu NO_INSTALL LOCAL) add_test(bu_gettime_test tester_bu_timer) +# +# ************ vls_vprintf.c tests ************* +# +BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL LOCAL) +add_test(bu_vls_vprintf_test_1 tester_bu_vls_vprintf 1) +add_test(bu_vls_vprintf_test_2 tester_bu_vls_vprintf 2) +add_test(bu_vls_vprintf_test_3 tester_bu_vls_vprintf 3) +add_test(bu_vls_vprintf_test_4 tester_bu_vls_vprintf 4) +add_test(bu_vls_vprintf_test_5 tester_bu_vls_vprintf 5) +add_test(bu_vls_vprintf_test_6 tester_bu_vls_vprintf 6) +add_test(bu_vls_vprintf_test_7 tester_bu_vls_vprintf 7) +add_test(bu_vls_vprintf_test_8 tester_bu_vls_vprintf 8) +add_test(bu_vls_vprintf_test_9 tester_bu_vls_vprintf 9) +add_test(bu_vls_vprintf_test_10 tester_bu_vls_vprintf 10) +add_test(bu_vls_vprintf_test_11 tester_bu_vls_vprintf 11) +add_test(bu_vls_vprintf_test_12 tester_bu_vls_vprintf 12) +add_test(bu_vls_vprintf_test_13 tester_bu_vls_vprintf 13) +add_test(bu_vls_vprintf_test_14 tester_bu_vls_vprintf 14) +add_test(bu_vls_vprintf_test_15 tester_bu_vls_vprintf 15) +add_test(bu_vls_vprintf_test_16 tester_bu_vls_vprintf 16) +add_test(bu_vls_vprintf_test_17 tester_bu_vls_vprintf 17) +add_test(bu_vls_vprintf_test_18 tester_bu_vls_vprintf 18) +add_test(bu_vls_vprintf_test_19 tester_bu_vls_vprintf 19) +add_test(bu_vls_vprintf_test_20 tester_bu_vls_vprintf 20) +add_test(bu_vls_vprintf_test_21 tester_bu_vls_vprintf 21) +add_test(bu_vls_vprintf_test_22 tester_bu_vls_vprintf 22) +add_test(bu_vls_vprintf_test_23 tester_bu_vls_vprintf 23) +add_test(bu_vls_vprintf_test_24 tester_bu_vls_vprintf 24) +add_test(bu_vls_vprintf_test_25 tester_bu_vls_vprintf 25) +add_test(bu_vls_vprintf_test_26 tester_bu_vls_vprintf 26) +add_test(bu_vls_vprintf_test_27 tester_bu_vls_vprintf 27) +add_test(bu_vls_vprintf_test_28 tester_bu_vls_vprintf 28) +add_test(bu_vls_vprintf_test_29 tester_bu_vls_vprintf 29) +add_test(bu_vls_vprintf_test_30 tester_bu_vls_vprintf 30) +add_test(bu_vls_vprintf_test_31 tester_bu_vls_vprintf 31) +add_test(bu_vls_vprintf_test_32 tester_bu_vls_vprintf 32) +add_test(bu_vls_vprintf_test_33 tester_bu_vls_vprintf 33) +add_test(bu_vls_vprintf_test_34 tester_bu_vls_vprintf 34) +add_test(bu_vls_vprintf_test_35 tester_bu_vls_vprintf 35) +add_test(bu_vls_vprintf_test_36 tester_bu_vls_vprintf 36) +add_test(bu_vls_vprintf_test_37 tester_bu_vls_vprintf 37) +add_test(bu_vls_vprintf_test_38 tester_bu_vls_vprintf 38) +add_test(bu_vls_vprintf_test_39 tester_bu_vls_vprintf 39) +add_test(bu_vls_vprintf_test_40 tester_bu_vls_vprintf 40) +add_test(bu_vls_vprintf_test_41 tester_bu_vls_vprintf 41) +add_test(bu_vls_vprintf_test_42 tester_bu_vls_vprintf 42) +add_test(bu_vls_vprintf_test_43 tester_bu_vls_vprintf 43) +add_test(bu_vls_vprintf_test_44 tester_bu_vls_vprintf 44) +add_test(bu_vls_vprintf_test_45 tester_bu_vls_vprintf 45) +add_test(bu_vls_vprintf_test_46 tester_bu_vls_vprintf 46) +add_test(bu_vls_vprintf_test_47 tester_bu_vls_vprintf 47) +add_test(bu_vls_vprintf_test_48 tester_bu_vls_vprintf 48) +add_test(bu_vls_vprintf_test_49 tester_bu_vls_vprintf 49) +add_test(bu_vls_vprintf_test_50 tester_bu_vls_vprintf 50) +add_test(bu_vls_vprintf_test_51 tester_bu_vls_vprintf 51) +add_test(bu_vls_vprintf_test_52 tester_bu_vls_vprintf 52) +add_test(bu_vls_vprintf_test_53 tester_bu_vls_vprintf 53) + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_vls_vprintf.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_vls_vprintf.c 2012-07-23 17:39:27 UTC (rev 51642) +++ brlcad/trunk/src/libbu/tests/bu_vls_vprintf.c 2012-07-23 18:09:27 UTC (rev 51643) @@ -107,220 +107,218 @@ int -main(int ac, char *av[]) +main(int argc, char *argv[]) { - int fails = 0; /* track unexpected failures */ - int expfails = 0; /* track expected failures */ + int test_num = 0; int f = 0; int p = 0; const char *word = "Lawyer"; - printf("Testing bu_vls_vprintf...\n"); + if (argc < 2) { + printf("Usage: %s test_num\n", argv[0]); + return 1; + } - /* ======================================================== */ - /* 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(); + sscanf(argv[1], "%d", &test_num); - printf("\n"); - printf("Testing format conversions ...\n\n"); - /* various types */ - printf("An empty string (\"\"):\n"); - fails += test_vls(""); + switch (test_num) { + case 1: + /* check that we handle all known format chars */ + return check_format_chars(); + case 2: + return test_vls(""); + case 3: + return test_vls("\n"); + case 4: + return test_vls("hello"); + case 5: + return test_vls("%s", "hello"); + case 6: + return test_vls("%d", 123); + case 7: + return test_vls("%u", -123); + case 8: + return test_vls("%e %E", 1.23, -3.21); + case 9: + return test_vls("%g %G", 1.23, -3.21); + case 10: + return test_vls("%x %X", 1.23, -3.21); + case 11: + return test_vls("%x %X", 123, -321); + case 12: + return test_vls("%o", 1.23); + case 13: + return test_vls("%c%c%c", '1', '2', '3'); + case 14: + return test_vls("%p", (void *)argv); + case 15: + return test_vls("%%%d%%", argc); + /* various lengths */ + case 16: + return test_vls("%zu %zd", (size_t)123, (ssize_t)-123); + case 17: + return test_vls("%jd %td", (intmax_t)123, (ptrdiff_t)-123); + /* various widths */ + case 18: + return test_vls("he%*so", 2, "ll"); + case 19: + return test_vls("he%*so", 2, "llll"); + case 20: + return test_vls("he%*so", 4, "ll"); + /* various precisions */ + case 21: + return test_vls("he%.*so", 2, "ll"); + case 22: + return test_vls("he%.-1-o", 123); + case 23: + return test_vls("%6.-3f", 123); + /* various flags */ + case 24: + return test_vls("%010d", 123); + case 25: + return test_vls("%#-.10lx", 123); + case 26: + return test_vls("%#lf", 123.0); + /* two-character length modifiers */ + case 27: + return test_vls("he%10dllo", 123); + case 28: + return test_vls("he%-10ullo", 123); + case 29: + return test_vls("he%#-12.10tullo", (ptrdiff_t)0x1234); + case 30: + return test_vls("he%+-6.3ld%-+3.6dllo", 123, 321); + case 31: + return test_vls("he%.10dllo", 123); + case 32: + return test_vls("he%.-10ullo", 123); + case 33: + return 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 */ + case 34: + f = p = 2; + return test_vls("|%-*.*s|%*.*s|", f, p, "t", f, p, "t"); + case 35: + f = p = 2; + return test_vls("|%*s|%-*s|", f, "test", f, "test"); + case 36: + f = p = 2; + return test_vls("|%*s|%-*s|", f, word, f, word); + /* min field width; max string length ('precision'); string */ + case 37: + f = 2; p = 4; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + return test_vls("%*.*s", f, p, word); + case 38: + f = 4; p = 2; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + return test_vls("%*.*s", f, p, word); + case 39: + f = 4; p = 8; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + return test_vls("%*.*s", f, p, word); + case 40: + f = 0; p = 8; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + return test_vls("%*.*s", f, p, word); + case 41: + f = 8; p = 0; + printf("fw=%d, prec=%d, '%s': '%%%d.%ds'\n", f, p, word, f, p); + return test_vls("%*.*s", f, p, word); + case 42: + /* mged bug at rev 48989 */ + f = 8; p = 0; + printf("fw=%d, '%s': '%%%ds'\n", f, word, f); + return test_vls("%*s", f, word); + /* same but left justify */ + case 43: + f = 2; p = 4; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + return test_vls("%-*.*s", f, p, word); + case 44: + f = 4; p = 2; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + return test_vls("%-*.*s", f, p, word); + case 45: + f = 4; p = 8; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + return test_vls("%-*.*s", f, p, word); + case 46: + f = 0; p = 8; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + return test_vls("%-*.*s", f, p, word); + case 47: + f = 8; p = 0; + printf("fw=%d, prec=%d, '%s': '%%-%d.%ds'\n", f, p, word, f, p); + return test_vls("%-*.*s", f, p, word); + /* from "various types" */ + case 48: + return test_vls("%f %F", 1.23, -3.21); + /* from "two-character length modifiers" */ + case 49: + return test_vls("%ld %lld", 123, -123LL); + /* unsigned variant */ + case 50: + return test_vls("%lu %llu", 123, 123ULL); + /* from "two-character length modifiers" */ + case 51: + return test_vls("%ld %lld", 123, -123); + /* unsigned variant */ + case 52: + return test_vls("%lu %llu", 123, 123); + case 53: + return test_vls("%hd %hhd", 123, -123); + /* misc */ + case 54: + return test_vls("% d % d", 123, -123); + case 55: + return test_vls("% 05d % d", 123, -123); + case 56: + return test_vls("%'d", 123000); + case 57: + return test_vls("%c", 'r'); - printf("A newline (\"\\n\"):\n"); - fails += test_vls("\n"); + /* this test needs a relook + return test_vls("%H", 123); + */ - 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("%x %X", 123, -321); - 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); + /* obsolete but usable */ + /* + test_vls("%S", (wchar_t *)"hello"); + test_vls("%qd %qd", 123, -123); + */ - /* various lengths */ - fails += test_vls("%zu %zd", (size_t)123, (ssize_t)-123); - fails += test_vls("%jd %td", (intmax_t)123, (ptrdiff_t)-123); + /* EXPECTED FAILURES (don't use in production code): + * + * 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. + * + */ - /* 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'); - -/* this test needs a relook - fails += test_vls("%H", 123); -*/ - - /* 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; + /* obsolete - expected failures + case 10000: + return !test_vls("%C", 'N'); + case 10001: + return !test_vls("%D %D", 123, -123); + case 10002: + return !test_vls("%O %O", 123, -123); + case 10003: + return !test_vls("%U %U", 123, -123);a + */ } - return 0; - + return 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ej...@us...> - 2013-08-05 17:23:42
|
Revision: 56587 http://sourceforge.net/p/brlcad/code/56587 Author: ejno Date: 2013-08-05 17:23:39 +0000 (Mon, 05 Aug 2013) Log Message: ----------- add a test of libbu semaphore locking Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_semaphore.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-08-05 16:44:10 UTC (rev 56586) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-08-05 17:23:39 UTC (rev 56587) @@ -300,6 +300,12 @@ add_test(bu_gettime_test tester_bu_timer) # +# ************ bu_semaphore.c tests ************* +# +BRLCAD_ADDEXEC(tester_bu_semaphore bu_semaphore.c libbu NO_INSTALL LOCAL) +add_test(bu_semaphore_test tester_bu_semaphore) + +# # ************ vls_vprintf.c tests ************* # BRLCAD_ADDEXEC(tester_bu_vls_vprintf bu_vls_vprintf.c libbu NO_INSTALL) Added: brlcad/trunk/src/libbu/tests/bu_semaphore.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_semaphore.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_semaphore.c 2013-08-05 17:23:39 UTC (rev 56587) @@ -0,0 +1,192 @@ +/* B U _ S E M A P H O R E . C + * BRL-CAD + * + * Copyright (c) 2013 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. + */ +/** @file bu_semaphore.c + * + * Tests libbu semaphore locking. + * + */ + + +#include "common.h" +#include "bu.h" + + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#include <signal.h> + + +static void +_exit_alarm_handler(int sig) +{ + if (sig == SIGALRM) exit(0); +} + + +int +set_exit_alarm(unsigned seconds) +{ + signal(SIGALRM, _exit_alarm_handler); + alarm(seconds); + return 1; +} + + +#else +#include <windows.h> + + +static void CALLBACK +_exit_alarm_handler(UINT UNUSED(uTimerID), UINT UNUSED(uMsg), DWORD_PTR UNUSED(dwUser), + DWORD_PTR UNUSED(dw1), DWORD_PTR UNUSED(dw2)) +{ + exit(0); +} + + +int +set_exit_alarm(unsigned seconds) +{ + return !!timeSetEvent(seconds*1000, 100, (LPTIMECALLBACK)_exit_alarm_handler, NULL, TIME_ONESHOT); +} + + +#endif + + +const int SEM = BU_SEM_LAST+1; + + +static int +repeat_test(unsigned long reps) +{ + unsigned long i; + + for (i = 0; i < reps; i++) bu_semaphore_init(SEM+1); + for (i = 0; i < reps; i++) bu_semaphore_free(); + + return 1; +} + + + +static int +single_thread_test() +{ + if (!set_exit_alarm(1)) { + bu_log("failed to start alarm; skipping single-thread bu_semaphore test"); + return 1; + } + + bu_semaphore_init(SEM+1); + bu_semaphore_acquire(SEM); + bu_semaphore_acquire(SEM); + bu_semaphore_free(); + + bu_log("single-thread bu_semaphore test failed"); + return 0; +} + + +struct increment_thread_args { int *parallel, *running; unsigned long reps, *counter; }; +static void +increment_thread(int ncpu, genptr_t pargs) +{ + struct increment_thread_args *args = pargs; + unsigned long i; + + (void)ncpu; + + if (*args->running) *args->parallel = 1; + *args->running = 1; + + for (i = 0; i < args->reps; i++) { + bu_semaphore_acquire(SEM); + ++*args->counter; + bu_semaphore_release(SEM); + } + *args->running = 0; +} + + +static int +parallel_test(unsigned long reps) +{ + const int nthreads = bu_avail_cpus(); + + + struct increment_thread_args args; + unsigned long counter = 0, expected = reps*nthreads; + int parallel = 0, running = 0; + args.parallel = ∥ + args.running = &running; + args.reps = reps; + args.counter = &counter; + + bu_semaphore_init(SEM+1); + bu_parallel(increment_thread, nthreads, &args); + bu_semaphore_free(); + + if (counter != expected) { + bu_log("parallel-increment bu_semaphore test failed: counter is %lu, expected %lu\n", counter, expected); + return 0; + } + + if ((nthreads > 1) && !parallel) { + bu_log("parallel-increment bu_semaphore test invalid: threads did not run in parallel\n"); + return 0; + } + + return 1; +} + + +int +main(int argc, char **argv) +{ + const char * const USAGE = "Usage: %s [-n reps]\n"; + + + unsigned long nreps = 10000; + char c; + int success; + + while ((c = bu_getopt(argc, argv, "n:")) != -1) { + switch (c) { + case 'n': nreps = strtoul(bu_optarg, NULL, 0); break; + default: bu_exit(1, USAGE, argv[0]); + } + } + + success = repeat_test(nreps) && parallel_test(nreps); + + return !(success && single_thread_test()); +} + + +/* + * 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/trunk/src/libbu/tests/bu_semaphore.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <j-s...@us...> - 2013-12-21 20:38:01
|
Revision: 59113 http://sourceforge.net/p/brlcad/code/59113 Author: j-schulte Date: 2013-12-21 20:37:59 +0000 (Sat, 21 Dec 2013) Log Message: ----------- add tests for bu_sort Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_sort.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-21 20:05:11 UTC (rev 59112) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-21 20:37:59 UTC (rev 59113) @@ -379,6 +379,12 @@ add_test(bu_vls_vprintf_test_64 tester_bu_vls_vprintf 64) add_test(bu_vls_vprintf_test_65 tester_bu_vls_vprintf 65) +# +# ************ sort.c test ************* +# +BRLCAD_ADDEXEC(tester_bu_sort bu_sort.c libbu NO_INSTALL) +add_test(bu_sort_test_1 tester_bu_sort) + # Local Variables: # tab-width: 8 # mode: cmake Added: brlcad/trunk/src/libbu/tests/bu_sort.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_sort.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_sort.c 2013-12-21 20:37:59 UTC (rev 59113) @@ -0,0 +1,140 @@ +/* B U _ S O R T . C + * BRL-CAD + * + * Copyright (c) 2004-2013 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 "bu.h" +#include "bn.h" +#include "string.h" + + +/* sort from small to big for unsigned int */ +int +comp_1(const void *num1, const void *num2, void *UNUSED(arg)) +{ + return (*((unsigned int *)num1) - *((unsigned int *)num2)); +} + + +/* sort from small to big for fastf_t */ +int +comp_2(const void *num1, const void *num2, void *UNUSED(arg)) +{ + if (*(fastf_t *)num1 > *(fastf_t *)num2) + return 1; + else if ((*(fastf_t *)num1 < *(fastf_t *)num2)) + return -1; + return 0; +} + + +/* sort strings based on ASCII-table */ +int +comp_3(const void *str1, const void *str2, void *UNUSED(arg)) +{ + return strcmp((char *)str1, (char *)str2); +} + + +/* sort fastf_t's by their distance to cmp */ +int +comp_4(const void *num1, const void *num2, void *cmp) +{ + if (abs(*(fastf_t *)num1 - *(fastf_t *)cmp) > abs((*(fastf_t *)num2)- *(fastf_t *)cmp)) + return 1; + else if (abs(*(fastf_t *)num1 - *(fastf_t *)cmp) < abs((*(fastf_t *)num2)- *(fastf_t *)cmp)) + return -1; + return 0; +} + + +int +main() +{ + unsigned int arg_1[6] = {5, 2, 6, -15, 168, 3}; + unsigned int exp_1[6] = {-15, 2, 3, 5, 6, 168}; + unsigned int arg_2[8] = {56, 4, 7, 156, 2, 0, 23, 8}; + unsigned int exp_2[8] = {0, 2, 4, 7, 8, 23, 56, 156}; + fastf_t arg_3[5] = {5.5, 3.8, -5.5, 1, -7}; + fastf_t exp_3[5] = {-7, -5.5, 1, 3.8, 5.5}; + fastf_t arg_4[7] = {7.42, -5.2, -5.9, 7.36, 7.0, 0, 7.36}; + fastf_t exp_4[7] = {-5.9, -5.2, 0, 7.0, 7.36, 7.36, 7.42}; + char arg_5[4][256] = {"Zfg", "ZFg", "azf", "bzf"}; + char exp_5[4][256] = {"ZFg", "Zfg", "azf", "bzf"}; + char arg_6[3][256] = {"test", "BAB", "aab"}; + char exp_6[3][256] = {"BAB", "aab", "test"}; + fastf_t cmp_7 = -2; + fastf_t arg_7[9] = {-3, 7, -9, 34, 33, -34, 0, -12, 6}; + fastf_t exp_7[9] = {-3, 0, -9, 6, 7, -12, -34, 33, 34}; + fastf_t cmp_8 = 3; + fastf_t arg_8[5] = {-5, 23, 5.5, 0, 2}; + fastf_t exp_8[5] = {2, 5.5, 0, -5, 23}; + int i; + + bu_sort(&arg_1, 6, sizeof(int), comp_1, NULL); + for (i = 0; i < 6; i++) + if (arg_1[i] != exp_1[i]) + return 1; + + bu_sort(&arg_2, 8, sizeof(int), comp_1, NULL); + for (i = 0; i < 8; i++) + if (arg_2[i] != exp_2[i]) + return 1; + + bu_sort(&arg_3, 5, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 5; i++) + if (!EQUAL(arg_3[i], exp_3[i])) + return 1; + + bu_sort(&arg_4, 7, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 7; i++) + if (!EQUAL(arg_4[i], exp_4[i])) + return 1; + + bu_sort(&arg_5, 4, sizeof(char[256]), comp_3, NULL); + for (i = 0; i < 4; i++) + if (strcmp(arg_5[i], exp_5[i]) != 0) + return 1; + + bu_sort(&arg_6, 3, sizeof(char[256]), comp_3, NULL); + for (i = 0; i < 3; i++) + if (strcmp(arg_6[i], exp_6[i]) != 0) + return 1; + + bu_sort(&arg_7, 9, sizeof(fastf_t), comp_4, &cmp_7); + for (i = 0; i < 9; i++) + if (!EQUAL(arg_7[i], exp_7[i])) + return 1; + + bu_sort(&arg_8, 5, sizeof(fastf_t), comp_4, &cmp_8); + for (i = 0; i < 5; i++) + if (!EQUAL(arg_8[i], exp_8[i])) + return 1; + 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/trunk/src/libbu/tests/bu_sort.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-csrc \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pet...@us...> - 2013-12-22 16:20:23
|
Revision: 59115 http://sourceforge.net/p/brlcad/code/59115 Author: peter-sa Date: 2013-12-22 16:20:20 +0000 (Sun, 22 Dec 2013) Log Message: ----------- Add unit tests for several libbu VLS functions, from GCI task http://www.google-melange.com/gci/task/view/google/gci2013/5315364418224128 Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_vls.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-22 13:07:38 UTC (rev 59114) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-22 16:20:20 UTC (rev 59115) @@ -380,6 +380,81 @@ add_test(bu_vls_vprintf_test_65 tester_bu_vls_vprintf 65) # +# ************ vls.c tests ************* + +# For tester_bu_vls, the input format is as follows: +# +# tester_bu_vls <function number> <args> +BRLCAD_ADDEXEC(tester_bu_vls bu_vls.c libbu NO_INSTALL) + +# For function #1 (bu_vls_init) there are no arguments +add_test(bu_vls_init tester_bu_vls 1) + +# For function #2 (bu_vls_vlsinit) there are no arguments +add_test(bu_vls_vlsinit tester_bu_vls 2) + +# For function #3 (bu_vls_strcpy/bu_vls_addr) the <args> format is as follows: +# +# string_to_test +# +# where string_to_test is a string to be used in testing bu_vls_strcpy/bu_vls_addr. + +add_test(bu_vls_access_1 tester_bu_vls 3 "Test 1 2 3") + +# For function #4 (bu_vls_strdup) the <args> format is as follwos: +# +# string_to_test +# +# where string_to_test is a string to be used in testing bu_vls_strdup. + +add_test(bu_vls_strdup_1 tester_bu_vls 4 "Test 1 2 3") + +# For function #5 (bu_vls_strlen) the <args> format is as follows: +# +# string_to_test +# +# where string_to_test is a string whose length will be checked + +add_test(bu_vls_strlen_1 tester_bu_vls 5 "Test 1 2 3") + +# For function #6 (bu_vls_trunc) the <args> format is as follows: +# +# string_to_test trunc_len expected_result +# +# where string_to_test is the string which will be truncated, and +# trunc_len is the length that will be used for truncation. + +add_test(bu_vls_trunc_1 tester_bu_vls 6 "Test 1 2 3" 6 "Test 1") +add_test(bu_vls_trunc_2 tester_bu_vls 6 "Test 1 2 3" -2 "Test 1 2") + +# For function #7 (bu_vls_trunc2) the <args> format is as follows: +# +# string_to_test trunc_len expected_result +# +# where string_to_test is the string which will be truncated, and +# trunc_len is the length that will be used for truncation. + +add_test(bu_vls_trunc2_1 tester_bu_vls 7 "Test 1 2 3" 6 "Test 1") +add_test(bu_vls_trunc2_2 tester_bu_vls 7 "Test 1 2 3" -2 "Test 1 2 3") + +# For function #8 (bu_vls_nibble) the <args> format is as follows: +# +# string_to_test nibble_len expected_result +# +# where string_to_test is the string which will be nibbled, and +# nibble_len is the length that will be nibbled. + +add_test(bu_vls_nibble_1 tester_bu_vls 8 "Test 1 2 3" 4 " 1 2 3") + +# For function #9 (bu_vls_strcat) the <args> format is as follows: +# +# string1 string2 expected_result +# +# where string1 and string2 will be concatenated. + +add_test(bu_vls_strcat_1 tester_bu_vls_strcat 9 "Test 1" " 2 3" "Test 1 2 3") + +# # ************ sort.c test ************* # BRLCAD_ADDEXEC(tester_bu_sort bu_sort.c libbu NO_INSTALL) Added: brlcad/trunk/src/libbu/tests/bu_vls.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_vls.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_vls.c 2013-12-22 16:20:20 UTC (rev 59115) @@ -0,0 +1,340 @@ +/* B U _ V L S . C + * BRL-CAD + * + * Copyright (c) 1985-2013 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 <stdio.h> +#include <string.h> + +#include "bu.h" + +#include "./vls_internals.h" + +/* This prints out the values of the expected vls and compares it with +the actual vls; it uses the C-style return values of 0 for false and 1 +for true */ +static int compare_vls(struct bu_vls *actual_vls, struct bu_vls *expected_vls) +{ + bu_log("magic: %lu", (unsigned long)expected_vls->vls_magic); + bu_log("str: %s", expected_vls->vls_str); + bu_log("offset: %lu", (unsigned long)expected_vls->vls_offset); + bu_log("len: %lu", (unsigned long)expected_vls->vls_len); + bu_log("max: %lu", (unsigned long)expected_vls->vls_max); + + return (expected_vls->vls_magic == actual_vls->vls_magic + && bu_vls_strcmp(expected_vls, actual_vls) == 0); +} + +static int test_bu_vls_init() +{ + struct bu_vls expected_vls = { BU_VLS_MAGIC, (char *)0, 0, 0, 0 }; + struct bu_vls actual_vls; + + bu_vls_init(&actual_vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !compare_vls(&actual_vls, &expected_vls); +} + +static int test_bu_vls_vlsinit() +{ + struct bu_vls expected_vls = { BU_VLS_MAGIC, (char *)0, 0, 0, 0 }; + struct bu_vls *actual_vls; + int retval; + + actual_vls = bu_vls_vlsinit(); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + retval = !compare_vls(actual_vls, &expected_vls); + + bu_vls_vlsfree(actual_vls); + + return retval; +} + +static int test_bu_vls_access(int argc, char *argv[]) +{ + char *null_expected_string = '\0'; + char *null_actual_string; + + char *set_expected_string; + char *set_actual_addr_string; + struct bu_vls *vls; + int retval; + + if (argc != 3) { + bu_exit(1, "ERROR: input format is string_to_test [%s]\n", argv[0]); + } + + set_expected_string = argv[2]; + + vls = bu_vls_vlsinit(); + + null_actual_string = bu_vls_addr(vls); + bu_vls_strcpy(vls, set_expected_string); + set_actual_addr_string = bu_vls_addr(vls); + + printf("Actual null: %s\n", null_actual_string); + printf("Actual addr_string (set): %s\n", set_actual_addr_string); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + retval = !(bu_strcmp(null_actual_string, null_expected_string) == 0 + && bu_strcmp(set_actual_addr_string, set_expected_string) == 0); + + bu_vls_vlsfree(vls); + + return retval; +} + +static int test_bu_vls_strdup(int argc, char *argv[]) +{ + char *set_expected_string; + char *set_actual_strdup_string; + struct bu_vls *vls; + int retval; + + if (argc != 3) { + bu_exit(1, "ERROR: input format is string_to_test [%s]\n", argv[0]); + } + + set_expected_string = argv[2]; + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, set_expected_string); + set_actual_strdup_string = bu_vls_strdup(vls); + + printf("Actual strdup_string (before free): %s\n", set_actual_strdup_string); + retval = bu_strcmp(set_actual_strdup_string, set_expected_string) == 0; + + bu_vls_vlsfree(vls); + printf("Actual strdup_string (after free): %s\n", set_actual_strdup_string); + retval = retval && bu_strcmp(set_actual_strdup_string, set_expected_string) == 0; + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !retval; +} + +static int test_bu_vls_strlen(int argc, char *argv[]) +{ + char *string; + int expected_length; + int actual_length; + struct bu_vls *vls; + + if (argc != 3) { + bu_exit(1, "ERROR: input format is string_to_test [%s]\n", argv[0]); + } + + string = argv[2]; + expected_length = strlen(string); + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, string); + actual_length = bu_vls_strlen(vls); + + bu_vls_vlsfree(vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !(expected_length == actual_length); +} + +static int test_bu_vls_trunc(int argc, char *argv[]) +{ + char *in_string; + int trunc_len; + char *expected_out_string; + char *actual_out_string; + struct bu_vls *vls; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string_to_test trunc_len expected_result[%s]\n", argv[0]); + } + + in_string = argv[2]; + sscanf(argv[3], "%d", &trunc_len); + expected_out_string = argv[4]; + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, in_string); + bu_vls_trunc(vls, trunc_len); + actual_out_string = bu_vls_strdup(vls); + + printf("trunc_len: %d\n", trunc_len); + printf("Result: %s\n", actual_out_string); + + bu_vls_vlsfree(vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +static int test_bu_vls_trunc2(int argc, char *argv[]) +{ + char *in_string; + int trunc_len; + char *expected_out_string; + char *actual_out_string; + struct bu_vls *vls; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string_to_test trunc_len expected_result[%s]\n", argv[0]); + } + + in_string = argv[2]; + sscanf(argv[3], "%d", &trunc_len); + expected_out_string = argv[4]; + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, in_string); + bu_vls_trunc2(vls, trunc_len); + actual_out_string = bu_vls_strdup(vls); + + printf("Result: %s\n", actual_out_string); + + bu_vls_vlsfree(vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +static int test_bu_vls_nibble(int argc, char *argv[]) +{ + char *in_string; + int nibble_len; + char *expected_out_string; + char *actual_out_string; + struct bu_vls *vls; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string_to_test nibble_len expected_result[%s]\n", argv[0]); + } + + in_string = argv[2]; + sscanf(argv[3], "%d", &nibble_len); + expected_out_string = argv[4]; + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, in_string); + bu_vls_nibble(vls, nibble_len); + actual_out_string = bu_vls_strdup(vls); + + printf("Result: %s\n", actual_out_string); + + bu_vls_vlsfree(vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +static int test_bu_vls_strcat(int argc, char *argv[]) +{ + char *in_string_1; + char *in_string_2; + char *expected_out_string; + char *actual_out_string; + struct bu_vls *vls; + + if (argc!= 5) { + bu_exit(1, "ERROR: input format is string1 string2 expected_result [%s]\n", argv[0]); + } + + in_string_1 = argv[2]; + in_string_2 = argv[3]; + expected_out_string = argv[4]; + + vls = bu_vls_vlsinit(); + + bu_vls_strcpy(vls, in_string_1); + bu_vls_strcat(vls, in_string_2); + actual_out_string = bu_vls_strdup(vls); + + printf("Result: %s\n", actual_out_string); + + bu_vls_vlsfree(vls); + + /* These functions need to return sh-style return values where + non-zero is false and zero is true */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +int +main(int argc, char *argv[]) +{ + int function_num = 0; + + if (argc < 2) { + bu_exit(1, "ERROR: input format is function_num function_test_args [%s]\n", argv[0]); + } + + sscanf(argv[1], "%d", &function_num); + + switch (function_num) { + case 1: + /* We don't need any arguments here, as there is only one + thing that bu_vls_init can do */ + return test_bu_vls_init(); + case 2: + /* We don't need any arguments here, as there is only one + thing that bu_vls_init can do */ + return test_bu_vls_vlsinit(); + case 3: + return test_bu_vls_access(argc, argv); + case 4: + return test_bu_vls_strdup(argc, argv); + case 5: + return test_bu_vls_strlen(argc, argv); + case 6: + return test_bu_vls_trunc(argc, argv); + case 7: + return test_bu_vls_trunc2(argc, argv); + case 8: + return test_bu_vls_nibble(argc, argv); + case 9: + return test_bu_vls_strcat(argc, argv); + } + + bu_log("ERROR: function_num %d is not valid [%s]\n", function_num, argv[0]); + return 1; +} + + +/* + * 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/trunk/src/libbu/tests/bu_vls.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <j-s...@us...> - 2013-12-22 18:53:18
|
Revision: 59120 http://sourceforge.net/p/brlcad/code/59120 Author: j-schulte Date: 2013-12-22 18:53:14 +0000 (Sun, 22 Dec 2013) Log Message: ----------- improve r59113 Revision Links: -------------- http://sourceforge.net/p/brlcad/code/59113 Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_sort.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-22 18:18:18 UTC (rev 59119) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-22 18:53:14 UTC (rev 59120) @@ -458,8 +458,19 @@ # ************ sort.c test ************* # BRLCAD_ADDEXEC(tester_bu_sort bu_sort.c libbu NO_INSTALL) -add_test(bu_sort_test_1 tester_bu_sort) +add_test(bu_sort_test_unsigned_int_1 tester_bu_sort 1) +add_test(bu_sort_test_unsigned_int_2 tester_bu_sort 2) +add_test(bu_sort_test_fastf_t_1 tester_bu_sort 3) +add_test(bu_sort_test_fastf_t_2 tester_bu_sort 4) +add_test(bu_sort_test_string_1 tester_bu_sort 5) +add_test(bu_sort_test_string_2 tester_bu_sort 6) +add_test(bu_sort_test_dist_to_int_1 tester_bu_sort 7) +add_test(bu_sort_test_dist_to_int_2 tester_bu_sort 8) +add_test(bu_sort_test_fastf_empty tester_bu_sort 9) +add_test(bu_sort_test_fastf_inf tester_bu_sort 10) + + # Local Variables: # tab-width: 8 # mode: cmake Modified: brlcad/trunk/src/libbu/tests/bu_sort.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_sort.c 2013-12-22 18:18:18 UTC (rev 59119) +++ brlcad/trunk/src/libbu/tests/bu_sort.c 2013-12-22 18:53:14 UTC (rev 59120) @@ -65,7 +65,7 @@ int -main() +main(int argc, char **argv) { unsigned int arg_1[6] = {5, 2, 6, -15, 168, 3}; unsigned int exp_1[6] = {-15, 2, 3, 5, 6, 168}; @@ -85,47 +85,77 @@ fastf_t cmp_8 = 3; fastf_t arg_8[5] = {-5, 23, 5.5, 0, 2}; fastf_t exp_8[5] = {2, 5.5, 0, -5, 23}; - int i; + fastf_t arg_9[5]; + fastf_t exp_9[5]; + fastf_t arg_10[5] = {INFINITY, 5, 5.2, 0, -INFINITY}; + fastf_t exp_10[5] = {-INFINITY, 0, 5, 5.2, INFINITY}; + int i, function_num; - bu_sort(&arg_1, 6, sizeof(int), comp_1, NULL); - for (i = 0; i < 6; i++) - if (arg_1[i] != exp_1[i]) - return 1; - - bu_sort(&arg_2, 8, sizeof(int), comp_1, NULL); - for (i = 0; i < 8; i++) - if (arg_2[i] != exp_2[i]) - return 1; - - bu_sort(&arg_3, 5, sizeof(fastf_t), comp_2, NULL); - for (i = 0; i < 5; i++) - if (!EQUAL(arg_3[i], exp_3[i])) - return 1; - - bu_sort(&arg_4, 7, sizeof(fastf_t), comp_2, NULL); - for (i = 0; i < 7; i++) - if (!EQUAL(arg_4[i], exp_4[i])) - return 1; - - bu_sort(&arg_5, 4, sizeof(char[256]), comp_3, NULL); - for (i = 0; i < 4; i++) - if (bu_strcmp(arg_5[i], exp_5[i]) != 0) - return 1; - - bu_sort(&arg_6, 3, sizeof(char[256]), comp_3, NULL); - for (i = 0; i < 3; i++) - if (bu_strcmp(arg_6[i], exp_6[i]) != 0) - return 1; - - bu_sort(&arg_7, 9, sizeof(fastf_t), comp_4, &cmp_7); - for (i = 0; i < 9; i++) - if (!EQUAL(arg_7[i], exp_7[i])) - return 1; - - bu_sort(&arg_8, 5, sizeof(fastf_t), comp_4, &cmp_8); - for (i = 0; i < 5; i++) - if (!EQUAL(arg_8[i], exp_8[i])) - return 1; + if (argc != 2) + bu_exit(1, "ERROR: wrong number of parameters"); + sscanf(argv[1], "%d", &function_num); + switch (function_num) { + case 1: + bu_sort(&arg_1, 6, sizeof(int), comp_1, NULL); + for (i = 0; i < 6; i++) + if (arg_1[i] != exp_1[i]) + return 1; + break; + case 2: + bu_sort(&arg_2, 8, sizeof(int), comp_1, NULL); + for (i = 0; i < 8; i++) + if (arg_2[i] != exp_2[i]) + return 1; + break; + case 3: + bu_sort(&arg_3, 5, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 5; i++) + if (!EQUAL(arg_3[i], exp_3[i])) + return 1; + break; + case 4: + bu_sort(&arg_4, 7, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 7; i++) + if (!EQUAL(arg_4[i], exp_4[i])) + return 1; + break; + case 5: + bu_sort(&arg_5, 4, sizeof(char[256]), comp_3, NULL); + for (i = 0; i < 4; i++) + if (strcmp(arg_5[i], exp_5[i]) != 0) + return 1; + break; + case 6: + bu_sort(&arg_6, 3, sizeof(char[256]), comp_3, NULL); + for (i = 0; i < 3; i++) + if (strcmp(arg_6[i], exp_6[i]) != 0) + return 1; + break; + case 7: + bu_sort(&arg_7, 9, sizeof(fastf_t), comp_4, &cmp_7); + for (i = 0; i < 9; i++) + if (!EQUAL(arg_7[i], exp_7[i])) + return 1; + break; + case 8: + bu_sort(&arg_8, 5, sizeof(fastf_t), comp_4, &cmp_8); + for (i = 0; i < 5; i++) + if (!EQUAL(arg_8[i], exp_8[i])) + return 1; + break; + case 9: + bu_sort(&arg_9, 5, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 5; i++) + if (!EQUAL(arg_9[i], exp_9[i])) + return 1; + break; + case 10: + bu_sort(&arg_10, 5, sizeof(fastf_t), comp_2, NULL); + for (i = 0; i < 5; i++) + if ((!EQUAL(arg_10[i], exp_10[i]) && (!isinf(arg_10[i]) || !isinf(exp_10[i]))) || ((exp_10[i] < 0) != (arg_10[i] < 0))) + return 1; + break; + } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pet...@us...> - 2013-12-23 22:02:25
|
Revision: 59136 http://sourceforge.net/p/brlcad/code/59136 Author: peter-sa Date: 2013-12-23 22:02:22 +0000 (Mon, 23 Dec 2013) Log Message: ----------- Add unit tests for several more VLS functions in libbu, from GCI task http://www.google-melange.com/gci/task/view/google/gci2013/5556754465161216 Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt brlcad/trunk/src/libbu/tests/bu_vls.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-23 21:26:19 UTC (rev 59135) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-23 22:02:22 UTC (rev 59136) @@ -401,60 +401,159 @@ add_test(bu_vls_access_1 tester_bu_vls 3 "Test 1 2 3") -# For function #4 (bu_vls_strdup) the <args> format is as follwos: +# For function #4 (bu_vls_strncpy) the <args> format is as follwos: # +# string_orig string_new n expected_result +# +# where string_new will be put into the vls via strncpy() after +# string_new is put in with strcpy(); n is the n given to strncpy() + +add_test(bu_vls_strncpy_1 tester_bu_vls 4 "Test 1" "Test 1 2" 4 "Test") +add_test(bu_vls_strncpy_2 tester_bu_vls 4 "Test 1" "Test 1 2" 8 "Test 1 2") + +# For function #5 (bu_vls_strdup) the <args> format is as follwos: +# # string_to_test # # where string_to_test is a string to be used in testing bu_vls_strdup. -add_test(bu_vls_strdup_1 tester_bu_vls 4 "Test 1 2 3") +add_test(bu_vls_strdup_1 tester_bu_vls 5 "Test 1 2 3") -# For function #5 (bu_vls_strlen) the <args> format is as follows: +# For function #6 (bu_vls_strlen) the <args> format is as follows: # # string_to_test # # where string_to_test is a string whose length will be checked -add_test(bu_vls_strlen_1 tester_bu_vls 5 "Test 1 2 3") +add_test(bu_vls_strlen_1 tester_bu_vls 6 "Test 1 2 3") -# For function #6 (bu_vls_trunc) the <args> format is as follows: +# For function #7 (bu_vls_trunc) the <args> format is as follows: # # string_to_test trunc_len expected_result # # where string_to_test is the string which will be truncated, and # trunc_len is the length that will be used for truncation. -add_test(bu_vls_trunc_1 tester_bu_vls 6 "Test 1 2 3" 6 "Test 1") -add_test(bu_vls_trunc_2 tester_bu_vls 6 "Test 1 2 3" -2 "Test 1 2") +add_test(bu_vls_trunc_1 tester_bu_vls 7 "Test 1 2 3" 6 "Test 1") +add_test(bu_vls_trunc_2 tester_bu_vls 7 "Test 1 2 3" -2 "Test 1 2") -# For function #7 (bu_vls_trunc2) the <args> format is as follows: +# For function #8 (bu_vls_trunc2) the <args> format is as follows: # # string_to_test trunc_len expected_result # # where string_to_test is the string which will be truncated, and # trunc_len is the length that will be used for truncation. -add_test(bu_vls_trunc2_1 tester_bu_vls 7 "Test 1 2 3" 6 "Test 1") -add_test(bu_vls_trunc2_2 tester_bu_vls 7 "Test 1 2 3" -2 "Test 1 2 3") +add_test(bu_vls_trunc2_1 tester_bu_vls 8 "Test 1 2 3" 6 "Test 1") +add_test(bu_vls_trunc2_2 tester_bu_vls 8 "Test 1 2 3" -2 "Test 1 2 3") -# For function #8 (bu_vls_nibble) the <args> format is as follows: +# For function #9 (bu_vls_nibble) the <args> format is as follows: # # string_to_test nibble_len expected_result # # where string_to_test is the string which will be nibbled, and # nibble_len is the length that will be nibbled. -add_test(bu_vls_nibble_1 tester_bu_vls 8 "Test 1 2 3" 4 " 1 2 3") +add_test(bu_vls_nibble_1 tester_bu_vls 9 "Test 1 2 3" 4 " 1 2 3") -# For function #9 (bu_vls_strcat) the <args> format is as follows: +# For function #10 (bu_vls_strcat) the <args> format is as follows: # # string1 string2 expected_result # # where string1 and string2 will be concatenated. -add_test(bu_vls_strcat_1 tester_bu_vls 9 "Test 1" " 2 3" "Test 1 2 3") +add_test(bu_vls_strcat_1 tester_bu_vls 10 "Test 1" " 2 3" "Test 1 2 3") +# For function #11 (bu_vls_strncat) the <args> format is as follows: # +# string1 string2 n expected_result +# +# where string1 and string2 will be concatenated. + +add_test(bu_vls_strncat_1 tester_bu_vls 11 "Test 1" " 2 3" 4 "Test 1 2 3") +add_test(bu_vls_strncat_2 tester_bu_vls 11 "Test 1" " 2 3" 2 "Test 1 2") +# This seems to be failing because a if() statement in strncat thinks +# that 4 is not greater than -4, so len is left at strlen(" 2 3") +add_test(bu_vls_strncat_3 tester_bu_vls 11 "Test 1" " 2 3" -4 "Test 1") + +# For function #12 (bu_vls_vlscat) the <args> format is as follows: +# +# string1 string2 expected_result +# +# where string1 and string2 will be concatenated via bu_vls_vlscat. + +add_test(bu_vls_vlscat_1 tester_bu_vls 12 "Test 1" " 2 3" "Test 1 2 3") + +# For function #13 (bu_vls_strcmp) the <args> format is as follows: +# +# string1 string2 expected_result +# +# where string1 and string2 will be compared via bu_vls_strcmp. + +add_test(bu_vls_strcmp_equal_1 tester_bu_vls 13 "Test 1" "Test 1" 0) +add_test(bu_vls_strcmp_lesser_1 tester_bu_vls 13 "Test 1" "Test 2" -1) +add_test(bu_vls_strcmp_greater_1 tester_bu_vls 13 "Test 1" "Test 0" 1) + +# For function #14 (bu_vls_strcmp) the <args> format is as follows: +# +# string1 string2 expected_result +# +# where string1 and string2 will be concatenated via bu_vls_vlscat. + +add_test(bu_vls_strncmp_equal_1 tester_bu_vls 14 "Test 1" "Test 1" 6 0) +add_test(bu_vls_strncmp_lesser_1 tester_bu_vls 14 "Test 1" "Test 2" 6 -1) +add_test(bu_vls_strncmp_greater_1 tester_bu_vls 14 "Test 1" "Test 0" 6 1) +add_test(bu_vls_strncmp_equal_2 tester_bu_vls 14 "Test 1" "Test 1" 4 0) +add_test(bu_vls_strncmp_equal_3 tester_bu_vls 14 "Test 1" "Test 2" 4 0) +add_test(bu_vls_strncmp_equal_4 tester_bu_vls 14 "Test 1" "Test 0" 4 0) + +# For function #15 (bu_vls_from_argv) the <args> format is as follows: +# +# strings expected_result +# +# where strings will be recreated via bu_vls_from_argv, and the +# recreation will be checked against expected_result + +add_test(bu_vls_from_argv_1 tester_bu_vls 15 Test Test 2 3 4 "Test Test 2 3 4") + +# For function #16 (bu_vls_trimspace) the <args> format is as follows: +# +# string expected_result +# +# where string will have spaces trimmed, and the result will be +# compared with expected_result + +add_test(bu_vls_trimspace_1 tester_bu_vls 16 " Testing1 2 " "Testing1 2") + +# For function #17 (bu_vls_spaces) the <args> format is as follows: +# +# string num_spaces expected_result +# +# where string will have num_spaces appended, and the result will be +# checked against expected_result + +add_test(bu_vls_spaces_1 tester_bu_vls 17 "Testing1 2" 3 "Testing1 2 ") + +# For function #18 (bu_vls_detab) the <args> format is as follows: +# +# string expected_result +# +# where string will have tabs replaced, and the result will be checked +# against expected_result + +add_test(bu_vls_detab_1 tester_bu_vls 18 "Testing 1 2 3" "Testing 1 2 3") + +# For function #19 (bu_vls_prepend) the <args> format is as follows: +# +# string string_to_prepend expected_result +# +# where string_to_prepend will be prepended to string, and the result +# will be checked against expected_result + +add_test(bu_vls_prepend_1 tester_bu_vls 19 "2 3" "Test 1 " "Test 1 2 3") + + +# # ************ sort.c test ************* # BRLCAD_ADDEXEC(tester_bu_sort bu_sort.c libbu NO_INSTALL) Modified: brlcad/trunk/src/libbu/tests/bu_vls.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_vls.c 2013-12-23 21:26:19 UTC (rev 59135) +++ brlcad/trunk/src/libbu/tests/bu_vls.c 2013-12-23 22:02:22 UTC (rev 59136) @@ -29,9 +29,11 @@ #include "./vls_internals.h" /* This prints out the values of the expected vls and compares it with -the actual vls; it uses the C-style return values of 0 for false and 1 -for true */ -static int compare_vls(struct bu_vls *actual_vls, struct bu_vls *expected_vls) + * the actual vls; it uses the C-style return values of 0 for false and 1 + * for true + */ +static int +compare_vls(struct bu_vls *actual_vls, struct bu_vls *expected_vls) { bu_log("magic: %lu", (unsigned long)expected_vls->vls_magic); bu_log("str: %s", expected_vls->vls_str); @@ -43,7 +45,8 @@ && bu_vls_strcmp(expected_vls, actual_vls) == 0); } -static int test_bu_vls_init() +static int +test_bu_vls_init() { struct bu_vls expected_vls = { BU_VLS_MAGIC, (char *)0, 0, 0, 0 }; struct bu_vls actual_vls; @@ -51,11 +54,13 @@ bu_vls_init(&actual_vls); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !compare_vls(&actual_vls, &expected_vls); } -static int test_bu_vls_vlsinit() +static int +test_bu_vls_vlsinit() { struct bu_vls expected_vls = { BU_VLS_MAGIC, (char *)0, 0, 0, 0 }; struct bu_vls *actual_vls; @@ -64,22 +69,24 @@ actual_vls = bu_vls_vlsinit(); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ retval = !compare_vls(actual_vls, &expected_vls); - bu_vls_vlsfree(actual_vls); + bu_vls_free(actual_vls); return retval; } -static int test_bu_vls_access(int argc, char *argv[]) +static int +test_bu_vls_access(int argc, char *argv[]) { char *null_expected_string = '\0'; char *null_actual_string; char *set_expected_string; char *set_actual_addr_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; int retval; if (argc != 3) { @@ -88,30 +95,68 @@ set_expected_string = argv[2]; - vls = bu_vls_vlsinit(); + null_actual_string = bu_vls_addr(&vls); + bu_vls_strcpy(&vls, set_expected_string); + set_actual_addr_string = bu_vls_addr(&vls); - null_actual_string = bu_vls_addr(vls); - bu_vls_strcpy(vls, set_expected_string); - set_actual_addr_string = bu_vls_addr(vls); - printf("Actual null: %s\n", null_actual_string); printf("Actual addr_string (set): %s\n", set_actual_addr_string); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ retval = !(bu_strcmp(null_actual_string, null_expected_string) == 0 && bu_strcmp(set_actual_addr_string, set_expected_string) == 0); - bu_vls_vlsfree(vls); + bu_vls_free(&vls); return retval; } -static int test_bu_vls_strdup(int argc, char *argv[]) +static int +test_bu_vls_strncpy(int argc, char *argv[]) { + char *expected_result_string; + char *actual_result_string; + int actual_result_len; + char *string_orig; + char *string_new; + int n; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 6) { + bu_exit(1, "ERROR: input format is string_orig string_new n expected_result [%s]\n", argv[0]); + } + + string_orig = argv[2]; + string_new = argv[3]; + sscanf(argv[4], "%d", &n); + expected_result_string = argv[5]; + + bu_vls_strcpy(&vls, string_orig); + bu_vls_strncpy(&vls, string_new, n); + + actual_result_string = bu_vls_strdup(&vls); + actual_result_len = bu_vls_strlen(&vls); + + printf("Result: %s\n", actual_result_string); + printf("Result len: %d\n", actual_result_len); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true + */ + return !(bu_strcmp(actual_result_string, expected_result_string) == 0 + && actual_result_len == n); +} + +static int +test_bu_vls_strdup(int argc, char *argv[]) +{ char *set_expected_string; char *set_actual_strdup_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; int retval; if (argc != 3) { @@ -120,29 +165,29 @@ set_expected_string = argv[2]; - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, set_expected_string); + set_actual_strdup_string = bu_vls_strdup(&vls); - bu_vls_strcpy(vls, set_expected_string); - set_actual_strdup_string = bu_vls_strdup(vls); - printf("Actual strdup_string (before free): %s\n", set_actual_strdup_string); retval = bu_strcmp(set_actual_strdup_string, set_expected_string) == 0; - bu_vls_vlsfree(vls); + bu_vls_free(&vls); printf("Actual strdup_string (after free): %s\n", set_actual_strdup_string); retval = retval && bu_strcmp(set_actual_strdup_string, set_expected_string) == 0; /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !retval; } -static int test_bu_vls_strlen(int argc, char *argv[]) +static int +test_bu_vls_strlen(int argc, char *argv[]) { char *string; int expected_length; int actual_length; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; if (argc != 3) { bu_exit(1, "ERROR: input format is string_to_test [%s]\n", argv[0]); @@ -151,25 +196,25 @@ string = argv[2]; expected_length = strlen(string); - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, string); + actual_length = bu_vls_strlen(&vls); - bu_vls_strcpy(vls, string); - actual_length = bu_vls_strlen(vls); + bu_vls_free(&vls); - bu_vls_vlsfree(vls); - /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !(expected_length == actual_length); } -static int test_bu_vls_trunc(int argc, char *argv[]) +static int +test_bu_vls_trunc(int argc, char *argv[]) { char *in_string; int trunc_len; char *expected_out_string; char *actual_out_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; if (argc != 5) { bu_exit(1, "ERROR: input format is string_to_test trunc_len expected_result[%s]\n", argv[0]); @@ -179,29 +224,29 @@ sscanf(argv[3], "%d", &trunc_len); expected_out_string = argv[4]; - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, in_string); + bu_vls_trunc(&vls, trunc_len); + actual_out_string = bu_vls_strdup(&vls); - bu_vls_strcpy(vls, in_string); - bu_vls_trunc(vls, trunc_len); - actual_out_string = bu_vls_strdup(vls); - printf("trunc_len: %d\n", trunc_len); printf("Result: %s\n", actual_out_string); - bu_vls_vlsfree(vls); + bu_vls_free(&vls); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !(bu_strcmp(actual_out_string, expected_out_string) == 0); } -static int test_bu_vls_trunc2(int argc, char *argv[]) +static int +test_bu_vls_trunc2(int argc, char *argv[]) { char *in_string; int trunc_len; char *expected_out_string; char *actual_out_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; if (argc != 5) { bu_exit(1, "ERROR: input format is string_to_test trunc_len expected_result[%s]\n", argv[0]); @@ -211,18 +256,17 @@ sscanf(argv[3], "%d", &trunc_len); expected_out_string = argv[4]; - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, in_string); + bu_vls_trunc2(&vls, trunc_len); + actual_out_string = bu_vls_strdup(&vls); - bu_vls_strcpy(vls, in_string); - bu_vls_trunc2(vls, trunc_len); - actual_out_string = bu_vls_strdup(vls); - printf("Result: %s\n", actual_out_string); - bu_vls_vlsfree(vls); + bu_vls_free(&vls); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !(bu_strcmp(actual_out_string, expected_out_string) == 0); } @@ -232,7 +276,7 @@ int nibble_len; char *expected_out_string; char *actual_out_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; if (argc != 5) { bu_exit(1, "ERROR: input format is string_to_test nibble_len expected_result[%s]\n", argv[0]); @@ -242,18 +286,17 @@ sscanf(argv[3], "%d", &nibble_len); expected_out_string = argv[4]; - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, in_string); + bu_vls_nibble(&vls, nibble_len); + actual_out_string = bu_vls_strdup(&vls); - bu_vls_strcpy(vls, in_string); - bu_vls_nibble(vls, nibble_len); - actual_out_string = bu_vls_strdup(vls); - printf("Result: %s\n", actual_out_string); - bu_vls_vlsfree(vls); + bu_vls_free(&vls); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !(bu_strcmp(actual_out_string, expected_out_string) == 0); } @@ -263,7 +306,7 @@ char *in_string_2; char *expected_out_string; char *actual_out_string; - struct bu_vls *vls; + struct bu_vls vls = BU_VLS_INIT_ZERO; if (argc!= 5) { bu_exit(1, "ERROR: input format is string1 string2 expected_result [%s]\n", argv[0]); @@ -273,21 +316,302 @@ in_string_2 = argv[3]; expected_out_string = argv[4]; - vls = bu_vls_vlsinit(); + bu_vls_strcpy(&vls, in_string_1); + bu_vls_strcat(&vls, in_string_2); + actual_out_string = bu_vls_strdup(&vls); - bu_vls_strcpy(vls, in_string_1); - bu_vls_strcat(vls, in_string_2); - actual_out_string = bu_vls_strdup(vls); + printf("Result: %s\n", actual_out_string); + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true + */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +static int test_bu_vls_strncat(int argc, char *argv[]) +{ + char *in_string_1; + char *in_string_2; + char *expected_out_string; + char *actual_out_string; + int n; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 6) { + bu_exit(1, "ERROR: input format is string1 string2 n expected_result [%s]\n", argv[0]); + } + + in_string_1 = argv[2]; + in_string_2 = argv[3]; + sscanf(argv[4], "%d", &n); + expected_out_string = argv[5]; + + bu_vls_strcpy(&vls, in_string_1); + bu_vls_strncat(&vls, in_string_2, n); + actual_out_string = bu_vls_strdup(&vls); + printf("Result: %s\n", actual_out_string); - bu_vls_vlsfree(vls); + bu_vls_free(&vls); /* These functions need to return sh-style return values where - non-zero is false and zero is true */ + * non-zero is false and zero is true + */ return !(bu_strcmp(actual_out_string, expected_out_string) == 0); } +static int test_bu_vls_vlscat(int argc, char *argv[]) +{ + char *in_string_1; + char *in_string_2; + char *expected_out_string; + char *actual_out_string; + struct bu_vls vls_1 = BU_VLS_INIT_ZERO; + struct bu_vls vls_2 = BU_VLS_INIT_ZERO; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string1 string2 expected_result [%s]\n", argv[0]); + } + + in_string_1 = argv[2]; + in_string_2 = argv[3]; + expected_out_string = argv[4]; + + bu_vls_strcpy(&vls_1, in_string_1); + bu_vls_strcpy(&vls_2, in_string_2); + bu_vls_vlscat(&vls_1, &vls_2); + actual_out_string = bu_vls_strdup(&vls_1); + + printf("Result: %s\n", actual_out_string); + + bu_vls_free(&vls_1); + bu_vls_free(&vls_2); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true + */ + return !(bu_strcmp(actual_out_string, expected_out_string) == 0); +} + +static int test_bu_vls_strcmp(int argc, char *argv[]) +{ + char *in_string_1; + char *in_string_2; + int expected_result; + int actual_result; + struct bu_vls vls_1 = BU_VLS_INIT_ZERO; + struct bu_vls vls_2 = BU_VLS_INIT_ZERO; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string1 string2 expected_result [%s]\n", argv[0]); + } + + in_string_1 = argv[2]; + in_string_2 = argv[3]; + sscanf(argv[4], "%d", &expected_result); + + bu_vls_strcpy(&vls_1, in_string_1); + bu_vls_strcpy(&vls_2, in_string_2); + actual_result = bu_vls_strcmp(&vls_1, &vls_2); + + printf("Result: %d\n", actual_result); + + bu_vls_free(&vls_1); + bu_vls_free(&vls_2); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true; the condition just checks + * that the expected and actual results are on the same side of 0; + * it currently expects expected_result to be on of -1, 0, or + * 1. + */ + return !(abs(actual_result) == expected_result*actual_result); +} + +static int test_bu_vls_strncmp(int argc, char *argv[]) +{ + char *in_string_1; + char *in_string_2; + int n; + int expected_result; + int actual_result; + struct bu_vls vls_1 = BU_VLS_INIT_ZERO; + struct bu_vls vls_2 = BU_VLS_INIT_ZERO; + + if (argc != 6) { + bu_exit(1, "ERROR: input format is string1 string2 n expected_result [%s]\n", argv[0]); + } + + in_string_1 = argv[2]; + in_string_2 = argv[3]; + sscanf(argv[4], "%d", &n); + sscanf(argv[5], "%d", &expected_result); + + bu_vls_strcpy(&vls_1, in_string_1); + bu_vls_strcpy(&vls_2, in_string_2); + actual_result = bu_vls_strncmp(&vls_1, &vls_2, n); + + printf("Result: %d\n", actual_result); + + bu_vls_free(&vls_1); + bu_vls_free(&vls_2); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true; the condition just checks + * that the expected and actual results are on the same side of 0; + * it currently expects expected_result to be on of -1, 0, or + * 1. + */ + return !(abs(actual_result) == expected_result*actual_result); +} + +static int test_bu_vls_from_argv(int argc, char *argv[]) +{ + char *expected_result; + char *actual_result; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc < 4) { + bu_exit(1, "ERROR: input format is strings expected_result [%s]\n", argv[0]); + } + + expected_result = argv[argc-1]; + + bu_vls_from_argv(&vls, argc-3, (const char **)argv+2); + actual_result = bu_vls_strdup(&vls); + + printf("Result: %s\n", actual_result); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true. + */ + return !(bu_strcmp(actual_result, expected_result) == 0); +} + +static int test_bu_vls_trimspace(int argc, char *argv[]) +{ + char *in_string; + char *expected_result; + char *actual_result; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 4) { + bu_exit(1, "ERROR: input format is string expected_result [%s]\n", argv[0]); + } + + in_string = argv[2]; + expected_result = argv[3]; + + bu_vls_strcpy(&vls, in_string); + bu_vls_trimspace(&vls); + + actual_result = bu_vls_strdup(&vls); + + printf("Result: %s\n", actual_result); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true. + */ + return !(bu_strcmp(actual_result, expected_result) == 0); +} + +static int test_bu_vls_spaces(int argc, char *argv[]) +{ + char *in_string; + int num_spaces; + char *expected_result; + char *actual_result; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string num_spaces expected_result [%s]\n", argv[0]); + } + + in_string = argv[2]; + sscanf(argv[3], "%d", &num_spaces); + expected_result = argv[4]; + + bu_vls_strcpy(&vls, in_string); + bu_vls_spaces(&vls, num_spaces); + + actual_result = bu_vls_strdup(&vls); + + printf("Result: %s\n", actual_result); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true. + */ + return !(bu_strcmp(actual_result, expected_result) == 0); +} + +static int test_bu_vls_detab(int argc, char *argv[]) +{ + char *in_string; + char *expected_result; + char *actual_result; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 4) { + bu_exit(1, "ERROR: input format is string expected_result [%s]\n", argv[0]); + } + + in_string = argv[2]; + expected_result = argv[3]; + + bu_vls_strcpy(&vls, in_string); + bu_vls_detab(&vls); + + actual_result = bu_vls_strdup(&vls); + + printf("Result: %s\n", actual_result); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true. + */ + return !(bu_strcmp(actual_result, expected_result) == 0); +} + +static int test_bu_vls_prepend(int argc, char *argv[]) +{ + char *in_string; + char *prepend_string; + char *expected_result; + char *actual_result; + struct bu_vls vls = BU_VLS_INIT_ZERO; + + if (argc != 5) { + bu_exit(1, "ERROR: input format is string string_to_prepend expected_result[%s]\n", argv[0]); + } + + in_string = argv[2]; + prepend_string= argv[3]; + expected_result = argv[4]; + + bu_vls_strcpy(&vls, in_string); + bu_vls_prepend(&vls, prepend_string); + + actual_result = bu_vls_strdup(&vls); + + printf("Result: %s\n", actual_result); + + bu_vls_free(&vls); + + /* These functions need to return sh-style return values where + * non-zero is false and zero is true. + */ + return !(bu_strcmp(actual_result, expected_result) == 0); +} + int main(int argc, char *argv[]) { @@ -302,26 +626,48 @@ switch (function_num) { case 1: /* We don't need any arguments here, as there is only one - thing that bu_vls_init can do */ + * thing that bu_vls_init can do + */ return test_bu_vls_init(); case 2: /* We don't need any arguments here, as there is only one - thing that bu_vls_init can do */ + * thing that bu_vls_init can do + */ return test_bu_vls_vlsinit(); case 3: return test_bu_vls_access(argc, argv); case 4: + return test_bu_vls_strncpy(argc, argv); + case 5: return test_bu_vls_strdup(argc, argv); - case 5: + case 6: return test_bu_vls_strlen(argc, argv); - case 6: + case 7: return test_bu_vls_trunc(argc, argv); - case 7: + case 8: return test_bu_vls_trunc2(argc, argv); - case 8: + case 9: return test_bu_vls_nibble(argc, argv); - case 9: + case 10: return test_bu_vls_strcat(argc, argv); + case 11: + return test_bu_vls_strncat(argc, argv); + case 12: + return test_bu_vls_vlscat(argc, argv); + case 13: + return test_bu_vls_strcmp(argc, argv); + case 14: + return test_bu_vls_strncmp(argc, argv); + case 15: + return test_bu_vls_from_argv(argc, argv); + case 16: + return test_bu_vls_trimspace(argc, argv); + case 17: + return test_bu_vls_spaces(argc, argv); + case 18: + return test_bu_vls_detab(argc, argv); + case 19: + return test_bu_vls_prepend(argc, argv); } bu_log("ERROR: function_num %d is not valid [%s]\n", function_num, argv[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pet...@us...> - 2013-12-29 04:51:10
|
Revision: 59222 http://sourceforge.net/p/brlcad/code/59222 Author: peter-sa Date: 2013-12-29 04:51:05 +0000 (Sun, 29 Dec 2013) Log Message: ----------- Add unit tests for the functions in src/libbu/color.c, from GCI task http://www.google-melange.com/gci/task/view/google/gci2013/5858454442868736 Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_color.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-28 18:27:10 UTC (rev 59221) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-29 04:51:05 UTC (rev 59222) @@ -568,8 +568,54 @@ add_test(bu_sort_test_fastf_empty tester_bu_sort 9) add_test(bu_sort_test_fastf_inf tester_bu_sort 10) +# +# ************ color.c tests ************* +# For tester_bu_color, the input format is as follows: +# +# tester_bu_color <function number> <args> +BRLCAD_ADDEXEC(tester_bu_color bu_color.c libbu NO_INSTALL) +# For function #1 (bu_rgb_to_hsv) the <args> format is as follows: +# +# rgb expected_hsv +# +# Where rgb colors are represented by comma-separated triples of +# integers, and hsv colors are represented by comma-separated triples +# of floats. + +add_test(bu_rgb_to_hsv_1 tester_bu_color 1 192,78,214 290,0.636,0.839) + +# For function #2 (bu_hsv_to_rgb) the <args> format is as follows: +# +# hsv expected_rgb +# +# Where rgb colors are represented by comma-separated triples of +# integers, and hsv colors are represented by comma-separated triples +# of floats. + +add_test(bu_hsv_to_rgb_1 tester_bu_color 2 290,0.636,0.839 192,78,214) + +# For function #3 (bu_str_to_rgb) the <args> format is as follows: +# +# string expected_rgb +# +# Where rgb colors are represented by comma-separated triples of +# integers. + +add_test(bu_str_to_rgb_1 tester_bu_color 3 "#C04ED6" 192,78,214) +add_test(bu_str_to_rgb_2 tester_bu_color 3 "192/78/214" 192,78,214) +add_test(bu_str_to_rgb_3 tester_bu_color 3 "192 78 214" 192,78,214) + +# For function #4 (bu_color_to_rgb_floats) the <args> format is as follows: +# +# rgb_color +# +# Where rgb colors are represented by comma-separated triples of +# integers or floats. + +add_test(bu_color_to_rgb_floats_1 tester_bu_color 4 192,78,214) + # Local Variables: # tab-width: 8 # mode: cmake Added: brlcad/trunk/src/libbu/tests/bu_color.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_color.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_color.c 2013-12-29 04:51:05 UTC (rev 59222) @@ -0,0 +1,189 @@ +/* B U _ C O L O R . C + * BRL-CAD + * + * Copyright (c) 1985-2013 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 <stdio.h> +#include <string.h> + +#include "bu.h" + +#include "vmath.h" + +static int +test_bu_rgb_to_hsv(int argc, char *argv[]) +{ + fastf_t expected_hsv_color[3]; + fastf_t actual_hsv_color[3]; + unsigned int rgb_color[3]; + + if (argc != 4) { + bu_exit(1, "ERROR: input format is rgb_values expected_hsv_values [%s]\n", argv[0]); + } + + sscanf(argv[2], "%u,%u,%u", &rgb_color[RED], &rgb_color[GRN], &rgb_color[BLU]); + sscanf(argv[3], "%lf,%lf,%lf", &expected_hsv_color[HUE], &expected_hsv_color[SAT], &expected_hsv_color[VAL]); + + bu_rgb_to_hsv((unsigned char *)rgb_color, actual_hsv_color); + + printf("Result: %f,%f,%f", actual_hsv_color[HUE], actual_hsv_color[SAT], actual_hsv_color[VAL]); + + return !(EQUAL(expected_hsv_color[HUE], actual_hsv_color[HUE]) + && EQUAL(expected_hsv_color[SAT], actual_hsv_color[SAT]) + && EQUAL(expected_hsv_color[VAL], actual_hsv_color[VAL])); +} + +static int +test_bu_hsv_to_rgb(int argc, char *argv[]) +{ + unsigned int expected_rgb_color[3]; + unsigned char actual_rgb_color[3]; + fastf_t hsv_color[3]; + + if (argc != 4) { + bu_exit(1, "ERROR: input format is hsv_values expected_rgb_values [%s]\n", argv[0]); + } + + sscanf(argv[2], "%lf,%lf,%lf", &hsv_color[HUE], &hsv_color[SAT], &hsv_color[VAL]); + sscanf(argv[3], "%u,%u,%u", &expected_rgb_color[RED], &expected_rgb_color[GRN], &expected_rgb_color[BLU]); + + bu_hsv_to_rgb(hsv_color, actual_rgb_color); + + printf("Result: %u,%u,%u", actual_rgb_color[RED], actual_rgb_color[GRN], actual_rgb_color[BLU]); + + return !(expected_rgb_color[RED] == actual_rgb_color[RED] + && expected_rgb_color[GRN] == actual_rgb_color[GRN] + && expected_rgb_color[BLU] == actual_rgb_color[BLU]); +} + +static int +test_bu_str_to_rgb(int argc, char *argv[]) +{ + unsigned int expected_rgb_color[3]; + unsigned char actual_rgb_color[3]; + char *rgb_string; + + if (argc != 4) { + bu_exit(1, "ERROR: input format is rgb_string expected_rgb_values [%s]\n", argv[0]); + } + + rgb_string = argv[2]; + sscanf(argv[3], "%u,%u,%u", &expected_rgb_color[RED], &expected_rgb_color[GRN], &expected_rgb_color[BLU]); + + bu_str_to_rgb(rgb_string, actual_rgb_color); + + printf("Result: %u,%u,%u", actual_rgb_color[RED], actual_rgb_color[GRN], actual_rgb_color[BLU]); + + return !(expected_rgb_color[RED] == actual_rgb_color[RED] + && expected_rgb_color[GRN] == actual_rgb_color[GRN] + && expected_rgb_color[BLU] == actual_rgb_color[BLU]); +} + +static int +test_bu_color_to_rgb_floats(int argc, char *argv[]) +{ + fastf_t expected_rgb_color[3]; + fastf_t actual_rgb_color[3]; + struct bu_color color = BU_COLOR_INIT_ZERO; + + if (argc != 3) { + bu_exit(1, "ERROR: input format is rgb_color [%s]\n", argv[0]); + } + + sscanf(argv[2], "%lf,%lf,%lf", &expected_rgb_color[RED], &expected_rgb_color[GRN], &expected_rgb_color[BLU]); + + color.buc_rgb[RED] = expected_rgb_color[RED]; + color.buc_rgb[GRN] = expected_rgb_color[GRN]; + color.buc_rgb[BLU] = expected_rgb_color[BLU]; + + bu_color_to_rgb_floats(&color, actual_rgb_color); + + printf("Result: %f,%f,%f", actual_rgb_color[RED], actual_rgb_color[GRN], actual_rgb_color[BLU]); + + return !(EQUAL(expected_rgb_color[RED], actual_rgb_color[RED]) + && EQUAL(expected_rgb_color[GRN], actual_rgb_color[GRN]) + && EQUAL(expected_rgb_color[BLU], actual_rgb_color[BLU])); +} + +static int +test_bu_color_from_rgb_floats(int argc, char *argv[]) +{ + fastf_t expected_rgb_color[3]; + fastf_t actual_rgb_color[3]; + struct bu_color color = BU_COLOR_INIT_ZERO; + + if (argc != 3) { + bu_exit(1, "ERROR: input format is rgb_color [%s]\n", argv[0]); + } + + sscanf(argv[2], "%lf,%lf,%lf", &expected_rgb_color[RED], &expected_rgb_color[GRN], &expected_rgb_color[BLU]); + + bu_color_from_rgb_floats(&color, expected_rgb_color); + + actual_rgb_color[RED] = color.buc_rgb[RED]; + actual_rgb_color[GRN] = color.buc_rgb[GRN]; + actual_rgb_color[BLU] = color.buc_rgb[BLU]; + + printf("Result: %f,%f,%f", actual_rgb_color[RED], actual_rgb_color[GRN], actual_rgb_color[BLU]); + + return !(EQUAL(expected_rgb_color[RED], actual_rgb_color[RED]) + && EQUAL(expected_rgb_color[GRN], actual_rgb_color[GRN]) + && EQUAL(expected_rgb_color[BLU], actual_rgb_color[BLU])); +} + +int +main(int argc, char *argv[]) +{ + int function_num = 0; + + if (argc < 2) { + bu_exit(1, "ERROR: input format is function_num function_test_args [%s]\n", argv[0]); + } + + sscanf(argv[1], "%d", &function_num); + + switch (function_num) { + case 1: + return test_bu_rgb_to_hsv(argc, argv); + case 2: + return test_bu_hsv_to_rgb(argc, argv); + case 3: + return test_bu_str_to_rgb(argc, argv); + case 4: + return test_bu_color_to_rgb_floats(argc, argv); + case 5: + return test_bu_color_from_rgb_floats(argc, argv); + } + + bu_log("ERROR: function_num %d is not valid [%s]\n", function_num, argv[0]); + return 1; +} + + +/* + * 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/trunk/src/libbu/tests/bu_color.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <agk...@us...> - 2013-12-31 00:37:54
|
Revision: 59237 http://sourceforge.net/p/brlcad/code/59237 Author: agkphysics Date: 2013-12-31 00:37:50 +0000 (Tue, 31 Dec 2013) Log Message: ----------- Added unit tests for bu_badmagic(). Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_badmagic.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-30 23:11:43 UTC (rev 59236) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-12-31 00:37:50 UTC (rev 59237) @@ -616,6 +616,16 @@ add_test(bu_color_to_rgb_floats_1 tester_bu_color 4 192,78,214) +# +# *********** badmagic.c tests ************ +# + +BRLCAD_ADDEXEC(tester_bu_badmagic bu_badmagic.c libbu NO_INSTALL) +add_test(bu_badmagic_diff_magic tester_bu_badmagic 1) +add_test(bu_badmagic_normal tester_bu_badmagic 2) +add_test(bu_badmagic_null_ptr tester_bu_badmagic 3) +add_test(bu_badmagic_misaligned tester_bu_badmagic 4) + # Local Variables: # tab-width: 8 # mode: cmake Added: brlcad/trunk/src/libbu/tests/bu_badmagic.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_badmagic.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_badmagic.c 2013-12-31 00:37:50 UTC (rev 59237) @@ -0,0 +1,110 @@ +/* B U _ B A D M A G I C . C + * BRL-CAD + * + * Copyright (c) 2013 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 <string.h> + +#include "bu.h" +#include "bn.h" + +int +bomb_callback(const void *data, const char *str) +{ + char *expected_str; + int result; + if (!data) exit(1); + expected_str = (char *)data;; + printf("Expected str: \"%s\"\n", expected_str); + printf("Actual str: \"%s\"\n", str); + result = strcmp(expected_str, str); + exit(result); +} + +int +main(int argc, char *argv[]) +{ + unsigned char *misalign = (unsigned char *)bu_malloc(1, "bu_badmagic.c"); + uint32_t *ptr = (uint32_t *)bu_malloc(sizeof(uint32_t), "bu_badmagic.c"); + uint32_t magic; + char *str = (char *)bu_malloc(20, "bu_badmagic.c"); + char *expected_str = (char *)bu_malloc(512, "bu_badmagic.c"); + char *file = "bu_badmagic.c"; + int line = 42, testnum; + + if (argc < 2) { + bu_exit(1, "Must specify a function number. [%s]\n", argv[0]); + } + + bu_bomb_add_hook((bu_hook_t)&bomb_callback, (genptr_t)expected_str); + + sscanf(argv[1], "%d", &testnum); + switch(testnum) { + case 1: + *ptr = BU_AVS_MAGIC; + magic = BU_BITV_MAGIC; + str = (char *)bu_identify_magic(*(ptr)); + sprintf(expected_str, "ERROR: bad pointer %p: s/b %s(x%lx), was %s(x%lx), file %s, line %d\n", + (void *)ptr, + str, (unsigned long)magic, + bu_identify_magic(*(ptr)), (unsigned long)*(ptr), + file, line); + bu_badmagic(ptr, magic, str, file, line); + return 1; + case 2: + *(ptr) = BU_BITV_MAGIC; + magic = BU_BITV_MAGIC; + str = (char *)bu_identify_magic(*ptr); + expected_str = "\0"; + bu_badmagic(ptr, magic, str, file, line); + return 0; + case 3: + ptr = NULL; + magic = BU_COLOR_MAGIC; + str = (char *)bu_identify_magic(magic); + sprintf(expected_str, "ERROR: NULL %s pointer, file %s, line %d\n", + str, file, line); + bu_badmagic(ptr, magic, str, file, line); + return 1; + case 4: + misalign = (unsigned char *)ptr; + ptr = (uint32_t *)(misalign + 1); + magic = BU_EXTERNAL_MAGIC; + str = (char *)bu_identify_magic(magic); + sprintf(expected_str, "ERROR: %p mis-aligned %s pointer, file %s, line %d\n", + (void *)ptr, str, file, line); + bu_badmagic(ptr, magic, str, file, line); + return 1; + } + + bu_log("Invalid function number %d specified. [%s]\n", testnum, argv[0]); + return 1; +} + +/* + * 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/trunk/src/libbu/tests/bu_badmagic.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <j-s...@us...> - 2014-01-03 00:32:59
|
Revision: 59264 http://sourceforge.net/p/brlcad/code/59264 Author: j-schulte Date: 2014-01-03 00:32:54 +0000 (Fri, 03 Jan 2014) Log Message: ----------- Add unit test for date-time.c from libbu (GCI task: http://www.google-melange.com/gci/task/view/google/gci2013/6441264325066752) Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/bu_date-time.c Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2014-01-02 21:39:34 UTC (rev 59263) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2014-01-03 00:32:54 UTC (rev 59264) @@ -626,6 +626,23 @@ add_test(bu_badmagic_null_ptr tester_bu_badmagic 3) add_test(bu_badmagic_misaligned tester_bu_badmagic 4) +# +# *********** date-time.c tests ************ +# + +BRLCAD_ADDEXEC(tester_bu_date-time bu_date-time.c libbu NO_INSTALL) +add_test(bu_date-time1 tester_bu_date-time 1) +add_test(bu_date-time2 tester_bu_date-time 2) +add_test(bu_date-time3 tester_bu_date-time 3) +add_test(bu_date-time4 tester_bu_date-time 4) +add_test(bu_date-time5 tester_bu_date-time 5) +add_test(bu_date-time6 tester_bu_date-time 6) +add_test(bu_date-time7 tester_bu_date-time 7) +add_test(bu_date-time8 tester_bu_date-time 8) +add_test(bu_date-time9 tester_bu_date-time 9) +add_test(bu_date-time10 tester_bu_date-time 10) + + # Local Variables: # tab-width: 8 # mode: cmake Added: brlcad/trunk/src/libbu/tests/bu_date-time.c =================================================================== --- brlcad/trunk/src/libbu/tests/bu_date-time.c (rev 0) +++ brlcad/trunk/src/libbu/tests/bu_date-time.c 2014-01-03 00:32:54 UTC (rev 59264) @@ -0,0 +1,83 @@ +#include "bu.h" +#include "stdio.h" + +int +main(int argc, char **argv) +{ + struct bu_vls result; + int64_t time; + int function_num; + time = 2147483647; + bu_vls_init(&result); + bu_utctime(&result, time); + printf("%s", result.vls_str); + if (argc != 2) + bu_exit(1, "ERROR: wrong number of parameters"); + sscanf(argv[1], "%d", &function_num); + switch (function_num) { + case 1: + time = 1087449261; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2004-06-17T05:14:21Z")) + return 1; + break; + case 2: + time = 631152000; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "1990-01-01T00:00:00Z")) + return 1; + break; + case 3: + time = 936860949; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "1999-09-09T07:09:09Z")) + return 1; + break; + case 4: + time = 1388696601; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2014-01-02T21:03:21Z")) + return 1; + break; + case 5: + time = 0; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "1970-01-01T00:00:00Z")) + return 1; + break; + case 6: + time = 1; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "1970-01-01T00:00:01Z")) + return 1; + break; + case 7: + time = 1431482805; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2015-05-13T02:06:45Z")) + return 1; + break; + case 8: + time = 2147483647; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2038-01-19T03:14:07Z")) + return 1; + break; + case 9: + time = 2147483649; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2038-01-19T03:14:09Z")) + return 1; + break; + case 10: + time = 3147483649; + bu_utctime(&result, time); + if(!BU_STR_EQUAL(result.vls_str, "2069-09-27T05:00:49Z")) + return 1; + break; + + } + bu_utctime(&result, time); + printf("%s", result.vls_str); + return 0; +} Property changes on: brlcad/trunk/src/libbu/tests/bu_date-time.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-csrc \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tbr...@us...> - 2014-01-19 11:57:52
|
Revision: 59462 http://sourceforge.net/p/brlcad/code/59462 Author: tbrowder2 Date: 2014-01-19 11:57:48 +0000 (Sun, 19 Jan 2014) Log Message: ----------- add a new header to help standardize correct use of zero or one for CTest's pass/fail convention Modified Paths: -------------- brlcad/trunk/src/libbu/tests/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/libbu/tests/test_internals.h Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt =================================================================== --- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2014-01-19 03:50:57 UTC (rev 59461) +++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2014-01-19 11:57:48 UTC (rev 59462) @@ -642,6 +642,9 @@ add_test(bu_date-time9 tester_bu_date-time 9) add_test(bu_date-time10 tester_bu_date-time 10) +CMAKEFILES( + test_internals.h +) # Local Variables: # tab-width: 8 Added: brlcad/trunk/src/libbu/tests/test_internals.h =================================================================== --- brlcad/trunk/src/libbu/tests/test_internals.h (rev 0) +++ brlcad/trunk/src/libbu/tests/test_internals.h 2014-01-19 11:57:48 UTC (rev 59462) @@ -0,0 +1,41 @@ +/* T E S T _ I N T E R N A L S . H + * BRL-CAD + * + * Copyright (c) 2014 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. + */ + + +#ifndef LIBBU_TESTS_TEST_INTERNALS_H +#define LIBBU_TESTS_TEST_INTERNALS_H + +/* define pass/fail per CMake/CTest testing convention */ +const int PASS = 0; +const int FAIL = 1; + +#endif /* LIBBU_TESTS_TEST_INTERNALS_H */ + + +/* + * 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/trunk/src/libbu/tests/test_internals.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |