Revision: 68970
          http://sourceforge.net/p/brlcad/code/68970
Author:   brlcad
Date:     2016-10-03 07:30:17 +0000 (Mon, 03 Oct 2016)
Log Message:
-----------
rewicker that booleanize test to not rely on some built-in notion of true or 
false that can become inconsistent with what libbu defines.  just make it take 
the expected result as input, then test and compare.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/tests/bu_booleanize.c

Modified: brlcad/trunk/src/libbu/tests/bu_booleanize.c
===================================================================
--- brlcad/trunk/src/libbu/tests/bu_booleanize.c        2016-10-03 07:28:51 UTC 
(rev 68969)
+++ brlcad/trunk/src/libbu/tests/bu_booleanize.c        2016-10-03 07:30:17 UTC 
(rev 68970)
@@ -1,4 +1,4 @@
-/*                 T E S T _ B O O L E A N I Z E . C
+/*                   B U _ B O O L E A N I Z E . C
  * BRL-CAD
  *
  * Copyright (c) 2012-2016 United States Government as represented by
@@ -19,95 +19,48 @@
  */
 
 #include "common.h"
+
 #include "bu.h"
 
-#include <string.h>
 
-
 int
-automatic_test(const char *input)
+main(int argc, char *argv[])
 {
+    int result_true = 0;
+    int result_false = 0;
+    int expect_true = 0;
 
-    char buf_input[1000], buf_aux[1000];
-    size_t buf_len;
-    int check, res, ans;
+    const char *input = NULL;
 
-    if (input) {
-       bu_strlcpy(buf_input, input, strlen(input)+1);
+    bu_log("argc: %d, %s %s %s\n", argc, argv[0], argv[1], argv[2]);
 
-       buf_len = strlen(buf_input);
-
-       /* Remove ending white space  */
-       while ((buf_len > 0) && (buf_input[buf_len-1] == ' ')) {
-           buf_input[buf_len-1] = '\0';
-           buf_len = strlen(buf_input);
-       }
-
-       /* Remove leading white space  */
-       while ((buf_len > 0) && (buf_input[0] == ' ')) {
-           bu_strlcpy(buf_aux, buf_input + 1, buf_len);
-           bu_strlcpy(buf_input, buf_aux, buf_len);
-           buf_len = strlen(buf_input);
-       }
-       res = bu_str_true(buf_input);
-
-       /* empty/'n'/'N' as first character for buf_input string */
-       if ((buf_len == 0) || (buf_input[0] == 'n') || (buf_input[0] == 'N') ||
-           (bu_strcmp(buf_input, "(null)") == 0)) {
-           ans = 0;
-           check = (res == ans);
-       } else {
-           /* true value comes from here on */
-           /* 'y'/'Y' as first character/"1" or variants of 1 for buf_input 
string  */
-           if ((buf_input[0] == 'y') || (buf_input[0] == 'Y') || 
(atol(buf_input) == 1)) {
-               ans = 1;
-               check = (res == ans);
-           } else {
-               /* "0" or variants of 0 */
-               if ((buf_input[0] == '0') && (atol(buf_input) == 0)) {
-                   ans = 0;
-                   check = (res == ans);
-               } else {
-                   ans = (int)buf_input[0];
-                   check = (res == ans);
-               }
-           }
-       }
+    if (argc > 3 || argc == 2) {
+       fprintf(stderr, "Usage: %s [test_string expect_true]\n", argv[0]);
+       return 1;
     }
 
-    if (!input) {
-       ans = 0;
-       res = bu_str_true(NULL);
-       check = (res == ans);
+    if (argc > 1) {
+       input = argv[1];
     }
-
-    if (check) {
-       printf("%24s -> %d [PASSED]\n", buf_input, res);
-    } else {
-       printf("%24s -> %d (should be: %d) [FAIL]\n", buf_input, res, ans);
+    if (argc > 2) {
+       expect_true = atol(argv[2]);
     }
 
-    return check;
-}
+    result_true = bu_str_true(input);
+    result_false = bu_str_false(input);
 
-
-int
-main(int argc, char *argv[])
-{
-    int pass = 0;
-
-    if (argc > 2)
-       fprintf(stderr,"Usage: %s test_string\n", argv[0]);
-
-    if (argc == 1) {
-       pass = automatic_test(NULL);
-       return !pass;
+    if ((expect_true > 1)
+       ?
+       (result_true > 1 && result_false == 0)
+       :
+       (expect_true == result_true && result_true != result_false))
+    {
+       printf("%24s -> true:%d, false:%d [PASSED]\n", input, result_true, 
result_false);
+       return 0;
     }
 
-    if (argc > 1)
-       pass = automatic_test(argv[1]);
-
-    return !pass;
+    printf("%24s -> true:%d, false:%d (expecting true:%d) [FAIL]\n", input, 
result_true, result_false, expect_true);
+    return 1;
 }
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to