Index: src/libbu/tests/bu_vls.c
===================================================================
--- src/libbu/tests/bu_vls.c	(revision 0)
+++ src/libbu/tests/bu_vls.c	(revision 0)
@@ -0,0 +1,520 @@
+/*                   T E S T _ V L S . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2011-2012 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#include "common.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "bu.h"
+
+
+
+int
+main(int ac, char *av[])
+{
+    int function_num = 0;
+    int test_num = 0;
+    char *c;
+    char *argvec[2] = {"abc", "def"};
+    size_t t;
+    int x;
+    struct bu_vls test_str, sec_str;
+    FILE *test_file;
+    char * filename;
+
+    filename = "tempvlstest.temp";
+
+    sscanf(av[1], "%d", &function_num);
+    sscanf(av[2], "%d", &test_num);
+    
+    if (function_num == 1) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		return !BU_STR_EQUAL(test_str.vls_str, (char *)0);
+	}
+    }
+    
+    if (function_num == 2) {
+	bu_vls_init_if_uninit(&test_str);	
+	switch (test_num) {
+	    case 1:
+		return !BU_STR_EQUAL(test_str.vls_str, (char *)0);
+	}
+    }
+
+    if (function_num == 3) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		c = bu_vls_addr(&test_str);
+		return !(*c == '\0');
+	}
+    }
+
+    if (function_num == 4) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		bu_vls_extend(&test_str, 10);
+		return !(test_str.vls_max == 32 && *test_str.vls_str == '\0');
+	    case 2:
+		bu_vls_extend(&test_str, 64);
+		return !(test_str.vls_max == 64 && *test_str.vls_str == '\0');
+	}
+    }
+
+    if (function_num == 5) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:	
+		bu_vls_setlen(&test_str, 5);
+		return !(test_str.vls_len == 5);
+	    case 2:
+		bu_vls_setlen(&test_str, 32);
+		bu_vls_setlen(&test_str, 5);
+		return !(test_str.vls_len == 32);
+	}
+    }
+
+    if (function_num == 6) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		bu_vls_setlen(&test_str, 32);
+		return !(bu_vls_strlen(&test_str) == 32);
+	}
+    }
+
+    if (function_num == 7) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 32);
+	switch (test_num) {
+	    case 1:
+		bu_vls_trunc(&test_str, 25);
+		return !(test_str.vls_len == 25);
+	    case 2:
+		bu_vls_trunc(&test_str, -7);
+		return !(test_str.vls_len == 25);
+	    case 3:
+		bu_vls_trunc(&test_str, 64);
+		return !(test_str.vls_len == 32);
+	    case 4:
+		bu_vls_trunc(&test_str, 0);
+		return !(test_str.vls_len == 0);
+	}
+    }
+
+    if (function_num == 8) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 32);
+	switch (test_num) {
+	    case 1:
+		bu_vls_trunc2(&test_str, 25);
+		return !(test_str.vls_len == 25);
+	    case 2:
+		bu_vls_trunc2(&test_str, -7);
+		return !(test_str.vls_len == 0);
+	}
+    }
+
+    if (function_num == 9) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 32);
+	switch (test_num) {
+	    case 1:
+		bu_vls_nibble(&test_str, 10);
+		return !(test_str.vls_offset == 10);
+	    case 2:
+		bu_vls_nibble(&test_str, 64);
+		return !(test_str.vls_len == 0);
+	}
+    }
+
+    if (function_num == 10) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_free(&test_str);
+		return !(*test_str.vls_str == '\0' && test_str.vls_len == 0 && test_str.vls_offset == 0 && test_str.vls_max == 0);
+	}
+    }
+
+    if (function_num == 11) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_vlsfree(&test_str);
+		return !(*test_str.vls_str == '\0' && test_str.vls_len == 0 && test_str.vls_offset == 0 && test_str.vls_max == 0);
+	}
+    }
+
+    if (function_num == 12) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "abc");
+	switch (test_num) {
+	    case 1:
+		c = bu_vls_strgrab(&test_str);
+		return !BU_STR_EQUAL(c,"abc");
+	    case 2:
+		test_str.vls_offset = 1;
+		c = bu_vls_strgrab(&test_str);
+		return !BU_STR_EQUAL(c, "bc");
+	}
+    }
+		
+    if (function_num == 13) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&test_str, "brlcad");
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, (char *)0);
+		return !BU_STR_EQUAL(test_str.vls_str, (char *)0);
+	}
+    }
+
+    if (function_num == 14) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_strncpy(&test_str, "brlcad", 32);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strncpy(&test_str, "brlcad", 3);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl");	
+	    case 3:    
+		bu_vls_strncpy(&test_str, (char *)0, 3);
+		return !BU_STR_EQUAL(test_str.vls_str, (char *)0);	
+	}
+    }
+
+    if (function_num == 15) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&test_str, "brl");
+		bu_vls_strcat(&test_str, "cad");
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, "brl");
+		bu_vls_strcat(&test_str, (char *)0);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl");
+	}
+    }
+
+    if (function_num == 16) {
+	bu_vls_init(&test_str);
+	bu_vls_setlen(&test_str, 3);
+	test_str.vls_str = "abc";
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&test_str, "brl");
+		bu_vls_strncat(&test_str, "cad", 32);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, "brl");
+		bu_vls_strncat(&test_str, "cad", 1);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlc");
+	    case 3:
+		bu_vls_strcpy(&test_str, "brl");
+		bu_vls_strncat(&test_str, (char *)0, 32);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl");
+	}
+    }
+
+    if (function_num == 17) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	bu_vls_init(&sec_str);
+	bu_vls_strcpy(&sec_str, "cad");
+	switch (test_num) {
+	    case 1:
+		bu_vls_vlscat(&test_str, &sec_str);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&sec_str, (char *)0);
+		bu_vls_vlscat(&test_str, &sec_str);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl");
+	}
+    }        
+
+    if (function_num == 18) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	bu_vls_init(&sec_str);
+	bu_vls_strcpy(&sec_str, "cad");
+	switch (test_num) {
+	    case 1:
+		bu_vls_vlscatzap(&test_str, &sec_str);	
+		return !(BU_STR_EQUAL(test_str.vls_str, "brlcad") && sec_str.vls_len ==0);
+	}
+    }
+
+    if (function_num == 19) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	bu_vls_init(&sec_str);
+	bu_vls_strcpy(&sec_str, "brl");
+	switch (test_num) {
+	    case 1:
+		return !(bu_vls_strcmp(&test_str, &sec_str) == 0);
+	    case 2:
+		bu_vls_strcpy(&sec_str, "cad");
+		return !(bu_vls_strcmp(&test_str, &sec_str) != 0);
+	}
+    }
+
+    if (function_num == 20) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	bu_vls_init(&sec_str);
+	bu_vls_strcpy(&sec_str, "bri");
+	switch (test_num) {
+	    case 1:
+		return !(bu_vls_strncmp(&test_str, &sec_str, 2) == 0);
+	    case 2:
+		bu_vls_strcpy(&sec_str, "cad");
+		return !(bu_vls_strncmp(&test_str, &sec_str, 2) != 0);
+	}
+    }
+
+    if (function_num == 21) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1: 
+		bu_vls_from_argv(&test_str, 2, argvec);
+		return !BU_STR_EQUAL(test_str.vls_str, "abc def");
+	}
+    }
+
+    if (function_num == 22) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "cad");
+	switch (test_num) {
+	    case 1:
+		bu_vls_prepend(&test_str, "brl");
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_prepend(&test_str, (char *)0);
+		return !BU_STR_EQUAL(test_str.vls_str, "cad");
+	}
+    }
+    
+    if (function_num == 23) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brlcad");
+	test_file = bu_temp_file(&filename, MAXPATHLEN);
+	switch (test_num) {
+	    case 1:
+		bu_vls_fwrite(test_file, &test_str);
+		t = fread(c, test_str.vls_len, 1, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(c, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, (char *)0);
+		bu_vls_fwrite(test_file, &test_str);
+		t = fread(c, test_str.vls_len, 1, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(c, (char *)0);
+	}
+    }
+
+    if (function_num == 24) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brlcad");
+	test_file = bu_temp_file(&filename, MAXPATHLEN);
+	switch (test_num) {
+	    case 1:		
+		x = fileno(test_file);
+		bu_vls_write(x, &test_str);
+		t = fread(c, test_str.vls_len, 1, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(c, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, (char *)0);
+		x = fileno(test_file);
+		bu_vls_write(x, &test_str);
+		t = fread(c, test_str.vls_len, 1, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(c, (char *)0);
+	}
+    }
+
+    if (function_num == 25) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brlcad");
+	bu_vls_init(&sec_str);
+	test_file = bu_temp_file(&filename, MAXPATHLEN);
+	switch (test_num) {
+	    case 1:
+		t = fwrite(test_str.vls_str + test_str.vls_offset, test_str.vls_len, 1, test_file);
+		x = fileno(test_file);
+		bu_vls_read(&sec_str, x);
+		fclose(test_file);
+		return !BU_STR_EQUAL(sec_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&test_str, (char *)0);
+		x = fileno(test_file);
+		bu_vls_read(&sec_str, x);
+		fclose(test_file);
+		return !BU_STR_EQUAL(sec_str.vls_str, (char *)0);
+	}
+    }
+
+    if (function_num == 26) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "abc");
+	switch (test_num) {
+	    case 1:
+		c = bu_vls_strdup(&test_str);
+		return !BU_STR_EQUAL(c,"abc");
+	    case 2:
+		test_str.vls_offset = 1;
+		c = bu_vls_strdup(&test_str);
+		return !BU_STR_EQUAL(c, "bc");
+	}
+    }
+
+    if (function_num == 27) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	bu_vls_init(&sec_str);	
+	test_file = bu_temp_file(&filename, MAXPATHLEN);
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&sec_str, "cad\nthisshouldnotappear");
+		bu_vls_fwrite(test_file, &sec_str);
+		x = bu_vls_gets(&test_str, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_strcpy(&sec_str, "\nthisshouldnotappear");
+		bu_vls_fwrite(test_file, &sec_str);
+		x = bu_vls_gets(&test_str, test_file);
+		fclose(test_file);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl");
+	}
+    }
+
+    if (function_num == 28) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brlca");
+	switch (test_num) {
+	    case 1:
+		bu_vls_putc(&test_str, 100);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	    case 2:
+		bu_vls_putc(&test_str, 0);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlca");            
+	}
+    }
+
+    if (function_num == 29) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&test_str, "  brl cad     ");
+		bu_vls_trimspace(&test_str);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl cad");
+	    case 2:
+		bu_vls_strcpy(&test_str, "  \nbrl cad\t     ");
+		bu_vls_trimspace(&test_str);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl cad");
+	}
+    }
+
+    if (function_num == 30) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl\ncad");	
+	switch (test_num) {
+	    case 1:
+		return !(bu_vls_print_positions_used(&test_str) == 3);
+	}
+    }
+
+    if (function_num == 31) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl\tcad");
+	switch (test_num) {
+	    case 1:
+		bu_vls_detab(&test_str);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl        cad");
+	}
+    }
+
+    if (function_num == 32) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	switch (test_num) {
+	    case 1:
+		bu_vls_printf(&test_str, "ca%c", 100);
+		return !BU_STR_EQUAL(test_str.vls_str, "brlcad");
+	}
+    }
+
+    if (function_num == 33) {
+	bu_vls_init(&test_str);
+	bu_vls_strcpy(&test_str, "brl");
+	switch (test_num) {
+	    case 1:
+		bu_vls_sprintf(&test_str, "ca%c", 100);
+		return !BU_STR_EQUAL(test_str.vls_str, "cad");
+	}
+    }
+
+    if (function_num == 34) {
+	bu_vls_init(&test_str);
+	switch (test_num) {
+	    case 1:
+		bu_vls_strcpy(&test_str, "brl cad");
+		bu_vls_spaces(&test_str, 3);
+		return !BU_STR_EQUAL(test_str.vls_str, "brl cad   ");
+	    case 2:
+		bu_vls_spaces(&test_str, 3);
+		return !BU_STR_EQUAL(test_str.vls_str, "   ");
+	}
+    }
+
+    return 1;
+
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */	
Index: src/libbu/tests/CMakeLists.txt
===================================================================
--- src/libbu/tests/CMakeLists.txt	(revision 54067)
+++ src/libbu/tests/CMakeLists.txt	(working copy)
@@ -355,6 +355,73 @@
 add_test(bu_vls_vprintf_test_56 tester_bu_vls_vprintf 56)
 add_test(bu_vls_vprintf_test_57 tester_bu_vls_vprintf 57)
 
+#
+#  ************ vls.c tests *************
+#
+BRLCAD_ADDEXEC(tester_bu_vls bu_vls.c libbu NO_INSTALL LOCAL)
+add_test(bu_vls_init_1 tester_bu_vls 1 1) 
+add_test(bu_vls_init_if_uninit_1 tester_bu_vls 2 1)
+add_test(bu_vls_addr_1 tester_bu_vls 3 1)
+add_test(bu_vls_extend_1 tester_bu_vls 4 1)
+add_test(bu_vls_extend_2 tester_bu_vls 4 2)
+add_test(bu_vls_setlen_1 tester_bu_vls 5 1)
+add_test(bu_vls_setlen_2 tester_bu_vls 5 2)
+add_test(bu_vls_strlen_1 tester_bu_vls 6 1)
+add_test(bu_vls_trunc_1 tester_bu_vls 7 1)
+add_test(bu_vls_trunc_2 tester_bu_vls 7 2)
+add_test(bu_vls_trunc_3 tester_bu_vls 7 3)
+add_test(bu_vls_trunc_4 tester_bu_vls 7 4)
+add_test(bu_vls_trunc2_1 tester_bu_vls 8 1)
+add_test(bu_vls_trunc2_2 tester_bu_vls 8 2)
+add_test(bu_vls_nibble_1 tester_bu_vls 9 1)
+add_test(bu_vls_nibble_2 tester_bu_vls 9 2)
+add_test(bu_vls_free_1 tester_bu_vls 10 1)
+add_test(bu_vls_vlsfree_1 tester_bu_vls 11 1)
+add_test(bu_vls_strgrab_1 tester_bu_vls 12 1)
+add_test(bu_vls_strgrab_2 tester_bu_vls 12 2)
+add_test(bu_vls_strcpy_1 tester_bu_vls 13 1)
+add_test(bu_vls_strcpy 2 tester_bu_vls 13 2)
+add_test(bu_vls_strncpy_1 tester_bu_vls 14 1)
+add_test(bu_vls_strncpy_2 tester_bu_vls 14 2)
+add_test(bu_vls_strncpy_3 tester_bu_vls 14 3)
+add_test(bu_vls_strcat_1 tester_bu_vls 15 1)
+add_test(bu_vls_strcat_2 tester_bu_vls 15 2)
+add_test(bu_vls_strncat_1 tester_bu_vls 16 1)
+add_test(bu_vls_strncat_2 tester_bu_vls 16 2)
+add_test(bu_vls_strncat_3 tester_bu_vls 16 3)
+add_test(bu_vls_vlscat_1 tester_bu_vls 17 1)
+add_test(bu_vls_vlscat_2 tester_bu_vls 17 2)
+add_test(bu_vls_vlscatzap_1 tester_bu_vls 18 1)
+add_test(bu_vls_strcmp_1 tester_bu_vls 19 1)
+add_test(bu_vls_strcmp_2 tester_bu_vls 19 2)
+add_test(bu_vls_strncmp_1 tester_bu_vls 20 1)
+add_test(bu_vls_strncmp_2 tester_bu_vls 20 2)
+add_test(bu_vls_from_argv_1 tester_bu_vls 21 1)
+add_test(bu_vls_prepend_1 tester_bu_vls 22 1)
+add_test(bu_vls_prepend_2 tester_bu_vls 22 2)
+add_test(bu_vls_fwrite_1 tester_bu_vls 23 1)
+add_test(bu_vls_fwrite_2 tester_bu_vls 23 2)
+add_test(bu_vls_write_1 tester_bu_vls 24 1)
+add_test(bu_vls_write_2 tester_bu_vls 24 2)
+add_test(bu_vls_read_1 tester_bu_vls 25 1)
+add_test(bu_vls_read_2 tester_bu_vls 25 2)
+add_test(bu_vls_strdup_1 tester_bu_vls 26 1)
+add_test(bu_vls_strdup_2 tester_bu_vls 26 2)
+add_test(bu_vls_gets_1 tester_bu_vls 27 1)
+add_test(bu_vls_gets_2 tester_bu_vls 27 2)
+add_test(bu_vls_putc_1 tester_bu_vls 28 1)
+add_test(bu_vls_putc_2 tester_bu_vls 28 2)
+add_test(bu_vls_trimspace_1 tester_bu_vls 29 1)
+add_test(bu_vls_trimspace_2 tester_bu_vls 29 2)
+add_test(bu_vls_print_positions_used_1 tester_bu_vls 30 1)
+add_test(bu_vls_detab_1 tester_bu_vls 31 1)
+add_test(bu_vls_printf_1 tester_bu_vls 32 1)
+add_test(bu_vls_sprintf_1 tester_bu_vls 33 1)
+add_test(bu_vls_spaces_1 tester_bu_vls 34 1)
+add_test(bu_vls_spaces_2 tester_bu_vls 34 2)
+
+
+
 # Local Variables:
 # tab-width: 8
 # mode: cmake
