Index: /trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.c	(revision 9749)
+++ /trunk/psLib/src/types/psMetadataConfig.c	(revision 9750)
@@ -10,6 +10,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-25 00:16:33 $
+*  @version $Revision: 1.98 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-26 04:44:09 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -1166,13 +1166,15 @@
     // Attempt to open specified file
     int fd = 0;
-    if (!(fd = open(filename, O_RDONLY))) {
+    fd = open(filename, O_RDONLY);
+    struct stat buf;                    // Results of stat() for file
+    if (fd < 0 || fstat(fd, &buf) != 0) {
         // XXX really should return strerror() here
         psError(PS_ERR_IO, true,
                 _("Failed to open file '%s'. Check if it exists and it has the proper "
                   "permissions."), filename);
+        close(fd);
         return NULL;
     }
-
-    struct stat buf;                    // Results of stat() for file
+    /*  This appears to be unreachable, but moving to check above just to be sure.
     if (fstat(fd, &buf) != 0) {
         psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
@@ -1180,5 +1182,5 @@
         return NULL;
     }
-
+    */
     // psMetadataConfigParse() is going to read the entire file into memory so
     // we're trying to be nice by allowing the VM to flush the file out of
@@ -1188,9 +1190,11 @@
     if (file == MAP_FAILED) {
         psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
-        if (close(fd) != 0) {
-            // XXX really should return strerror() here
-            psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
-            return NULL;
-        }
+        /*        if (close(fd) != 0) {
+                    // XXX really should return strerror() here
+                    psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
+                    return NULL;
+                }
+        */
+        close(fd);
         return NULL;
     }
@@ -1199,5 +1203,5 @@
 
     munmap(file, (size_t)buf.st_size);
-
+    /*
     if (close(fd) != 0) {
         // XXX really should return strerror() here
@@ -1205,5 +1209,6 @@
         return NULL;
     }
-
+    */
+    close(fd);
     return md;
 }
@@ -1241,5 +1246,7 @@
 
     psList *doc = psStringSplit(str, "\n", false);
-    if (!doc) {
+    if (!doc || doc->n == 0) {
+        if (doc != NULL)
+            psFree(doc);
         psFree(parseLevelInfoArray);
         psFree(md);
Index: /trunk/psLib/test/types/tap_psMetadataConfig_input.c
===================================================================
--- /trunk/psLib/test/types/tap_psMetadataConfig_input.c	(revision 9749)
+++ /trunk/psLib/test/types/tap_psMetadataConfig_input.c	(revision 9750)
@@ -12,4 +12,7 @@
 #include <pslib.h>
 #include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 
 #include "tap.h"
@@ -22,5 +25,5 @@
 int main(void)
 {
-    plan_tests(4);
+    plan_tests(10);
 
     diag("Tests for psMetadataConfig Input Functions");
@@ -39,5 +42,5 @@
     unsigned int nfail = 0;
     md = psMetadataAlloc();
-    psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666);
+    psMetadataAddS32(md, PS_LIST_HEAD, "new_S32", 0, "", 666);
 
     //Return NULL for NULL filename input
@@ -47,5 +50,5 @@
             "psMetadataConfigRead:           return NULL for NULL filename input.");
     }
-    //Return false for invalid filename input
+    //Return NULL for invalid filename input
     {
         out = psMetadataConfigRead(out, &nfail, ".", false);
@@ -53,11 +56,33 @@
             "psMetadataConfigRead:           return NULL for invalid filename input.");
     }
+    //Return NULL for missing file input
+    {
+        out = psMetadataConfigRead(out, &nfail, "table4.dat", false);
+        ok( out == NULL,
+            "psMetadataConfigRead:           return NULL for missing file input.");
+    }
+    //Return empty metadata for read-only file with invalid syntax
+    {
+        out = psMetadataConfigRead(out, &nfail, "table3.dat", false);
+        ok( out != NULL && out->list->n == 0,
+            "psMetadataConfigRead:           return empty metadata for file"
+            " with invalid syntax.");
+        psFree(out);
+        out = NULL;
+    }
     //Return true for valid inputs
     {
-        skip_start(  !psMetadataConfigWrite(md, "mdcfg.wrt"), 1,
-                     "Skipping 1 tests because psMetadataConfigWrite failed");
+        skip_start(  !psMetadataConfigWrite(md, "mdcfg.wrt"), 2,
+                     "Skipping 2 tests because psMetadataConfigWrite failed");
         out = psMetadataConfigRead(out, &nfail, "mdcfg.wrt", false);
-        ok( out != NULL,
+        psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
+        ok( out != NULL && nfail == 0,
             "psMetadataConfigRead:           return correct metadata for valid inputs.");
+        skip_start(  tempItem == NULL, 1,
+                     "Skipping 1 tests because metadata container is empty!");
+        ok_str( tempItem->name, "new_S32",
+                "psMetadataConfigRead:           return correct metadataItem from "
+                "returned metadata.");
+        skip_end();
         skip_end();
     }
@@ -76,50 +101,84 @@
 {
     diag("  >>>Test 2:  psMetadataConfigParse");
+    psMetadata *out = NULL;
+    unsigned int nfail = 0;
+    char str1[30];
+    strcpy(str1, "-10.05    2        4");
+    char str2[30];
+    strcpy(str2, "\nnew S32       666\n");
+
+    //Return NULL for NULL string input
+    {
+        out = psMetadataConfigParse(out, &nfail, NULL, false);
+        ok( out == NULL,
+            "psMetadataConfigParse:          return NULL for NULL string input.");
+    }
+    //Return correct metadata for correct string input
+    {
+        psFree(out);
+        out = NULL;
+        out = psMetadataConfigParse(out, NULL, str2, false);
+        psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
+        ok( out != NULL && tempItem != NULL,
+            "psMetadataConfigParse:          return correct metadata for valid "
+            "string input.");
+    }
+    //Return empty metadata for incorrect string input
+    {
+        psFree(out);
+        out = NULL;
+        out = psMetadataConfigParse(out, NULL, str1, false);
+        psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
+        ok( out != NULL && tempItem == NULL,
+            "psMetadataConfigParse:          return correct metadata for valid "
+            "string input.");
+        if (tempItem != NULL)
+            printf("\n\n name=%s\n", tempItem->name);
+    }
+
+
     /*    FILE *openfile;
-        openfile = fopen("mdcfg.prt", "w+");
-        FILE *nofile = NULL;
-        psMetadata *md = NULL;
-        md = psMetadataAlloc();
-     
-        //psMetadataConfigParse(psMetadata* md,unsigned int *nFail,const char *str,bool overwrite)
-     
-        //Return false for NULL metadata input
-        {
-            ok( !psMetadataConfigPrint(openfile, NULL),
-                 "psMetadataConfigPrint:           return false for NULL metadata input.");
-        }
-        //Return false for empty metadata input
-        {
-            ok( !psMetadataConfigPrint(openfile, md),
-                 "psMetadataConfigPrint:           return false for empty metadata input.");
-        }
-        //Return false for NULL file input
-        psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666);
-        {
-            ok( !psMetadataConfigPrint(nofile, md),
-                 "psMetadataConfigPrint:           return false for NULL FILE* input.");
-        }
-        //Return false for read-only file input
-        nofile = fopen("mdcfg.prt", "r");
-        {
-            ok( !psMetadataConfigPrint(nofile, md),
-                 "psMetadataConfigPrint:           return false for read-only FILE* input.");
-        }
-        //Return true for valid inputs
-        {
-            ok( psMetadataConfigPrint(openfile, md),
-                "psMetadataConfigPrint:           return true for valid inputs.");
-        }
-     
-     
-        //Check for Memory leaks
-        {
-            fclose(nofile);
-            fclose(openfile);
-            psFree(md);
-            remove("mdcfg.prt");
-            checkMem();
-        }
-        */
+    openfile = fopen("mdcfg.prt", "w+");
+    FILE *nofile = NULL;
+    psMetadata *md = NULL;
+    md = psMetadataAlloc();
+
+    //psMetadataConfigParse(psMetadata* md,unsigned int *nFail,const char *str,bool overwrite)
+
+    //Return false for NULL metadata input
+    {
+        ok( !psMetadataConfigPrint(openfile, NULL),
+             "psMetadataConfigPrint:           return false for NULL metadata input.");
+    }
+    //Return false for empty metadata input
+    {
+        ok( !psMetadataConfigPrint(openfile, md),
+             "psMetadataConfigPrint:           return false for empty metadata input.");
+    }
+    //Return false for NULL file input
+    psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666);
+    {
+        ok( !psMetadataConfigPrint(nofile, md),
+             "psMetadataConfigPrint:           return false for NULL FILE* input.");
+    }
+    //Return false for read-only file input
+    nofile = fopen("mdcfg.prt", "r");
+    {
+        ok( !psMetadataConfigPrint(nofile, md),
+             "psMetadataConfigPrint:           return false for read-only FILE* input.");
+    }
+    //Return true for valid inputs
+    {
+        ok( psMetadataConfigPrint(openfile, md),
+            "psMetadataConfigPrint:           return true for valid inputs.");
+    }
+
+    */
+    //Check for Memory leaks
+    {
+        psFree(out);
+        checkMem();
+    }
+
 }
 
Index: /trunk/psLib/test/types/tap_psMetadataConfig_output.c
===================================================================
--- /trunk/psLib/test/types/tap_psMetadataConfig_output.c	(revision 9749)
+++ /trunk/psLib/test/types/tap_psMetadataConfig_output.c	(revision 9750)
@@ -124,34 +124,2 @@
 }
 
-
-/*
-void testLookupTableAlloc(void)
-{
-    diag("  >>>Test 1:  psLookupTableAlloc & psMemCheckLookupTable Fxns");
- 
-    psLookupTable *lt = NULL;
- 
-//Tests for psLookupTableAlloc
-   //Return NULL for NULL filename input
-    {
-        lt = psLookupTableAlloc(NULL, "\%f \%lf \%d \%ld", 10);
-        ok( lt == NULL,
-            "psLookupTableAlloc:               return NULL for NULL filename input.");
-    }
-    //Return correct vector output for valid inputs
-    {
-        vec = psLookupTableInterpolateAll(table2, 1);
-        skip_start(  vec == NULL, 1,
-                     "Skipping 1 tests because psLookupTableInterpolateAll failed");
-        ok_double(vec->data.F64[0], 1.0,
-                  "psLookupTableInterpolateAll:     return correct output vector for valid inputs.");
-        skip_end();
-    }
-    //Check for Memory leaks
-    {
-        psFree(lt);
-        checkMem();
-    }
-}
-*/
-
