Added: hadoop/avro/trunk/src/c/json_tests/pass/empty_array
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/empty_array?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/empty_array (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/empty_array Thu Oct 15 18:00:21 2009
@@ -0,0 +1 @@
+[]

Added: hadoop/avro/trunk/src/c/json_tests/pass/empty_object
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/empty_object?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/empty_object (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/empty_object Thu Oct 15 18:00:21 
2009
@@ -0,0 +1 @@
+{}

Added: hadoop/avro/trunk/src/c/json_tests/pass/json_org_example1
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/json_org_example1?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/json_org_example1 (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/json_org_example1 Thu Oct 15 
18:00:21 2009
@@ -0,0 +1,88 @@
+{"web-app": {
+  "servlet": [   
+    {
+      "servlet-name": "cofaxCDS",
+      "servlet-class": "org.cofax.cds.CDSServlet",
+      "init-param": {
+        "configGlossary:installationAt": "Philadelphia, PA",
+        "configGlossary:adminEmail": "[email protected]",
+        "configGlossary:poweredBy": "Cofax",
+        "configGlossary:poweredByIcon": "/images/cofax.gif",
+        "configGlossary:staticPath": "/content/static",
+        "templateProcessorClass": "org.cofax.WysiwygTemplate",
+        "templateLoaderClass": "org.cofax.FilesTemplateLoader",
+        "templatePath": "templates",
+        "templateOverridePath": "",
+        "defaultListTemplate": "listTemplate.htm",
+        "defaultFileTemplate": "articleTemplate.htm",
+        "useJSP": false,
+        "jspListTemplate": "listTemplate.jsp",
+        "jspFileTemplate": "articleTemplate.jsp",
+        "cachePackageTagsTrack": 200,
+        "cachePackageTagsStore": 200,
+        "cachePackageTagsRefresh": 60,
+        "cacheTemplatesTrack": 100,
+        "cacheTemplatesStore": 50,
+        "cacheTemplatesRefresh": 15,
+        "cachePagesTrack": 200,
+        "cachePagesStore": 100,
+        "cachePagesRefresh": 10,
+        "cachePagesDirtyRead": 10,
+        "searchEngineListTemplate": "forSearchEnginesList.htm",
+        "searchEngineFileTemplate": "forSearchEngines.htm",
+        "searchEngineRobotsDb": "WEB-INF/robots.db",
+        "useDataStore": true,
+        "dataStoreClass": "org.cofax.SqlDataStore",
+        "redirectionClass": "org.cofax.SqlRedirection",
+        "dataStoreName": "cofax",
+        "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
+        "dataStoreUrl": 
"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
+        "dataStoreUser": "sa",
+        "dataStorePassword": "dataStoreTestQuery",
+        "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
+        "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
+        "dataStoreInitConns": 10,
+        "dataStoreMaxConns": 100,
+        "dataStoreConnUsageLimit": 100,
+        "dataStoreLogLevel": "debug",
+        "maxUrlLength": 500}},
+    {
+      "servlet-name": "cofaxEmail",
+      "servlet-class": "org.cofax.cds.EmailServlet",
+      "init-param": {
+      "mailHost": "mail1",
+      "mailHostOverride": "mail2"}},
+    {
+      "servlet-name": "cofaxAdmin",
+      "servlet-class": "org.cofax.cds.AdminServlet"},
+ 
+    {
+      "servlet-name": "fileServlet",
+      "servlet-class": "org.cofax.cds.FileServlet"},
+    {
+      "servlet-name": "cofaxTools",
+      "servlet-class": "org.cofax.cms.CofaxToolsServlet",
+      "init-param": {
+        "templatePath": "toolstemplates/",
+        "log": 1,
+        "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
+        "logMaxSize": "",
+        "dataLog": 1,
+        "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
+        "dataLogMaxSize": "",
+        "removePageCache": "/content/admin/remove?cache=pages&id=",
+        "removeTemplateCache": "/content/admin/remove?cache=templates&id=",
+        "fileTransferFolder": 
"/usr/local/tomcat/webapps/content/fileTransferFolder",
+        "lookInContext": 1,
+        "adminGroupID": 4,
+        "betaServer": true}}],
+  "servlet-mapping": {
+    "cofaxCDS": "/",
+    "cofaxEmail": "/cofaxutil/aemail/*",
+    "cofaxAdmin": "/admin/*",
+    "fileServlet": "/static/*",
+    "cofaxTools": "/tools/*"},
+ 
+  "taglib": {
+    "taglib-uri": "cofax.tld",
+    "taglib-location": "/WEB-INF/tlds/cofax.tld"}}}

Added: hadoop/avro/trunk/src/c/json_tests/pass/json_org_example2
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/json_org_example2?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/json_org_example2 (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/json_org_example2 Thu Oct 15 
18:00:21 2009
@@ -0,0 +1,26 @@
+{"widget": {
+    "debug": "on",
+    "window": {
+        "title": "Sample Konfabulator Widget",
+        "name": "main_window",
+        "width": 500,
+        "height": 500
+    },
+    "image": { 
+        "src": "Images/Sun.png",
+        "name": "sun1",
+        "hOffset": 250,
+        "vOffset": 250,
+        "alignment": "center"
+    },
+    "text": {
+        "data": "Click Here",
+        "size": 36,
+        "style": "bold",
+        "name": "text1",
+        "hOffset": 250,
+        "vOffset": 100,
+        "alignment": "center",
+        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
+    }
+}}    

Added: hadoop/avro/trunk/src/c/json_tests/pass/json_org_example3
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/json_org_example3?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/json_org_example3 (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/json_org_example3 Thu Oct 15 
18:00:21 2009
@@ -0,0 +1,23 @@
+{
+    "glossary": {
+        "title": "example glossary",
+               "GlossDiv": {
+            "title": "S",
+                       "GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+                                       "SortAs": "SGML",
+                                       "GlossTerm": "Standard Generalized 
Markup Language",
+                                       "Acronym": "SGML",
+                                       "Abbrev": "ISO 8879:1986",
+                                       "GlossDef": {
+                        "para": "A meta-markup language, used to create markup 
languages such as DocBook.",
+                                               "GlossSeeAlso": ["GML", "XML"]
+                    },
+                                       "GlossSee": "markup"
+                }
+            }
+        }
+    }
+}
+

Added: hadoop/avro/trunk/src/c/json_tests/pass/json_org_test1
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/json_org_test1?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/json_org_test1 (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/json_org_test1 Thu Oct 15 18:00:21 
2009
@@ -0,0 +1,58 @@
+[
+    "JSON Test Pattern pass1",
+    {"object with 1 member":["array with 1 element"]},
+    {},
+    [],
+    -42,
+    true,
+    false,
+    null,
+    {
+        "integer": 1234567890,
+        "real": -9876.543210,
+        "e": 0.123456789e-12,
+        "E": 1.234567890E+34,
+        "":  23456789012E66,
+        "zero": 0,
+        "one": 1,
+        "space": " ",
+        "quote": "\"",
+        "backslash": "\\",
+        "controls": "\b\f\n\r\t",
+        "slash": "/ & \/",
+        "alpha": "abcdefghijklmnopqrstuvwyz",
+        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
+        "digit": "0123456789",
+        "0123456789": "digit",
+        "special": "`...@#$%^&*()_+-={':[,]}|;.</>?",
+        "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
+        "true": true,
+        "false": false,
+        "null": null,
+        "array":[  ],
+        "object":{  },
+        "address": "50 St. James Street",
+        "url": "http://www.JSON.org/";,
+        "comment": "// /* <!-- --",
+        "# -- --> */": " ",
+        " s p a c e d " :[1,2 , 3
+
+,
+
+4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],
+        "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
+        "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
+        
"\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`...@#$%^&*()_+-=[]{}|;:',./<>?"
+: "A key can be any string"
+    },
+    0.5 ,98.6
+,
+99.44
+,
+
+1066,
+1e1,
+0.1e1,
+1e-1,
+1e00,2e+00,2e-00
+,"rosebud"]

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_duplicate_keys
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_duplicate_keys?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_duplicate_keys (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_duplicate_keys Thu Oct 
15 18:00:21 2009
@@ -0,0 +1,3 @@
+{ "Dup" : "<-- first value",
+  "Dup" : "<-- second value", 
+  "Dup" : "success"}

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_false
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_false?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_false (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_false Thu Oct 15 
18:00:21 2009
@@ -0,0 +1 @@
+{ "two" : false }

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_multiple_members
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_multiple_members?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_multiple_members (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_multiple_members Thu 
Oct 15 18:00:21 2009
@@ -0,0 +1,4 @@
+{ "one" : "value",
+"Schöne" : "value ™ ∆",
+"three" : "Schöne Grüße",
+"four" : "This is line one.\n\tThis is line two.\nThis is line 
three.\n\t\u0041\u0042\u0043" }

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_null
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_null?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_null (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_null Thu Oct 15 
18:00:21 2009
@@ -0,0 +1 @@
+{ "three" : null }

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_object_member
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_object_member?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_object_member (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_object_member Thu Oct 
15 18:00:21 2009
@@ -0,0 +1 @@
+{ "foo" : { "This" : "works" } }

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_one_member
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_one_member?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_one_member (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_one_member Thu Oct 15 
18:00:21 2009
@@ -0,0 +1 @@
+{ "key" : "value" }

Added: hadoop/avro/trunk/src/c/json_tests/pass/object_with_true
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/object_with_true?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/object_with_true (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/object_with_true Thu Oct 15 
18:00:21 2009
@@ -0,0 +1 @@
+{ "one" : true }

Added: hadoop/avro/trunk/src/c/json_tests/pass/rfc_example
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/rfc_example?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/rfc_example (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/rfc_example Thu Oct 15 18:00:21 2009
@@ -0,0 +1,22 @@
+[
+      {
+         "precision": "zip",
+         "Latitude":  37.7668,
+         "Longitude": -122.3959,
+         "Address":   "",
+         "City":      "SAN FRANCISCO",
+         "State":     "CA",
+         "Zip":       "94107",
+         "Country":   "US"
+      },
+      {
+         "precision": "zip",
+         "Latitude":  37.371991,
+         "Longitude": -122.026020,
+         "Address":   "",
+         "City":      "SUNNYVALE",
+         "State":     "CA",
+         "Zip":       "94085",
+         "Country":   "US"
+      }
+]

Added: hadoop/avro/trunk/src/c/json_tests/pass/rfc_example2
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/rfc_example2?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/rfc_example2 (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/rfc_example2 Thu Oct 15 18:00:21 
2009
@@ -0,0 +1,13 @@
+{
+      "Image": {
+          "Width":  800,
+          "Height": 600,
+          "Title":  "View from 15th Floor",
+          "Thumbnail": {
+              "Url":    "http://www.example.com/image/481989943";,
+              "Height": 125,
+              "Width":  "100"
+          },
+          "IDs": [116, 943, 234, 38793]
+        }
+}

Added: hadoop/avro/trunk/src/c/json_tests/pass/string_u_value
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tests/pass/string_u_value?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/json_tests/pass/string_u_value (added)
+++ hadoop/avro/trunk/src/c/json_tests/pass/string_u_value Thu Oct 15 18:00:21 
2009
@@ -0,0 +1 @@
+{ "good" : "\u0041\u0042\u0043-DEF" }

Modified: hadoop/avro/trunk/src/c/json_tokenizer.h
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/json_tokenizer.h?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/json_tokenizer.h (original)
+++ hadoop/avro/trunk/src/c/json_tokenizer.h Thu Oct 15 18:00:21 2009
@@ -21,7 +21,7 @@
 #define JSON_TOKENIZER_H
 
 #include <wchar.h>
-#include "json_schema.h"
+#include "json_parser.h"
 
 /* Tokens which are not part of the schema */
 enum json_tokens

Added: hadoop/avro/trunk/src/c/test_avro_interop.c
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/test_avro_interop.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/test_avro_interop.c (added)
+++ hadoop/avro/trunk/src/c/test_avro_interop.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,75 @@
+#include "avro_private.h"
+#include <apr_strings.h>
+#include <stdlib.h>
+
+apr_pool_t *pool;
+
+/*
+TODO:
+
+We still need to create a File Object container to finish this test.
+For now, we're only validating that we can parse the schema.
+
+$ ant generate-test-data
+needs to be called to make sure that test data is created.
+
+The test files are then in ./build/test/data-files 
+*/
+
+int
+main (void)
+{
+  char *srcdir = getenv ("srcdir");
+  char *path;
+  char *jsontext;
+  apr_size_t jsonlen;
+  struct avro_value *value;
+  struct avro_channel *channel;
+
+  if (!srcdir)
+    {
+      srcdir = ".";
+    }
+
+  avro_initialize ();
+  apr_pool_create (&pool, NULL);
+
+  path = apr_pstrcat (pool, srcdir, "/../test/schemata/interop.avsc", NULL);
+  if (!path)
+    {
+      fprintf (stderr, "Couldn't allocate memory for file path\n");
+      return EXIT_FAILURE;
+    }
+  jsontext = avro_util_file_read_full (pool, path, &jsonlen);
+  if (!jsontext)
+    {
+      fprintf (stderr, "Failed to parse the JSON in file %s\n", path);
+      return EXIT_FAILURE;
+    }
+  value = avro_value_create (pool, jsontext, jsonlen);
+  if (!value)
+    {
+      fprintf (stderr, "Unable to parse the Avro schema in file %s\n", path);
+      return EXIT_FAILURE;
+    }
+
+  path =
+    apr_pstrcat (pool, srcdir, "/../../build/test/data-files/test.py.avro",
+                NULL);
+  if (!path)
+    {
+      return EXIT_FAILURE;
+    }
+  channel = avro_file_container_create (pool, path, APR_READ, APR_OS_DEFAULT);
+  if (!channel)
+    {
+      fprintf (stderr, "Failed to open data file %s\n", path);
+      return EXIT_FAILURE;
+    }
+
+  value->read_data (value, channel);
+  value->print_info (value, stderr);
+
+  apr_pool_destroy (pool);
+  return EXIT_SUCCESS;
+}

Added: hadoop/avro/trunk/src/c/test_avro_schema.c
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/test_avro_schema.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/test_avro_schema.c (added)
+++ hadoop/avro/trunk/src/c/test_avro_schema.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,103 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#include "avro.h"
+#include "avro_private.h"
+#include "apr_strings.h"
+
+apr_pool_t *pool;
+
+static void
+run_tests (char *dirpath, int should_pass)
+{
+  char *jsontext;
+  apr_size_t jsonlen;
+  struct avro_value *value;
+  DIR *dir;
+  struct dirent *dent;
+  char *filepath;
+
+  dir = opendir (dirpath);
+  if (dir == NULL)
+    {
+      fprintf (stderr, "Unable to open '%s'\n", dirpath);
+      exit (EXIT_FAILURE);
+    }
+  do
+    {
+      dent = readdir (dir);
+      if (dent && dent->d_name[0] != '.')
+       {
+         filepath = apr_pstrcat (pool, dirpath, "/", dent->d_name, NULL);
+         fprintf (stderr, "TEST %s...", filepath);
+         jsontext = avro_util_file_read_full (pool, filepath, &jsonlen);
+         if (!jsontext)
+           {
+             fprintf (stderr, "Can't read the file\n");
+             exit (EXIT_FAILURE);
+           }
+
+         value = avro_value_create (pool, jsontext, jsonlen);
+         if (value && should_pass)
+           {
+             /*value->print_info (value, stderr); */
+           }
+         else if (!value && !should_pass)
+           {
+             /* failure expected */
+           }
+         else
+           {
+             exit (EXIT_FAILURE);
+           }
+         fprintf (stderr, "ok!\n");
+       }
+    }
+  while (dent != NULL);
+}
+
+int
+main (int argc, char *argv[])
+{
+  char *srcdir = getenv ("srcdir");
+  char *path;
+
+  if (!srcdir)
+    {
+      srcdir = ".";
+    }
+
+  avro_initialize ();
+  apr_pool_create (&pool, NULL);
+
+  /* Run the tests that should pass */
+  path = apr_pstrcat (pool, srcdir, "/avro_schema_tests/pass", NULL);
+  fprintf (stderr, "RUNNING %s\n", path);
+  run_tests (path, 1);
+  path = apr_pstrcat (pool, srcdir, "/avro_schema_tests/fail", NULL);
+  fprintf (stderr, "RUNNING %s\n", path);
+  run_tests (path, 0);
+
+  apr_pool_destroy (pool);
+  return EXIT_SUCCESS;
+}

Modified: hadoop/avro/trunk/src/c/test_json_parser.c
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/test_json_parser.c?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/test_json_parser.c (original)
+++ hadoop/avro/trunk/src/c/test_json_parser.c Thu Oct 15 18:00:21 2009
@@ -25,49 +25,85 @@
 
 #include <apr.h>
 #include <apr_pools.h>
+#include <apr_strings.h>
 
 #include "avro.h"
+#include "avro_private.h"
 #include "json.h"
 
-#define TRACING 1
+apr_pool_t *pool;
 
-static struct test_dir
+void
+run_tests (char *dirpath, int should_pass)
 {
-  char *path;
-  int shouldFail;
-} test_dirs[] =
-{
-  {
-  "json/pass", 0},
-  {
-  "json/fail", 1}
-};
+  FILE *file;
+  DIR *dir;
+  struct dirent *dent;
+  JSON_value *value;
+  char *filepath;
+  char *text;
+  apr_size_t len;
+
+  dir = opendir (dirpath);
+  if (dir == NULL)
+    {
+      fprintf (stderr, "Unable to open '%s'\n", dirpath);
+      exit (EXIT_FAILURE);
+    }
+  do
+    {
+      dent = readdir (dir);
+      if (dent && dent->d_name[0] != '.')
+       {
+         filepath = apr_pstrcat (pool, dirpath, "/", dent->d_name, NULL);
+         file = fopen (filepath, "r");
+         if (file == NULL)
+           {
+             fprintf (stderr, "Can't open file %s", filepath);
+             exit (EXIT_FAILURE);
+           }
 
-#define NUM_TEST_DIRS (sizeof(test_dirs)/sizeof(test_dirs[0]))
+         text = avro_util_file_read_full (pool, filepath, &len);
+         if (!text)
+           {
+             fprintf (stderr, "Can't read the file %s\n", filepath);
+             exit (EXIT_FAILURE);
+           }
 
-FILE *trace = NULL;
+         value = JSON_parse (pool, text, len);
+         if (!value && should_pass)
+           {
+             exit (EXIT_FAILURE);
+           }
+         else if (value && !should_pass)
+           {
+             exit (EXIT_FAILURE);
+           }
+         else if (value)
+           {
+#if TRACING
+             JSONParserTrace (trace, buf);
+#endif
+/*
+             JSON_print (stderr, value);
+*/
+           }
+       }
+    }
+  while (dent != NULL);
+  closedir (dir);
+}
 
 int
 main (int argc, char *argv[], char *envp[])
 {
-  FILE *file;
-  DIR *dir;
-  struct dirent *dent;
-  int i, processed;
-  char buf[4096];
-  apr_pool_t *pool;
-  JSON_value *value;
-  char path[256];
+  char *dirpath;
   char *srcdir = getenv ("srcdir");
   if (!srcdir)
     {
       srcdir = ".";
     }
 
-  avro_initialize ();
-
-  apr_pool_create (&pool, NULL);
-
 #if TRACING
   trace = fopen ("trace.txt", "w");
   if (trace == NULL)
@@ -76,64 +112,14 @@
     }
 #endif
 
-  for (i = 0; i < NUM_TEST_DIRS; i++)
-    {
-      struct test_dir *td = test_dirs + i;
-      snprintf (path, sizeof (path), "%s/%s", srcdir, td->path);
-      dir = opendir (path);
-      if (dir == NULL)
-       {
-         fprintf (stderr, "Unable to open '%s'\n", path);
-         return EXIT_FAILURE;
-       }
-      dent = readdir (dir);
-      while (dent != NULL)
-       {
-         if (dent->d_name[0] != '.')
-           {
-             char filepath[256];
-             snprintf (filepath, sizeof (filepath), "%s/%s", path,
-                       dent->d_name);
-
-             file = fopen (filepath, "r");
-             if (file == NULL)
-               {
-                 fprintf (stderr, "Can't open file");
-                 return EXIT_FAILURE;
-               }
-
-             processed = 0;
-             while (!feof (file))
-               {
-                 if (fread (buf + processed, 1, 1, file) == 1)
-                   {
-                     processed++;
-                   }
-               }
-             buf[processed] = '\0';
-             fclose (file);
-
-             value = JSON_parse (pool, buf, processed);
-             if (!value)
-               {
-                 if (!td->shouldFail)
-                   {
-                     return EXIT_FAILURE;
-                   }
-               }
-             else
-               {
-                 if (td->shouldFail)
-                   {
-                     return EXIT_FAILURE;
-                   }
-               }
-             /* JSONParserTrace (trace, buf); */
-             /* JSON_print (stderr, value); */
-           }
-         dent = readdir (dir);
-       }
-      closedir (dir);
-    }
+  avro_initialize ();
+
+  apr_pool_create (&pool, NULL);
+
+  dirpath = apr_pstrcat (pool, srcdir, "/json_tests/pass", NULL);
+  run_tests (dirpath, 1);
+  dirpath = apr_pstrcat (pool, srcdir, "/json_tests/fail", NULL);
+  run_tests (dirpath, 0);
+
   return EXIT_SUCCESS;
 }


Reply via email to