You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ma...@apache.org on 2010/01/16 02:52:29 UTC

svn commit: r899870 [6/8] - in /hadoop/avro/trunk: ./ lang/c/ lang/c/datatypes/ lang/c/docs/ lang/c/io/ lang/c/jansson/ lang/c/jansson/doc/ lang/c/jansson/doc/ext/ lang/c/jansson/src/ lang/c/jansson/test/ lang/c/jansson/test/testdata/ lang/c/jansson/te...

Added: hadoop/avro/trunk/lang/c/jansson/test/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/Makefile.am?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/Makefile.am (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/Makefile.am Sat Jan 16 01:52:24 2010
@@ -0,0 +1,22 @@
+DIST_SUBDIRS = testprogs testdata
+SUBDIRS = testprogs
+
+check_PROGRAMS = loadf_dumpf loads_dumps load_file_dump_file
+
+AM_CPPFLAGS = -I$(top_srcdir)/src
+AM_CFLAGS = -Wall -Werror
+LDFLAGS = -static  # for speed and Valgrind
+LDADD = ../src/libjansson.la
+
+TESTS = test-api test-invalid test-valid
+
+EXTRA_DIST = \
+	test-api \
+	test-invalid \
+	test-valid \
+	run-test \
+	json-compare.py \
+	split-testfile.py
+
+clean-local:
+	rm -rf testlogs

Added: hadoop/avro/trunk/lang/c/jansson/test/json-compare.py
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/json-compare.py?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/json-compare.py (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/json-compare.py Sat Jan 16 01:52:24 2010
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+import sys
+try:
+    import json
+except ImportError:
+    import simplejson as json
+
+def load(filename):
+    try:
+        jsonfile = open(filename)
+    except IOError, err:
+        print >>sys.stderr, "unable to load %s: %s" % \
+            (filename, err.strerror)
+        sys.exit(1)
+
+    try:
+        jsondata = json.load(jsonfile)
+    except ValueError, err:
+        print "%s is malformed: %s" % (filename, err)
+        sys.exit(1)
+    finally:
+        jsonfile.close()
+
+    return jsondata
+
+def main():
+    if len(sys.argv) != 3:
+        print >>sys.stderr, "usage: %s json1 json2" % sys.argv[0]
+        return 2
+
+    json1 = load(sys.argv[1])
+    json2 = load(sys.argv[2])
+    if json1 == json2:
+        return 0
+    else:
+        return 1
+
+if __name__ == '__main__':
+    sys.exit(main() or 0)

Propchange: hadoop/avro/trunk/lang/c/jansson/test/json-compare.py
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/avro/trunk/lang/c/jansson/test/load_file_dump_file.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/load_file_dump_file.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/load_file_dump_file.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/load_file_dump_file.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <stdio.h>
+#include <jansson.h>
+
+int main(int argc, char *argv[])
+{
+    json_t *json;
+    json_error_t error;
+
+    if(argc != 3) {
+        fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
+        return 2;
+    }
+
+    json = json_load_file(argv[1], &error);
+    if(!json) {
+        fprintf(stderr, "%d\n%s\n", error.line, error.text);
+        return 1;
+    }
+
+    json_dump_file(json, argv[2], 0);
+    json_decref(json);
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/loadf_dumpf.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/loadf_dumpf.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/loadf_dumpf.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/loadf_dumpf.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <stdio.h>
+#include <jansson.h>
+
+int main(int argc, char *argv[])
+{
+    json_t *json;
+    json_error_t error;
+
+    if(argc != 1) {
+        fprintf(stderr, "usage: %s\n", argv[0]);
+        return 2;
+    }
+
+    json = json_loadf(stdin, &error);
+    if(!json) {
+        fprintf(stderr, "%d\n%s\n", error.line, error.text);
+        return 1;
+    }
+
+    /* loadf_dumpf indents, others don't, so dumping with and without
+       indenting is tested */
+    json_dumpf(json, stdout, JSON_INDENT(4));
+    json_decref(json);
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/loads_dumps.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/loads_dumps.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/loads_dumps.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/loads_dumps.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jansson.h>
+
+#define BUFFER_SIZE (256 * 1024)
+
+int main(int argc, char *argv[])
+{
+    json_t *json;
+    json_error_t error;
+    int count;
+    char buffer[BUFFER_SIZE];
+    char *result;
+
+    if(argc != 1) {
+        fprintf(stderr, "usage: %s\n", argv[0]);
+        return 2;
+    }
+
+    count = fread(buffer, 1, BUFFER_SIZE, stdin);
+    if(count < 0 || count >= BUFFER_SIZE) {
+        fprintf(stderr, "unable to read input\n");
+        return 1;
+    }
+    buffer[count] = '\0';
+
+    json = json_loads(buffer, &error);
+    if(!json) {
+        fprintf(stderr, "%d\n%s\n", error.line, error.text);
+        return 1;
+    }
+
+    result = json_dumps(json, 0);
+    json_decref(json);
+
+    puts(result);
+    free(result);
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/run-test
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/run-test?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/run-test (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/run-test Sat Jan 16 01:52:24 2010
@@ -0,0 +1,57 @@
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"
+
+run_testprog() {
+    local prog=$1
+    local prefix=$2
+    if [ -n "$VALGRIND" ]; then
+        local runner="$VALGRIND_CMDLINE "
+    fi
+
+    case "$prog" in
+        load_file_dump_file)
+            $runner./$prog \
+                $prefix.in \
+                $prefix.$prog.stdout \
+                2>$prefix.$prog.stderr
+            ;;
+        *)
+            $runner./$prog \
+                <$prefix.in \
+                >$prefix.$prog.stdout \
+                2>$prefix.$prog.stderr
+            ;;
+    esac
+
+    if [ -n "$VALGRIND" ]; then
+        # Check for Valgrind error output. The valgrind option
+        # --error-exitcode is not enough because Valgrind doesn't
+        # think unfreed allocs are errors.
+        if grep -E -q '^==[0-9]+== ' $prefix.$prog.stderr; then
+            echo "### $prefix ($prog) failed:" >&2
+            echo "valgrind detected an error" >&2
+            echo "for details, see test/$prefix.$prog.stderr" >&2
+            exit 1
+        fi
+    fi
+}
+
+for testfile in $TESTFILES; do
+    tmpdir="testlogs/`basename $testfile`"
+    rm -rf $tmpdir
+    mkdir -p $tmpdir
+    if echo "$testfile" | grep -q -E -e '-strip$'; then
+        opts="--strip"
+    fi
+    ${srcdir}/split-testfile.py $opts $testfile $tmpdir | while read name; do
+        run_test loadf_dumpf $tmpdir/$name
+        run_test loads_dumps $tmpdir/$name
+        run_test load_file_dump_file $tmpdir/$name
+        printf '.'
+    done || exit 1
+    echo
+done

Added: hadoop/avro/trunk/lang/c/jansson/test/split-testfile.py
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/split-testfile.py?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/split-testfile.py (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/split-testfile.py Sat Jan 16 01:52:24 2010
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+import os
+import sys
+from optparse import OptionParser
+
+def strip_file(filename):
+    with open(filename) as fobj:
+        data = fobj.read()
+    with open(filename, 'w') as fobj:
+        fobj.write(data.strip())
+
+def open_files(outdir, i, name):
+    basename = '%02d_%s' % (i, name)
+    print basename
+    input_path = os.path.join(outdir, basename + '.in')
+    output_path = os.path.join(outdir, basename + '.out')
+    return open(input_path, 'w'), open(output_path, 'w')
+
+def main():
+    parser = OptionParser('usage: %prog [options] inputfile outputdir')
+    parser.add_option('--strip', help='strip whitespace from input',
+                      action='store_true', default=False)
+    options, args = parser.parse_args()
+
+    if len(args) != 2:
+        parser.print_help()
+        return 2
+
+    infile = os.path.normpath(args[0])
+    outdir = os.path.normpath(args[1])
+
+    if not os.path.exists(outdir):
+        print >>sys.stderr, 'output directory %r does not exist!' % outdir
+        return 1
+
+    n = 0
+    current = None
+    input, output = None, None
+
+    for line in open(infile):
+        if line.startswith('==== '):
+            n += 1
+            if input is not None and output is not None:
+                input.close()
+                output.close()
+                if options.strip:
+                    strip_file(input.name)
+            input, output = open_files(outdir, n, line[5:line.find(' ====\n')])
+            current = input
+        elif line == '====\n':
+            current = output
+        else:
+            current.write(line)
+
+    if input is not None and output is not None:
+        input.close()
+        output.close()
+
+    print >>sys.stderr, "%s: %d test cases" % (infile, n)
+
+if __name__ == '__main__':
+    sys.exit(main() or 0)

Propchange: hadoop/avro/trunk/lang/c/jansson/test/split-testfile.py
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/avro/trunk/lang/c/jansson/test/test-api
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/test-api?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/test-api (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/test-api Sat Jan 16 01:52:24 2010
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"
+LOGDIR="testlogs/api"
+N=`find testprogs -type f | wc -l`
+
+echo "testprogs: $N tests"
+
+rm -rf $LOGDIR
+mkdir -p $LOGDIR
+
+if [ -n "$VALGRIND" ]; then
+    runner="$VALGRIND_CMDLINE "
+fi
+
+i=1
+failed=
+for prog in testprogs/*; do
+    [ -x $prog ] || continue
+    t=`basename $prog`
+    logbase="testlogs/api/`printf '%02d-%s' $i $t`"
+    if ! $runner./$prog >$logbase.stdout 2>$logbase.stderr; then
+        echo >&2
+        echo "### $prog failed:" >&2
+        cat $logbase.stderr
+        exit 1
+    fi
+    if [ -n "$VALGRIND" ]; then
+        # Check for Valgrind error output. The valgrind option
+        # --error-exitcode is not enough because Valgrind doesn't
+        # think unfreed allocs are errors.
+        if grep -E -q '^==[0-9]+== ' $logbase.stderr; then
+            echo "### $prog failed:" >&2
+            echo "valgrind detected an error" >&2
+            echo "for details, see test/$logbase.stderr" >&2
+            exit 1
+        fi
+    fi
+    printf '.'
+done
+echo

Propchange: hadoop/avro/trunk/lang/c/jansson/test/test-api
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/avro/trunk/lang/c/jansson/test/test-invalid
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/test-invalid?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/test-invalid (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/test-invalid Sat Jan 16 01:52:24 2010
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+TESTFILES="${srcdir}/testdata/invalid ${srcdir}/testdata/invalid-strip ${srcdir}/testdata/invalid-unicode"
+
+run_test() {
+    local prog=$1
+    local prefix=$2
+
+    run_testprog $prog $prefix
+    if ! cmp $prefix.out $prefix.$prog.stderr >/dev/null; then
+        echo >&2
+        echo "### $prefix ($prog) failed:" >&2
+        cat $prefix.in >&2
+        echo "### expected output:" >&2
+        cat $prefix.out >&2
+        echo "### actual output:" >&2
+        cat $prefix.$prog.stderr >&2
+        exit 1
+    fi
+}
+
+. ${srcdir}/run-test

Propchange: hadoop/avro/trunk/lang/c/jansson/test/test-invalid
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/avro/trunk/lang/c/jansson/test/test-valid
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/test-valid?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/test-valid (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/test-valid Sat Jan 16 01:52:24 2010
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+#
+# Jansson is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+
+TESTFILES="${srcdir}/testdata/valid ${srcdir}/testdata/valid-strip"
+
+run_test() {
+    local prog=$1
+    local prefix=$2
+
+    run_testprog $prog $prefix
+
+    if ! ${srcdir}/json-compare.py $prefix.in $prefix.$prog.stdout \
+        >$prefix.$prog.cmp-stdout
+    then
+        echo >&2
+        echo "### $prefix ($prog) failed:" >&2
+        cat $prefix.in >&2
+        if [ -f $prefix.$prog.stdout ]; then
+            echo "### output:" >&2
+            cat $prefix.$prog.stdout >&2
+        fi
+        if [ -s $prefix.$prog.stdout ]; then
+            echo "### compare output:" >&2
+            cat $prefix.$prog.cmp-stdout >&2
+        fi
+        exit 1
+    fi
+}
+
+. ${srcdir}/run-test

Propchange: hadoop/avro/trunk/lang/c/jansson/test/test-valid
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/Makefile.am?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/Makefile.am (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/Makefile.am Sat Jan 16 01:52:24 2010
@@ -0,0 +1 @@
+EXTRA_DIST = invalid invalid-strip invalid-unicode valid valid-strip

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid Sat Jan 16 01:52:24 2010
@@ -0,0 +1,235 @@
+==== empty ====
+====
+1
+'[' or '{' expected near end of file
+==== null ====
+null
+====
+1
+'[' or '{' expected near 'null'
+==== lone-open-brace ====
+{
+====
+2
+string or '}' expected near end of file
+==== lone-open-bracket ====
+[
+====
+2
+']' expected near end of file
+==== bracket-comma ====
+[,
+====
+1
+unexpected token near ','
+==== bracket-one-comma ====
+[1,
+====
+2
+']' expected near end of file
+==== unterminated-string ====
+["a
+====
+1
+unexpected newline near '"a'
+==== unterminated-array ====
+["a"
+====
+2
+']' expected near end of file
+==== apostrophe ====
+['
+====
+1
+invalid token near '''
+==== brace-comma ====
+{,
+====
+1
+string or '}' expected near ','
+==== unterminated-empty-key ====
+{"
+====
+1
+unexpected newline near '"'
+==== unterminated-key ====
+{"a
+====
+1
+unexpected newline near '"a'
+==== object-no-colon ====
+{"a"
+====
+2
+':' expected near end of file
+==== object-apostrophes ====
+{'a'
+====
+1
+string or '}' expected near '''
+==== object-no-value ====
+{"a":
+====
+2
+unexpected token near end of file
+==== object-unterminated-value ====
+{"a":"a
+====
+1
+unexpected newline near '"a'
+==== object-garbage-at-end ====
+{"a":"a" 123}
+====
+1
+'}' expected near '123'
+==== unterminated-object-and-array ====
+{[
+====
+1
+string or '}' expected near '['
+==== unterminated-array-and-object ====
+[{
+====
+2
+string or '}' expected near end of file
+==== object-in-unterminated-array ====
+[{}
+====
+2
+']' expected near end of file
+==== extra-comma-in-array ====
+[1,]
+====
+1
+unexpected token near ']'
+==== extra-command-in-multiline-array ====
+[1,
+2,
+3,
+4,
+5,
+]
+====
+6
+unexpected token near ']'
+==== real-truncated-at-point ====
+[1.]
+====
+1
+invalid token near '1.'
+==== real-truncated-at-e ====
+[1e]
+====
+1
+invalid token near '1e'
+==== real-garbage-after-e ====
+[1ea]
+====
+1
+invalid token near '1e'
+==== real-positive-overflow ====
+[123123e100000]
+====
+1
+real number overflow near '123123e100000'
+==== real-negative-overflow ====
+[-123123e100000]
+====
+1
+real number overflow near '-123123e100000'
+==== real-underflow ====
+[123e-10000000]
+====
+1
+real number underflow near '123e-10000000'
+==== integer-starting-with-zero ====
+[012]
+====
+1
+invalid token near '0'
+==== negative-integer-starting-with-zero ====
+[-012]
+====
+1
+invalid token near '-0'
+==== too-big-positive-integer ====
+[123123123123123]
+====
+1
+too big integer near '123123123123123'
+==== too-big-negative-integer ====
+[-123123123123123]
+====
+1
+too big negative integer near '-123123123123123'
+==== invalid-identifier ====
+[troo
+====
+1
+invalid token near 'troo'
+==== minus-sign-without-number ====
+[-foo]
+====
+1
+invalid token near '-'
+==== invalid-negative-integerr ====
+[-123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-negative-real ====
+[-123.123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-escape ====
+["\a <-- invalid escape"]
+====
+1
+invalid escape near '"\'
+==== tab-character-in-string ====
+["	 <-- tab character"]
+====
+1
+control character 0x9 near '"'
+==== null-byte-in-string ====
+["\u0000 (null byte not allowed)"]
+====
+1
+\u0000 is not allowed
+==== truncated-unicode-surrogate ====
+["\uDADA (first surrogate without the second)"]
+====
+1
+invalid Unicode '\uDADA'
+==== invalid-second-surrogate ====
+["\uD888\u3210 (first surrogate and invalid second surrogate)"]
+====
+1
+invalid Unicode '\uD888\u3210'
+==== lone-second-surrogate ====
+["\uDFAA (second surrogate on it's own)"]
+====
+1
+invalid Unicode '\uDFAA'
+==== unicode-identifier ====
+Ã¥
+====
+1
+'[' or '{' expected near 'Ã¥'
+==== ascii-unicode-identifier ====
+aå
+====
+1
+'[' or '{' expected near 'a'
+==== garbage-at-the-end ====
+[1,2,3]foo
+====
+1
+end of file expected near 'foo'
+==== garbage-after-newline ====
+[1,2,3]
+foo
+====
+2
+end of file expected near 'foo'

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-strip
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-strip?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-strip (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-strip Sat Jan 16 01:52:24 2010
@@ -0,0 +1,235 @@
+==== empty ====
+====
+1
+'[' or '{' expected near end of file
+==== null ====
+null
+====
+1
+'[' or '{' expected near 'null'
+==== lone-open-brace ====
+{
+====
+1
+string or '}' expected near end of file
+==== lone-open-bracket ====
+[
+====
+1
+']' expected near end of file
+==== bracket-comma ====
+[,
+====
+1
+unexpected token near ','
+==== bracket-one-comma ====
+[1,
+====
+1
+']' expected near end of file
+==== unterminated-string ====
+["a
+====
+1
+premature end of input near '"a'
+==== unterminated-array ====
+["a"
+====
+1
+']' expected near end of file
+==== apostrophe ====
+['
+====
+1
+invalid token near '''
+==== brace-comma ====
+{,
+====
+1
+string or '}' expected near ','
+==== unterminated-empty-key ====
+{"
+====
+1
+premature end of input near '"'
+==== unterminated-key ====
+{"a
+====
+1
+premature end of input near '"a'
+==== object-no-colon ====
+{"a"
+====
+1
+':' expected near end of file
+==== object-apostrophes ====
+{'a'
+====
+1
+string or '}' expected near '''
+==== object-no-value ====
+{"a":
+====
+1
+unexpected token near end of file
+==== object-unterminated-value ====
+{"a":"a
+====
+1
+premature end of input near '"a'
+==== object-garbage-at-end ====
+{"a":"a" 123}
+====
+1
+'}' expected near '123'
+==== unterminated-object-and-array ====
+{[
+====
+1
+string or '}' expected near '['
+==== unterminated-array-and-object ====
+[{
+====
+1
+string or '}' expected near end of file
+==== object-in-unterminated-array ====
+[{}
+====
+1
+']' expected near end of file
+==== extra-comma-in-array ====
+[1,]
+====
+1
+unexpected token near ']'
+==== extra-command-in-multiline-array ====
+[1,
+2,
+3,
+4,
+5,
+]
+====
+6
+unexpected token near ']'
+==== real-truncated-at-point ====
+[1.]
+====
+1
+invalid token near '1.'
+==== real-truncated-at-e ====
+[1e]
+====
+1
+invalid token near '1e'
+==== real-garbage-after-e ====
+[1ea]
+====
+1
+invalid token near '1e'
+==== real-positive-overflow ====
+[123123e100000]
+====
+1
+real number overflow near '123123e100000'
+==== real-negative-overflow ====
+[-123123e100000]
+====
+1
+real number overflow near '-123123e100000'
+==== real-underflow ====
+[123e-10000000]
+====
+1
+real number underflow near '123e-10000000'
+==== integer-starting-with-zero ====
+[012]
+====
+1
+invalid token near '0'
+==== negative-integer-starting-with-zero ====
+[-012]
+====
+1
+invalid token near '-0'
+==== too-big-positive-integer ====
+[123123123123123]
+====
+1
+too big integer near '123123123123123'
+==== too-big-negative-integer ====
+[-123123123123123]
+====
+1
+too big negative integer near '-123123123123123'
+==== invalid-identifier ====
+[troo
+====
+1
+invalid token near 'troo'
+==== minus-sign-without-number ====
+[-foo]
+====
+1
+invalid token near '-'
+==== invalid-negative-integerr ====
+[-123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-negative-real ====
+[-123.123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-escape ====
+["\a <-- invalid escape"]
+====
+1
+invalid escape near '"\'
+==== tab-character-in-string ====
+["	 <-- tab character"]
+====
+1
+control character 0x9 near '"'
+==== null-byte-in-string ====
+["\u0000 (null byte not allowed)"]
+====
+1
+\u0000 is not allowed
+==== truncated-unicode-surrogate ====
+["\uDADA (first surrogate without the second)"]
+====
+1
+invalid Unicode '\uDADA'
+==== invalid-second-surrogate ====
+["\uD888\u3210 (first surrogate and invalid second surrogate)"]
+====
+1
+invalid Unicode '\uD888\u3210'
+==== lone-second-surrogate ====
+["\uDFAA (second surrogate on it's own)"]
+====
+1
+invalid Unicode '\uDFAA'
+==== unicode-identifier ====
+Ã¥
+====
+1
+'[' or '{' expected near 'Ã¥'
+==== ascii-unicode-identifier ====
+aå
+====
+1
+'[' or '{' expected near 'a'
+==== garbage-at-the-end ====
+[1,2,3]foo
+====
+1
+end of file expected near 'foo'
+==== garbage-after-newline ====
+[1,2,3]
+foo
+====
+2
+end of file expected near 'foo'

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-unicode
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-unicode?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-unicode (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/invalid-unicode Sat Jan 16 01:52:24 2010
@@ -0,0 +1,90 @@
+==== lone-invalid-utf-8 ====
+å
+====
+-1
+unable to decode byte 0xe5 at position 0
+==== invalid-utf-8-in-string ====
+["å <-- invalid UTF-8"]
+====
+-1
+unable to decode byte 0xe5 at position 2
+==== invalid-utf-8-in-array ====
+[å]
+====
+-1
+unable to decode byte 0xe5 at position 1
+==== invalid-utf-8-in-identifier ====
+[aå]
+====
+-1
+unable to decode byte 0xe5 at position 2
+==== invalid-utf-8-in-escape ====
+["\uå"]
+====
+-1
+unable to decode byte 0xe5 at position 4
+==== invalid-utf-8-after-backslash ====
+["\å"]
+====
+-1
+unable to decode byte 0xe5 at position 3
+==== invalid-utf-8-in-int ====
+[0å]
+====
+-1
+unable to decode byte 0xe5 at position 2
+==== invalid-utf-8-in-bigger-int ====
+[123å]
+====
+-1
+unable to decode byte 0xe5 at position 4
+==== invalid-utf-8-in-real-after-e ====
+[1eå]
+====
+-1
+unable to decode byte 0xe5 at position 3
+==== invalid-utf-8-in-exponent ====
+[1e1å]
+====
+-1
+unable to decode byte 0xe5 at position 4
+==== lone-utf-8-continuation-byte ====
+[""]
+====
+-1
+unable to decode byte 0x81 at position 2
+==== overlong-ascii-encoding ====
+["Á"]
+====
+-1
+unable to decode byte 0xc1 at position 2
+==== restricted-utf-8 ====
+["ý"]
+====
+-1
+unable to decode byte 0xfd at position 2
+==== not-in-unicode-range ====
+["ô¿¿¿"]
+====
+-1
+unable to decode byte 0xf4 at position 2
+==== overlong-3-byte-encoding ====
+["à€¢ <-- overlong encoding"]
+====
+-1
+unable to decode byte 0xe0 at position 2
+==== overlong-4-byte-encoding ====
+["ð€€¢ <-- overlong encoding"]
+====
+-1
+unable to decode byte 0xf0 at position 2
+==== truncated-utf-8 ====
+["àÿ <-- truncated UTF-8"]
+====
+-1
+unable to decode byte 0xe0 at position 2
+==== encoded-surrogate-half ====
+["í¢« <-- encoded surrogate half"]
+====
+-1
+unable to decode byte 0xed at position 2

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/valid
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/valid?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/valid (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/valid Sat Jan 16 01:52:24 2010
@@ -0,0 +1,68 @@
+==== empty-string ====
+[""]
+==== short-string ====
+["a"]
+==== simple-ascii-string ====
+["abcdefghijklmnopqrstuvwxyz1234567890 "]
+==== utf-8-string ====
+["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
+==== string-escapes ====
+["\"\\\/\b\f\n\r\t"]
+==== one-byte-utf-8 ====
+["\u002c one-byte UTF-8"]
+==== two-byte-utf-8 ====
+["\u0123 two-byte UTF-8"]
+==== three-byte-utf-8 ====
+["\u0821 three-byte UTF-8"]
+==== utf-surrogate-four-byte-encoding ====
+["\uD834\uDD1E surrogate, four-byte UTF-8"]
+==== escaped-utf-control-char ====
+["\u0012 escaped control character"]
+==== simple-int-0 ====
+[0]
+==== simple-int-1 ====
+[1]
+==== simple-int-123 ====
+[123]
+==== negative-zero ====
+[-0]
+==== negative-one ====
+[-1]
+==== negative-int ====
+[-123]
+==== simple-real ====
+[123.456789]
+==== real-exponent ====
+[123e45]
+==== real-capital-e ====
+[1E22]
+==== real-positive-exponent ====
+[1e+2]
+==== real-negative-exponent ====
+[1e-2]
+==== real-capital-e-positive-exponent ====
+[1E+2]
+==== real-capital-e-negative-exponent ====
+[1E-2]
+==== real-fraction-exponent ====
+[123.456e78]
+==== true ====
+[true]
+==== false ====
+[false]
+==== null ====
+[null]
+==== empty-array ====
+[]
+==== empty-object-in-array ====
+[{}]
+==== complex-array ====
+[1,2,3,4,
+"a", "b", "c",
+{"foo": "bar", "core": "dump"},
+true, false, true, true, null, false
+]
+==== empty-object ====
+{}
+==== simple-object ====
+{"a":[]}

Added: hadoop/avro/trunk/lang/c/jansson/test/testdata/valid-strip
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testdata/valid-strip?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testdata/valid-strip (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testdata/valid-strip Sat Jan 16 01:52:24 2010
@@ -0,0 +1,68 @@
+==== empty-string ====
+[""]
+==== short-string ====
+["a"]
+==== simple-ascii-string ====
+["abcdefghijklmnopqrstuvwxyz1234567890 "]
+==== utf-8-string ====
+["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
+==== string-escapes ====
+["\"\\\/\b\f\n\r\t"]
+==== one-byte-utf-8 ====
+["\u002c one-byte UTF-8"]
+==== two-byte-utf-8 ====
+["\u0123 two-byte UTF-8"]
+==== three-byte-utf-8 ====
+["\u0821 three-byte UTF-8"]
+==== utf-surrogate-four-byte-encoding ====
+["\uD834\uDD1E surrogate, four-byte UTF-8"]
+==== escaped-utf-control-char ====
+["\u0012 escaped control character"]
+==== simple-int-0 ====
+[0]
+==== simple-int-1 ====
+[1]
+==== simple-int-123 ====
+[123]
+==== negative-zero ====
+[-0]
+==== negative-one ====
+[-1]
+==== negative-int ====
+[-123]
+==== simple-real ====
+[123.456789]
+==== real-exponent ====
+[123e45]
+==== real-capital-e ====
+[1E22]
+==== real-positive-exponent ====
+[1e+2]
+==== real-negative-exponent ====
+[1e-2]
+==== real-capital-e-positive-exponent ====
+[1E+2]
+==== real-capital-e-negative-exponent ====
+[1E-2]
+==== real-fraction-exponent ====
+[123.456e78]
+==== true ====
+[true]
+==== false ====
+[false]
+==== null ====
+[null]
+==== empty-array ====
+[]
+==== empty-object-in-array ====
+[{}]
+==== complex-array ====
+[1,2,3,4,
+"a", "b", "c",
+{"foo": "bar", "core": "dump"},
+true, false, true, true, null, false
+]
+==== empty-object ====
+{}
+==== simple-object ====
+{"a":[]}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/Makefile.am?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/Makefile.am (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/Makefile.am Sat Jan 16 01:52:24 2010
@@ -0,0 +1,12 @@
+check_PROGRAMS = test_array test_load test_simple test_number test_object
+
+test_array_SOURCES = test_array.c util.h
+test_load_SOURCES = test_load.c util.h
+test_simple_SOURCES = test_simple.c util.h
+test_number_SOURCES = test_number.c util.h
+test_object_SOURCES = test_object.c util.h
+
+AM_CPPFLAGS = -I$(top_srcdir)/src
+AM_CFLAGS = -Wall -Werror
+LDFLAGS = -static  # for speed and Valgrind
+LDADD = ../../src/libjansson.la

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_array.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_array.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_array.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_array.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,400 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <jansson.h>
+#include "util.h"
+
+static void test_misc(void)
+{
+    json_t *array, *five, *seven, *value;
+    int i;
+
+    array = json_array();
+    five = json_integer(5);
+    seven = json_integer(7);
+
+    if(!array)
+        fail("unable to create array");
+    if(!five || !seven)
+        fail("unable to create integer");
+
+    if(json_array_size(array) != 0)
+        fail("empty array has nonzero size");
+
+    if(!json_array_append(array, NULL))
+        fail("able to append NULL");
+
+    if(json_array_append(array, five))
+        fail("unable to append");
+
+    if(json_array_size(array) != 1)
+        fail("wrong array size");
+
+    value = json_array_get(array, 0);
+    if(!value)
+        fail("unable to get item");
+    if(value != five)
+        fail("got wrong value");
+
+    if(json_array_append(array, seven))
+        fail("unable to append value");
+
+    if(json_array_size(array) != 2)
+        fail("wrong array size");
+
+    value = json_array_get(array, 1);
+    if(!value)
+        fail("unable to get item");
+    if(value != seven)
+        fail("got wrong value");
+
+    if(json_array_set(array, 0, seven))
+        fail("unable to set value");
+
+    if(!json_array_set(array, 0, NULL))
+        fail("able to set NULL");
+
+    if(json_array_size(array) != 2)
+        fail("wrong array size");
+
+    value = json_array_get(array, 0);
+    if(!value)
+        fail("unable to get item");
+    if(value != seven)
+        fail("got wrong value");
+
+    if(json_array_get(array, 2) != NULL)
+        fail("able to get value out of bounds");
+
+    if(!json_array_set(array, 2, seven))
+        fail("able to set value out of bounds");
+
+    for(i = 2; i < 30; i++) {
+        if(json_array_append(array, seven))
+            fail("unable to append value");
+
+        if(json_array_size(array) != i + 1)
+            fail("wrong array size");
+    }
+
+    for(i = 0; i < 30; i++) {
+        value = json_array_get(array, i);
+        if(!value)
+            fail("unable to get item");
+        if(value != seven)
+            fail("got wrong value");
+    }
+
+    if(json_array_set_new(array, 15, json_integer(123)))
+        fail("unable to set new value");
+
+    value = json_array_get(array, 15);
+    if(!json_is_integer(value) || json_integer_value(value) != 123)
+        fail("json_array_set_new works incorrectly");
+
+    if(!json_array_set_new(array, 15, NULL))
+        fail("able to set_new NULL value");
+
+    if(json_array_append_new(array, json_integer(321)))
+        fail("unable to append new value");
+
+    value = json_array_get(array, json_array_size(array) - 1);
+    if(!json_is_integer(value) || json_integer_value(value) != 321)
+        fail("json_array_append_new works incorrectly");
+
+    if(!json_array_append_new(array, NULL))
+        fail("able to append_new NULL value");
+
+    json_decref(five);
+    json_decref(seven);
+    json_decref(array);
+}
+
+static void test_insert(void)
+{
+    json_t *array, *five, *seven, *eleven, *value;
+    int i;
+
+    array = json_array();
+    five = json_integer(5);
+    seven = json_integer(7);
+    eleven = json_integer(11);
+
+    if(!array)
+        fail("unable to create array");
+    if(!five || !seven || !eleven)
+        fail("unable to create integer");
+
+
+    if(!json_array_insert(array, 1, five))
+        fail("able to insert value out of bounds");
+
+
+    if(json_array_insert(array, 0, five))
+        fail("unable to insert value in an empty array");
+
+    if(json_array_get(array, 0) != five)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_size(array) != 1)
+        fail("array size is invalid after insertion");
+
+
+    if(json_array_insert(array, 1, seven))
+        fail("unable to insert value at the end of an array");
+
+    if(json_array_get(array, 0) != five)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_get(array, 1) != seven)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_size(array) != 2)
+        fail("array size is invalid after insertion");
+
+
+    if(json_array_insert(array, 1, eleven))
+        fail("unable to insert value in the middle of an array");
+
+    if(json_array_get(array, 0) != five)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_get(array, 1) != eleven)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_get(array, 2) != seven)
+        fail("json_array_insert works incorrectly");
+
+    if(json_array_size(array) != 3)
+        fail("array size is invalid after insertion");
+
+
+    if(json_array_insert_new(array, 2, json_integer(123)))
+        fail("unable to insert value in the middle of an array");
+
+    value = json_array_get(array, 2);
+    if(!json_is_integer(value) || json_integer_value(value) != 123)
+        fail("json_array_insert_new works incorrectly");
+
+    if(json_array_size(array) != 4)
+        fail("array size is invalid after insertion");
+
+
+    for(i = 0; i < 20; i++) {
+        if(json_array_insert(array, 0, seven))
+            fail("unable to insert value at the begining of an array");
+    }
+
+    for(i = 0; i < 20; i++) {
+        if(json_array_get(array, i) != seven)
+            fail("json_aray_insert works incorrectly");
+    }
+
+    if(json_array_size(array) != 24)
+        fail("array size is invalid after loop insertion");
+
+    json_decref(five);
+    json_decref(seven);
+    json_decref(eleven);
+    json_decref(array);
+}
+
+static void test_remove(void)
+{
+    json_t *array, *five, *seven;
+
+    array = json_array();
+    five = json_integer(5);
+    seven = json_integer(7);
+
+    if(!array)
+        fail("unable to create array");
+    if(!five)
+        fail("unable to create integer");
+    if(!seven)
+        fail("unable to create integer");
+
+
+    if(!json_array_remove(array, 0))
+        fail("able to remove an unexisting index");
+
+
+    if(json_array_append(array, five))
+        fail("unable to append");
+
+    if(!json_array_remove(array, 1))
+        fail("able to remove an unexisting index");
+
+    if(json_array_remove(array, 0))
+        fail("unable to remove");
+
+    if(json_array_size(array) != 0)
+        fail("array size is invalid after removing");
+
+
+    if(json_array_append(array, five) ||
+       json_array_append(array, seven) ||
+       json_array_append(array, five) ||
+       json_array_append(array, seven))
+        fail("unable to append");
+
+    if(json_array_remove(array, 2))
+        fail("unable to remove");
+
+    if(json_array_size(array) != 3)
+        fail("array size is invalid after removing");
+
+    if(json_array_get(array, 0) != five ||
+       json_array_get(array, 1) != seven ||
+       json_array_get(array, 2) != seven)
+        fail("remove works incorrectly");
+
+    json_decref(five);
+    json_decref(seven);
+    json_decref(array);
+}
+
+static void test_clear(void)
+{
+    json_t *array, *five, *seven;
+    int i;
+
+    array = json_array();
+    five = json_integer(5);
+    seven = json_integer(7);
+
+    if(!array)
+        fail("unable to create array");
+    if(!five || !seven)
+        fail("unable to create integer");
+
+    for(i = 0; i < 10; i++) {
+        if(json_array_append(array, five))
+            fail("unable to append");
+    }
+    for(i = 0; i < 10; i++) {
+        if(json_array_append(array, seven))
+            fail("unable to append");
+    }
+
+    if(json_array_size(array) != 20)
+        fail("array size is invalid after appending");
+
+    if(json_array_clear(array))
+        fail("unable to clear");
+
+    if(json_array_size(array) != 0)
+        fail("array size is invalid after clearing");
+
+    json_decref(five);
+    json_decref(seven);
+    json_decref(array);
+}
+
+static void test_extend(void)
+{
+    json_t *array1, *array2, *five, *seven;
+    int i;
+
+    array1 = json_array();
+    array2 = json_array();
+    five = json_integer(5);
+    seven = json_integer(7);
+
+    if(!array1 || !array2)
+        fail("unable to create array");
+    if(!five || !seven)
+        fail("unable to create integer");
+
+    for(i = 0; i < 10; i++) {
+        if(json_array_append(array1, five))
+            fail("unable to append");
+    }
+    for(i = 0; i < 10; i++) {
+        if(json_array_append(array2, seven))
+            fail("unable to append");
+    }
+
+    if(json_array_size(array1) != 10 || json_array_size(array2) != 10)
+        fail("array size is invalid after appending");
+
+    if(json_array_extend(array1, array2))
+        fail("unable to extend");
+
+    for(i = 0; i < 10; i++) {
+        if(json_array_get(array1, i) != five)
+            fail("invalid array contents after extending");
+    }
+    for(i = 10; i < 20; i++) {
+        if(json_array_get(array1, i) != seven)
+            fail("invalid array contents after extending");
+    }
+
+    json_decref(five);
+    json_decref(seven);
+    json_decref(array1);
+    json_decref(array2);
+}
+
+static void test_circular()
+{
+    json_t *array1, *array2;
+
+    /* the simple cases are checked */
+
+    array1 = json_array();
+    if(!array1)
+        fail("unable to create array");
+
+    if(json_array_append(array1, array1) == 0)
+        fail("able to append self");
+
+    if(json_array_insert(array1, 0, array1) == 0)
+        fail("able to insert self");
+
+    if(json_array_append_new(array1, json_true()))
+        fail("failed to append true");
+
+    if(json_array_set(array1, 0, array1) == 0)
+        fail("able to set self");
+
+    json_decref(array1);
+
+
+    /* create circular references */
+
+    array1 = json_array();
+    array2 = json_array();
+    if(!array1 || !array2)
+        fail("unable to create array");
+
+    if(json_array_append(array1, array2) ||
+       json_array_append(array2, array1))
+        fail("unable to append");
+
+    /* circularity is detected when dumping */
+    if(json_dumps(array1, 0) != NULL)
+        fail("able to dump circulars");
+
+    /* decref twice to deal with the circular references */
+    json_decref(array1);
+    json_decref(array2);
+    json_decref(array1);
+}
+
+
+int main()
+{
+    test_misc();
+    test_insert();
+    test_remove();
+    test_clear();
+    test_extend();
+    test_circular();
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_load.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_load.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_load.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_load.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <jansson.h>
+#include <string.h>
+#include "util.h"
+
+int main()
+{
+    json_t *json;
+    json_error_t error;
+
+    json = json_load_file("/path/to/nonexistent/file.json", &error);
+    if(error.line != -1)
+        fail("json_load_file returned an invalid line number");
+    if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json: No such file or directory") != 0)
+        fail("json_load_file returned an invalid error message");
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_number.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_number.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_number.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_number.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <jansson.h>
+#include "util.h"
+
+int main()
+{
+    json_t *integer, *real;
+    int i;
+    double d;
+
+    integer = json_integer(5);
+    real = json_real(100.1);
+
+    if(!integer)
+        fail("unable to create integer");
+    if(!real)
+        fail("unable to create real");
+
+    i = json_integer_value(integer);
+    if(i != 5)
+        fail("wrong integer value");
+
+    d = json_real_value(real);
+    if(d != 100.1)
+        fail("wrong real value");
+
+    d = json_number_value(integer);
+    if(d != 5.0)
+        fail("wrong number value");
+    d = json_number_value(real);
+    if(d != 100.1)
+        fail("wrong number value");
+
+    json_decref(integer);
+    json_decref(real);
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_object.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_object.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_object.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_object.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <jansson.h>
+#include <string.h>
+#include "util.h"
+
+static void test_clear()
+{
+    json_t *object, *ten;
+
+    object = json_object();
+    ten = json_integer(10);
+
+    if(!object)
+        fail("unable to create object");
+    if(!ten)
+        fail("unable to create integer");
+
+    if(json_object_set(object, "a", ten) ||
+       json_object_set(object, "b", ten) ||
+       json_object_set(object, "c", ten) ||
+       json_object_set(object, "d", ten) ||
+       json_object_set(object, "e", ten))
+        fail("unable to set value");
+
+    if(json_object_size(object) != 5)
+        fail("invalid size");
+
+    json_object_clear(object);
+
+    if(json_object_size(object) != 0)
+        fail("invalid size after clear");
+
+    json_decref(ten);
+    json_decref(object);
+}
+
+static void test_update()
+{
+    json_t *object, *other, *nine, *ten;
+
+    object = json_object();
+    other = json_object();
+
+    nine = json_integer(9);
+    ten = json_integer(10);
+
+    if(!object || !other)
+        fail("unable to create object");
+    if(!nine || !ten)
+        fail("unable to create integer");
+
+
+    /* update an empty object with an empty object */
+
+    if(json_object_update(object, other))
+        fail("unable to update an emtpy object with an empty object");
+
+    if(json_object_size(object) != 0)
+        fail("invalid size after update");
+
+    if(json_object_size(other) != 0)
+        fail("invalid size for updater after update");
+
+
+    /* update an empty object with a nonempty object */
+
+    if(json_object_set(other, "a", ten) ||
+       json_object_set(other, "b", ten) ||
+       json_object_set(other, "c", ten) ||
+       json_object_set(other, "d", ten) ||
+       json_object_set(other, "e", ten))
+        fail("unable to set value");
+
+    if(json_object_update(object, other))
+        fail("unable to update an empty object");
+
+    if(json_object_size(object) != 5)
+        fail("invalid size after update");
+
+    if(json_object_get(object, "a") != ten ||
+       json_object_get(object, "b") != ten ||
+       json_object_get(object, "c") != ten ||
+       json_object_get(object, "d") != ten ||
+       json_object_get(object, "e") != ten)
+        fail("update works incorrectly");
+
+
+    /* perform the same update again */
+
+    if(json_object_update(object, other))
+        fail("unable to update an empty object");
+
+    if(json_object_size(object) != 5)
+        fail("invalid size after update");
+
+    if(json_object_get(object, "a") != ten ||
+       json_object_get(object, "b") != ten ||
+       json_object_get(object, "c") != ten ||
+       json_object_get(object, "d") != ten ||
+       json_object_get(object, "e") != ten)
+        fail("update works incorrectly");
+
+
+    /* update a nonempty object with a nonempty object with both old
+       and new keys */
+
+    if(json_object_clear(other))
+        fail("clear failed");
+
+    if(json_object_set(other, "a", nine) ||
+       json_object_set(other, "b", nine) ||
+       json_object_set(other, "f", nine) ||
+       json_object_set(other, "g", nine) ||
+       json_object_set(other, "h", nine))
+        fail("unable to set value");
+
+    if(json_object_update(object, other))
+        fail("unable to update a nonempty object");
+
+    if(json_object_size(object) != 8)
+        fail("invalid size after update");
+
+    if(json_object_get(object, "a") != nine ||
+       json_object_get(object, "b") != nine ||
+       json_object_get(object, "f") != nine ||
+       json_object_get(object, "g") != nine ||
+       json_object_get(object, "h") != nine)
+        fail("update works incorrectly");
+
+    json_decref(nine);
+    json_decref(ten);
+    json_decref(other);
+    json_decref(object);
+}
+
+static void test_circular()
+{
+    json_t *object1, *object2;
+
+    object1 = json_object();
+    object2 = json_object();
+    if(!object1 || !object2)
+        fail("unable to create object");
+
+    /* the simple case is checked */
+    if(json_object_set(object1, "a", object1) == 0)
+        fail("able to set self");
+
+    /* create circular references */
+    if(json_object_set(object1, "a", object2) ||
+       json_object_set(object2, "a", object1))
+        fail("unable to set value");
+
+    /* circularity is detected when dumping */
+    if(json_dumps(object1, 0) != NULL)
+        fail("able to dump circulars");
+
+    /* decref twice to deal with the circular references */
+    json_decref(object1);
+    json_decref(object2);
+    json_decref(object1);
+}
+
+static void test_misc()
+{
+    json_t *object, *string, *other_string, *value;
+    void *iter;
+
+    object = json_object();
+    string = json_string("test");
+    other_string = json_string("other");
+
+    if(!object)
+        fail("unable to create object");
+    if(!string || !other_string)
+        fail("unable to create string");
+
+    if(json_object_get(object, "a"))
+        fail("value for nonexisting key");
+
+    if(json_object_set(object, "a", string))
+        fail("unable to set value");
+
+    if(!json_object_set(object, NULL, string))
+        fail("able to set NULL key");
+
+    if(!json_object_set(object, "a", NULL))
+        fail("able to set NULL value");
+
+    iter = json_object_iter(object);
+    if(!iter)
+        fail("unable to get iterator");
+
+    if(strcmp(json_object_iter_key(iter), "a"))
+        fail("iterating failed: wrong key");
+    if(json_object_iter_value(iter) != string)
+        fail("iterating failed: wrong value");
+    if(json_object_iter_next(object, iter) != NULL)
+        fail("able to iterate over the end");
+
+    /* invalid UTF-8 in key */
+    if(!json_object_set(object, "a\xefz", string))
+        fail("able to set invalid unicode key");
+
+    value = json_object_get(object, "a");
+    if(!value)
+        fail("no value for existing key");
+    if(value != string)
+        fail("got different value than what was added");
+
+    /* "a", "lp" and "px" collide in a five-bucket hashtable */
+    if(json_object_set(object, "b", string) ||
+       json_object_set(object, "lp", string) ||
+       json_object_set(object, "px", string))
+        fail("unable to set value");
+
+    value = json_object_get(object, "a");
+    if(!value)
+        fail("no value for existing key");
+    if(value != string)
+        fail("got different value than what was added");
+
+    if(json_object_set(object, "a", other_string))
+        fail("unable to replace an existing key");
+
+    value = json_object_get(object, "a");
+    if(!value)
+        fail("no value for existing key");
+    if(value != other_string)
+        fail("got different value than what was set");
+
+    if(!json_object_del(object, "nonexisting"))
+        fail("able to delete a nonexisting key");
+
+    if(json_object_del(object, "px"))
+        fail("unable to delete an existing key");
+
+    if(json_object_del(object, "a"))
+        fail("unable to delete an existing key");
+
+    if(json_object_del(object, "lp"))
+        fail("unable to delete an existing key");
+
+
+    /* add many keys to initiate rehashing */
+
+    if(json_object_set(object, "a", string))
+        fail("unable to set value");
+
+    if(json_object_set(object, "lp", string))
+        fail("unable to set value");
+
+    if(json_object_set(object, "px", string))
+        fail("unable to set value");
+
+    if(json_object_set(object, "c", string))
+        fail("unable to set value");
+
+    if(json_object_set(object, "d", string))
+        fail("unable to set value");
+
+    if(json_object_set(object, "e", string))
+        fail("unable to set value");
+
+
+    if(json_object_set_new(object, "foo", json_integer(123)))
+        fail("unable to set new value");
+
+    value = json_object_get(object, "foo");
+    if(!json_is_integer(value) || json_integer_value(value) != 123)
+        fail("json_object_set_new works incorrectly");
+
+    if(!json_object_set_new(object, NULL, json_integer(432)))
+        fail("able to set_new NULL key");
+
+    if(!json_object_set_new(object, "foo", NULL))
+        fail("able to set_new NULL value");
+
+    json_decref(string);
+    json_decref(other_string);
+    json_decref(object);
+}
+
+int main()
+{
+    test_misc();
+    test_clear();
+    test_update();
+    test_circular();
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_simple.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_simple.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_simple.c (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/test_simple.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <string.h>
+#include <jansson.h>
+#include "util.h"
+
+/* Call the simple functions not covered by other tests of the public API */
+int main()
+{
+    json_t *value;
+
+    value = json_integer(1);
+    if(json_typeof(value) != JSON_INTEGER)
+        fail("json_typeof failed");
+
+    if(json_is_object(value))
+        fail("json_is_object failed");
+
+    if(json_is_array(value))
+        fail("json_is_array failed");
+
+    if(json_is_string(value))
+        fail("json_is_string failed");
+
+    if(!json_is_integer(value))
+        fail("json_is_integer failed");
+
+    if(json_is_real(value))
+        fail("json_is_real failed");
+
+    if(!json_is_number(value))
+        fail("json_is_number failed");
+
+    if(json_is_true(value))
+        fail("json_is_true failed");
+
+    if(json_is_false(value))
+        fail("json_is_false failed");
+
+    if(json_is_boolean(value))
+        fail("json_is_boolean failed");
+
+    if(json_is_null(value))
+        fail("json_is_null failed");
+
+    json_decref(value);
+
+
+    value = json_string("foo");
+    if(!value)
+        fail("json_string failed");
+    if(strcmp(json_string_value(value), "foo"))
+        fail("invalid string value");
+
+    if(json_string_set(value, "bar"))
+        fail("json_string_set failed");
+    if(strcmp(json_string_value(value), "bar"))
+        fail("invalid string value");
+
+    json_decref(value);
+
+    value = json_string(NULL);
+    if(value)
+        fail("json_string(NULL) failed");
+
+    /* invalid UTF-8  */
+    value = json_string("a\xefz");
+    if(value)
+        fail("json_string(<invalid utf-8>) failed");
+
+
+    value = json_integer(123);
+    if(!value)
+        fail("json_integer failed");
+    if(json_integer_value(value) != 123)
+        fail("invalid integer value");
+    if(json_number_value(value) != 123.0)
+        fail("invalid number value");
+
+    if(json_integer_set(value, 321))
+        fail("json_integer_set failed");
+    if(json_integer_value(value) != 321)
+        fail("invalid integer value");
+    if(json_number_value(value) != 321.0)
+        fail("invalid number value");
+
+    json_decref(value);
+
+    value = json_real(123.123);
+    if(!value)
+        fail("json_real failed");
+    if(json_real_value(value) != 123.123)
+        fail("invalid integer value");
+    if(json_number_value(value) != 123.123)
+        fail("invalid number value");
+
+    if(json_real_set(value, 321.321))
+        fail("json_real_set failed");
+    if(json_real_value(value) != 321.321)
+        fail("invalid real value");
+    if(json_number_value(value) != 321.321)
+        fail("invalid number value");
+
+    json_decref(value);
+
+    value = json_true();
+    if(!value)
+        fail("json_true failed");
+    json_decref(value);
+
+    value = json_false();
+    if(!value)
+        fail("json_false failed");
+    json_decref(value);
+
+    value = json_null();
+    if(!value)
+        fail("json_null failed");
+    json_decref(value);
+
+    return 0;
+}

Added: hadoop/avro/trunk/lang/c/jansson/test/testprogs/util.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/jansson/test/testprogs/util.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/jansson/test/testprogs/util.h (added)
+++ hadoop/avro/trunk/lang/c/jansson/test/testprogs/util.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <pe...@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#ifndef TESTPROGS_UTIL_H
+#define TESTPROGS_UTIL_H
+
+#include <stdlib.h>
+
+#define fail(msg)                                                \
+    do {                                                         \
+        fprintf(stderr, "%s:%s:%d: %s\n",                        \
+                __FILE__, __FUNCTION__, __LINE__, msg);          \
+        exit(1);                                                 \
+    } while(0)
+
+#endif

Added: hadoop/avro/trunk/lang/c/src/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/Makefile.am?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/Makefile.am (added)
+++ hadoop/avro/trunk/lang/c/src/Makefile.am Sat Jan 16 01:52:24 2010
@@ -0,0 +1,15 @@
+# -pedantic
+AM_CPPFLAGS=-I$(top_srcdir)/jansson/src
+AM_CFLAGS=-Wall
+ACLOCAL_AMFLAGS=-I m4
+
+include_HEADERS = avro.h
+
+lib_LTLIBRARIES = libavro.la
+libavro_la_SOURCES = st.c st.h schema.c schema.h schema_printf.c schema_equal.c datum.c datum.h \
+io.c dump.c dump.h encoding_binary.c container_of.h queue.h encoding.h
+libavro_la_LIBADD = $(top_builddir)/jansson/src/.libs/libjansson.a
+libavro_la_LDFLAGS = \
+        -version-info $(LIBAVRO_VERSION) \
+        -release $(VERSION) \
+        -export-dynamic

Added: hadoop/avro/trunk/lang/c/src/avro.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/avro.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/avro.h (added)
+++ hadoop/avro/trunk/lang/c/src/avro.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,209 @@
+/*
+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.
+*/
+#ifndef AVRO_H
+#define AVRO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+
+  enum avro_type_t
+  {
+    AVRO_STRING,
+    AVRO_BYTES,
+    AVRO_INT,
+    AVRO_LONG,
+    AVRO_FLOAT,
+    AVRO_DOUBLE,
+    AVRO_BOOLEAN,
+    AVRO_NULL,
+    AVRO_RECORD,
+    AVRO_ENUM,
+    AVRO_FIXED,
+    AVRO_MAP,
+    AVRO_ARRAY,
+    AVRO_UNION,
+    AVRO_LINK
+  };
+  typedef enum avro_type_t avro_type_t;
+
+  enum avro_class_t
+  {
+    AVRO_SCHEMA,
+    AVRO_DATUM
+  };
+  typedef enum avro_class_t avro_class_t;
+
+  struct avro_obj_t
+  {
+    avro_type_t type;
+    avro_class_t class_type;
+    unsigned long refcount;
+  };
+
+
+
+#define avro_classof(obj)     ((obj)->class_type)
+#define is_avro_schema(obj)   (obj && avro_classof(obj) == AVRO_SCHEMA)
+#define is_avro_datum(obj)    (obj && avro_classof(obj) == AVRO_DATUM)
+
+#define avro_typeof(obj)      ((obj)->type)
+#define is_avro_string(obj)   (obj && avro_typeof(obj) == AVRO_STRING)
+#define is_avro_bytes(obj)    (obj && avro_typeof(obj) == AVRO_BYTES)
+#define is_avro_int(obj)      (obj && avro_typeof(obj) == AVRO_INT)
+#define is_avro_long(obj)     (obj && avro_typeof(obj) == AVRO_LONG)
+#define is_avro_float(obj)    (obj && avro_typeof(obj) == AVRO_FLOAT)
+#define is_avro_double(obj)   (obj && avro_typeof(obj) == AVRO_DOUBLE)
+#define is_avro_boolean(obj)  (obj && avro_typeof(obj) == AVRO_BOOLEAN)
+#define is_avro_null(obj)     (obj && avro_typeof(obj) == AVRO_NULL)
+#define is_avro_primitive(obj)(is_avro_string(obj) \
+                             ||is_avro_bytes(obj) \
+                             ||is_avro_int(obj) \
+                             ||is_avro_long(obj) \
+                             ||is_avro_float(obj) \
+                             ||is_avro_double(obj) \
+                             ||is_avro_boolean(obj) \
+                             ||is_avro_null(obj))
+#define is_avro_record(obj)   (obj && avro_typeof(obj) == AVRO_RECORD)
+#define is_avro_enum(obj)     (obj && avro_typeof(obj) == AVRO_ENUM)
+#define is_avro_fixed(obj)    (obj && avro_typeof(obj) == AVRO_FIXED)
+#define is_avro_named_type(obj)(is_avro_record(obj) \
+                              ||is_avro_enum(obj) \
+                              ||is_avro_fixed(obj))
+#define is_avro_map(obj)      (obj && avro_typeof(obj) == AVRO_MAP)
+#define is_avro_array(obj)    (obj && avro_typeof(obj) == AVRO_ARRAY)
+#define is_avro_union(obj)    (obj && avro_typeof(obj) == AVRO_UNION)
+#define is_avro_complex_type(obj) (!(is_avro_primitive(obj) || is_avro_link(obj)))
+#define is_avro_link(obj)     (obj && avro_typeof(obj) == AVRO_LINK)
+
+  /* schema */
+  typedef struct avro_obj_t *avro_schema_t;
+
+  avro_schema_t avro_schema_string (void);
+  avro_schema_t avro_schema_bytes (void);
+  avro_schema_t avro_schema_int (void);
+  avro_schema_t avro_schema_long (void);
+  avro_schema_t avro_schema_float (void);
+  avro_schema_t avro_schema_double (void);
+  avro_schema_t avro_schema_boolean (void);
+  avro_schema_t avro_schema_null (void);
+
+  avro_schema_t avro_schema_record (const char *name);
+  avro_schema_t avro_schema_record_field_get (const avro_schema_t record,
+					      const char *field_name);
+  int avro_schema_record_field_append (const avro_schema_t record,
+				       const char *field_name,
+				       const avro_schema_t type);
+
+  avro_schema_t avro_schema_enum (const char *name);
+  int avro_schema_enum_symbol_append (const avro_schema_t enump,
+				      const char *symbol);
+
+  avro_schema_t avro_schema_fixed (const char *name, const size_t len);
+  avro_schema_t avro_schema_map (const avro_schema_t values);
+  avro_schema_t avro_schema_array (const avro_schema_t items);
+
+  avro_schema_t avro_schema_union (void);
+  int avro_schema_union_append (const avro_schema_t union_schema,
+				const avro_schema_t schema);
+
+  avro_schema_t avro_schema_link (avro_schema_t schema);
+
+  typedef struct avro_schema_error_t *avro_schema_error_t;
+  int avro_schema_from_json (const char *jsontext, size_t len,
+			     avro_schema_t * schema,
+			     avro_schema_error_t * error);
+
+  int avro_schema_to_specific (avro_schema_t schema, const char *prefix);
+
+  const char *avro_schema_name (const avro_schema_t schema);
+  avro_schema_t avro_schema_copy (avro_schema_t schema);
+  int avro_schema_equal (avro_schema_t a, avro_schema_t b);
+
+  void avro_schema_printf (avro_schema_t schema, FILE * fp);
+
+  /* value */
+  typedef struct avro_obj_t *avro_datum_t;
+  avro_datum_t avro_string (const char *str);
+  avro_datum_t avro_bytes (const char *buf, int64_t len);
+  avro_datum_t avro_int (int32_t i);
+  avro_datum_t avro_long (int64_t l);
+  avro_datum_t avro_float (float f);
+  avro_datum_t avro_double (double d);
+  avro_datum_t avro_boolean (int8_t i);
+  avro_datum_t avro_null (void);
+
+  avro_datum_t avro_record (const char *name);
+  avro_datum_t avro_record_field_get (const avro_datum_t record,
+				      const char *field_name);
+  int avro_record_field_append (const avro_datum_t record,
+				const char *field_name,
+				const avro_datum_t value);
+
+  avro_datum_t avro_enum (const char *name, const char *symbol);
+
+  avro_datum_t avro_fixed (const char *name, const size_t len,
+			   const char *bytes);
+
+  avro_datum_t avro_map (const avro_datum_t values);
+  avro_datum_t avro_array (const avro_datum_t items);
+
+  avro_datum_t avro_union (void);
+  int avro_union_append (const avro_datum_t union_value,
+			 const avro_datum_t value);
+
+  avro_datum_t avro_datum_incref (avro_datum_t value);
+  void avro_datum_decref (avro_datum_t value);
+
+  void avro_datum_print (avro_datum_t value, FILE * fp);
+
+/* IO */
+  typedef struct avro_reader_t *avro_reader_t;
+  typedef struct avro_writer_t *avro_writer_t;
+
+  avro_reader_t avro_reader_file (FILE * fp);
+  avro_writer_t avro_writer_file (FILE * fp);
+  avro_reader_t avro_reader_memory (const char *buf, size_t len);
+  avro_writer_t avro_writer_memory (const char *buf, size_t len);
+
+  int avro_read (avro_reader_t reader, void *buf, int64_t len);
+  int avro_skip (avro_reader_t reader, int64_t len);
+  int avro_write (avro_writer_t writer, void *buf, int64_t len);
+  int avro_flush (avro_writer_t writer);
+
+  void avro_reader_free (avro_reader_t reader);
+  void avro_writer_free (avro_writer_t writer);
+
+/* Datum */
+  int avro_read_data (avro_reader_t reader, avro_schema_t writer_schema,
+		      avro_schema_t reader_schema, avro_datum_t * datum);
+  int avro_write_data (avro_writer_t writer, avro_schema_t writer_schema,
+		       avro_datum_t datum);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: hadoop/avro/trunk/lang/c/src/container_of.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/container_of.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/container_of.h (added)
+++ hadoop/avro/trunk/lang/c/src/container_of.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,25 @@
+/*
+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.
+*/
+#ifndef CONTAINER_OF_H
+#define CONTAINER_OF_H
+
+#define container_of(ptr_, type_, member_)  \
+    ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
+
+#endif

Added: hadoop/avro/trunk/lang/c/src/datum.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum.c (added)
+++ hadoop/avro/trunk/lang/c/src/datum.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,533 @@
+/*
+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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "avro.h"
+#include "schema.h"
+#include "datum.h"
+#include "encoding.h"
+
+static void
+avro_datum_init (avro_datum_t datum, avro_type_t type)
+{
+  datum->type = type;
+  datum->class_type = AVRO_DATUM;
+  datum->refcount = 1;
+}
+
+avro_datum_t
+avro_string (const char *str)
+{
+  struct avro_string_datum_t *string_datum =
+    malloc (sizeof (struct avro_string_datum_t));
+  if (!string_datum)
+    {
+      return NULL;
+    }
+  string_datum->s = strdup (str);
+
+  avro_datum_init (&string_datum->obj, AVRO_STRING);
+  return &string_datum->obj;
+}
+
+avro_datum_t
+avro_bytes (const char *buf, int64_t len)
+{
+  struct avro_bytes_datum_t *bytes_datum =
+    malloc (sizeof (struct avro_bytes_datum_t));
+  if (!bytes_datum)
+    {
+      return NULL;
+    }
+  bytes_datum->buf = malloc (len);
+  if (!bytes_datum->buf)
+    {
+      free (bytes_datum);
+      return NULL;
+    }
+  memcpy (bytes_datum->buf, buf, len);
+  bytes_datum->len = len;
+
+  avro_datum_init (&bytes_datum->obj, AVRO_BYTES);
+  return &bytes_datum->obj;
+}
+
+avro_datum_t
+avro_int (int32_t i)
+{
+  struct avro_int_datum_t *int_datum =
+    malloc (sizeof (struct avro_int_datum_t));
+  if (!int_datum)
+    {
+      return NULL;
+    }
+  int_datum->i = i;
+
+  avro_datum_init (&int_datum->obj, AVRO_INT);
+  return &int_datum->obj;
+}
+
+avro_datum_t
+avro_long (int64_t l)
+{
+  struct avro_long_datum_t *long_datum =
+    malloc (sizeof (struct avro_long_datum_t));
+  if (!long_datum)
+    {
+      return NULL;
+    }
+  long_datum->l = l;
+
+  avro_datum_init (&long_datum->obj, AVRO_LONG);
+  return &long_datum->obj;
+}
+
+avro_datum_t
+avro_float (float f)
+{
+  struct avro_float_datum_t *float_datum =
+    malloc (sizeof (struct avro_float_datum_t));
+  if (!float_datum)
+    {
+      return NULL;
+    }
+  float_datum->f = f;
+
+  avro_datum_init (&float_datum->obj, AVRO_FLOAT);
+  return &float_datum->obj;
+}
+
+avro_datum_t
+avro_double (double d)
+{
+  struct avro_double_datum_t *double_datum =
+    malloc (sizeof (struct avro_double_datum_t));
+  if (!double_datum)
+    {
+      return NULL;
+    }
+  double_datum->d = d;
+
+  avro_datum_init (&double_datum->obj, AVRO_DOUBLE);
+  return &double_datum->obj;
+}
+
+avro_datum_t
+avro_boolean (int8_t i)
+{
+  struct avro_boolean_datum_t *boolean_datum =
+    malloc (sizeof (struct avro_boolean_datum_t));
+  if (!boolean_datum)
+    {
+      return NULL;
+    }
+  boolean_datum->i = i;
+
+  avro_datum_init (&boolean_datum->obj, AVRO_BOOLEAN);
+  return &boolean_datum->obj;
+}
+
+avro_datum_t
+avro_null (void)
+{
+  static struct avro_obj_t obj = {
+    .type = AVRO_NULL,
+    .class_type = AVRO_DATUM,
+    .refcount = 1
+  };
+  return &obj;
+}
+
+avro_datum_t
+avro_record (const char *name)
+{
+  /* TODO */
+  return NULL;
+}
+
+avro_datum_t
+avro_record_field_get (const avro_datum_t record, const char *field_name)
+{
+  /* TODO */
+  return NULL;
+}
+
+int
+avro_record_field_append (const avro_datum_t record,
+			  const char *field_name, const avro_datum_t value)
+{
+  /* TODO */
+  return 1;
+}
+
+avro_datum_t
+avro_enum (const char *name, const char *symbol)
+{
+  /* TODO */
+  return NULL;
+}
+
+int
+avro_enum_symbol_append (const avro_datum_t enum_value, const char *symbol)
+{
+  /* TODO */
+  return 1;
+}
+
+avro_datum_t
+avro_fixed_from_schema (struct schema_fixed_t * schema)
+{
+  struct avro_fixed_datum_t *datum;
+  if (!schema)
+    {
+      return NULL;
+    }
+  datum = malloc (sizeof (struct avro_fixed_datum_t));
+  if (!datum)
+    {
+      return NULL;
+    }
+  avro_schema_incref (&schema->obj);
+  datum->schema = schema;
+  avro_datum_init (&datum->obj, AVRO_FIXED);
+  return &datum->obj;
+}
+
+avro_datum_t
+avro_fixed (const char *name, const size_t len, const char *bytes)
+{
+  struct avro_fixed_datum_t *fixed;
+  avro_datum_t datum;
+  avro_schema_t schema = avro_schema_fixed (name, len);
+  if (!schema)
+    {
+      return NULL;
+    }
+  datum = avro_fixed_from_schema (schema);
+  avro_schema_decref (schema);	/* only want one reference */
+  if (!datum)
+    {
+      return NULL;
+    }
+  fixed = avro_datum_to_fixed (datum);
+  /* TODO */
+  return datum;
+}
+
+avro_datum_t
+avro_map (const avro_datum_t values)
+{
+  /* TODO */
+  return NULL;
+}
+
+avro_datum_t
+avro_array (const avro_datum_t items)
+{
+  /* TODO */
+  return NULL;
+}
+
+avro_datum_t
+avro_union (void)
+{
+  /* TODO */
+  return NULL;
+}
+
+int
+avro_union_append (const avro_datum_t union_value, const avro_datum_t value)
+{
+  /* TODO */
+  return 1;
+}
+
+avro_datum_t
+avro_datum_incref (avro_datum_t value)
+{
+  /* TODO */
+  return NULL;
+}
+
+void
+avro_datum_decref (avro_datum_t value)
+{
+
+}
+
+void
+avro_datum_print (avro_datum_t value, FILE * fp)
+{
+
+}
+
+static int
+schema_match (avro_schema_t writers_schema, avro_schema_t readers_schema)
+{
+  if (is_avro_union (writers_schema) || is_avro_union (readers_schema))
+    {
+      return 1;
+    }
+  /* union */
+  else if (is_avro_primitive (writers_schema)
+	   && is_avro_primitive (readers_schema)
+	   && avro_typeof (writers_schema) == avro_typeof (readers_schema))
+    {
+      return 1;
+    }
+  /* record */
+  else if (is_avro_record (writers_schema) && is_avro_record (readers_schema)
+	   && strcmp (avro_schema_name (writers_schema),
+		      avro_schema_name (readers_schema)) == 0)
+    {
+      return 1;
+    }
+  /* fixed */
+  else if (is_avro_fixed (writers_schema) && is_avro_fixed (readers_schema)
+	   && strcmp (avro_schema_name (writers_schema),
+		      avro_schema_name (readers_schema)) == 0
+	   && (avro_schema_to_fixed (writers_schema))->size ==
+	   (avro_schema_to_fixed (readers_schema))->size)
+    {
+      return 1;
+    }
+  /* enum */
+  else if (is_avro_enum (writers_schema) && is_avro_enum (readers_schema)
+	   && strcmp (avro_schema_name (writers_schema),
+		      avro_schema_name (readers_schema)) == 0)
+    {
+      return 1;
+    }
+  /* map */
+  else if (is_avro_map (writers_schema) && is_avro_map (readers_schema)
+	   && avro_typeof ((avro_schema_to_map (writers_schema))->values)
+	   == avro_typeof ((avro_schema_to_map (readers_schema))->values))
+    {
+      return 1;
+    }
+  /* array */
+  else if (is_avro_array (writers_schema) && is_avro_array (readers_schema)
+	   && avro_typeof ((avro_schema_to_array (writers_schema))->items)
+	   == avro_typeof ((avro_schema_to_array (readers_schema))->items))
+    {
+      return 1;
+    }
+
+  /* handle schema promotion */
+  else if (is_avro_int (writers_schema)
+	   && (is_avro_long (readers_schema) || is_avro_float (readers_schema)
+	       || is_avro_double (readers_schema)))
+    {
+      return 1;
+    }
+  else if (is_avro_long (writers_schema)
+	   && (is_avro_float (readers_schema)
+	       && is_avro_double (readers_schema)))
+    {
+      return 1;
+    }
+  else if (is_avro_float (writers_schema) && is_avro_double (readers_schema))
+    {
+      return 1;
+    }
+  return 0;
+}
+
+static int
+read_fixed (avro_reader_t reader, const avro_encoding_t * enc,
+	    avro_schema_t writers_schema, avro_schema_t readers_schema,
+	    avro_datum_t * datum)
+{
+  return 1;
+}
+
+static int
+read_enum (avro_reader_t reader, const avro_encoding_t * enc,
+	   avro_schema_t writers_schema, avro_schema_t readers_schema,
+	   avro_datum_t * datum)
+{
+  return 1;
+}
+
+static int
+read_array (avro_reader_t reader, const avro_encoding_t * enc,
+	    avro_schema_t writers_schema, avro_schema_t readers_schema,
+	    avro_datum_t * datum)
+{
+  return 1;
+}
+
+static int
+read_map (avro_reader_t reader, const avro_encoding_t * enc,
+	  avro_schema_t writers_schema, avro_schema_t readers_schema,
+	  avro_datum_t * datum)
+{
+  return 1;
+}
+
+static int
+read_union (avro_reader_t reader, const avro_encoding_t * enc,
+	    avro_schema_t writers_schema, avro_schema_t readers_schema,
+	    avro_datum_t * datum)
+{
+  return 1;
+}
+
+static int
+read_record (avro_reader_t reader, const avro_encoding_t * enc,
+	     avro_schema_t writers_schema, avro_schema_t readers_schema,
+	     avro_datum_t * datum)
+{
+  return 1;
+}
+
+int
+avro_read_data (avro_reader_t reader, avro_schema_t writers_schema,
+		avro_schema_t readers_schema, avro_datum_t * datum)
+{
+  int rval = EINVAL;
+  const avro_encoding_t *enc = &avro_binary_encoding;
+
+  if (!reader || !schema_match (writers_schema, readers_schema) || !datum)
+    {
+      return EINVAL;
+    }
+
+  /* schema resolution */
+  if (!is_avro_union (writers_schema) && is_avro_union (readers_schema))
+    {
+      struct union_schema_t *s;
+      struct schema_union_t *union_schema =
+	avro_schema_to_union (readers_schema);
+
+      for (s = TAILQ_FIRST (&union_schema->schemas);
+	   s != NULL; s = TAILQ_NEXT (s, schemas))
+	{
+	  if (schema_match (writers_schema, s->schema))
+	    {
+	      return avro_read_data (reader, writers_schema, s->schema,
+				     datum);
+	    }
+	}
+      return EINVAL;
+    }
+
+  switch (avro_typeof (writers_schema))
+    {
+    case AVRO_NULL:
+      rval = enc->read_null (reader);
+      break;
+
+    case AVRO_BOOLEAN:
+      {
+	int8_t b;
+	rval = enc->read_boolean (reader, &b);
+	*datum = avro_boolean (b);
+      }
+      break;
+
+    case AVRO_STRING:
+      {
+	char *s;
+	rval = enc->read_string (reader, &s);
+	*datum = avro_string (s);
+      }
+      break;
+
+    case AVRO_INT:
+      {
+	int32_t i;
+	rval = enc->read_int (reader, &i);
+	*datum = avro_int (i);
+      }
+      break;
+
+    case AVRO_LONG:
+      {
+	int64_t l;
+	rval = enc->read_long (reader, &l);
+	*datum = avro_long (l);
+      }
+      break;
+
+    case AVRO_FLOAT:
+      {
+	float f;
+	rval = enc->read_float (reader, &f);
+	*datum = avro_float (f);
+      }
+      break;
+
+    case AVRO_DOUBLE:
+      {
+	double d;
+	rval = enc->read_double (reader, &d);
+	*datum = avro_double (d);
+      }
+      break;
+
+    case AVRO_BYTES:
+      {
+	char *bytes;
+	int64_t len;
+	rval = enc->read_bytes (reader, &bytes, &len);
+	*datum = avro_bytes (bytes, len);
+      }
+      break;
+
+    case AVRO_FIXED:
+      rval = read_fixed (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_ENUM:
+      rval = read_enum (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_ARRAY:
+      rval = read_array (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_MAP:
+      rval = read_map (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_UNION:
+      rval = read_union (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_RECORD:
+      rval = read_record (reader, enc, writers_schema, readers_schema, datum);
+      break;
+
+    case AVRO_LINK:
+      /* TODO */
+      break;
+    }
+
+  return rval;
+}
+
+int
+avro_write_data (avro_writer_t writer, avro_schema_t writer_schema,
+		 avro_datum_t datum)
+{
+  /* TODO */
+  return 1;
+}

Added: hadoop/avro/trunk/lang/c/src/datum.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum.h (added)
+++ hadoop/avro/trunk/lang/c/src/datum.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,84 @@
+/*
+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.
+*/
+
+#ifndef AVRO_DATUM_H
+#define AVRO_DATUM_H
+#include "avro.h"		/* for avro_schema_t */
+#include "container_of.h"
+
+struct avro_string_datum_t
+{
+  struct avro_obj_t obj;
+  char *s;
+};
+
+struct avro_bytes_datum_t
+{
+  struct avro_obj_t obj;
+  char *buf;
+  size_t len;
+};
+
+struct avro_int_datum_t
+{
+  struct avro_obj_t obj;
+  int32_t i;
+};
+
+struct avro_long_datum_t
+{
+  struct avro_obj_t obj;
+  int64_t l;
+};
+
+struct avro_float_datum_t
+{
+  struct avro_obj_t obj;
+  float f;
+};
+
+struct avro_double_datum_t
+{
+  struct avro_obj_t obj;
+  double d;
+};
+
+struct avro_boolean_datum_t
+{
+  struct avro_obj_t obj;
+  int8_t i;
+};
+
+struct avro_fixed_datum_t
+{
+  struct avro_obj_t obj;
+  struct schema_fixed_t *schema;
+  char *bytes;
+};
+
+#define avro_datum_to_string(datum_)    container_of(datum_, struct avro_string_datum_t, obj)
+#define avro_datum_to_bytes(datum_)     container_of(datum_, struct avro_bytes_datum_t, obj)
+#define avro_datum_to_int(datum_)       container_of(datum_, struct avro_int_datum_t, obj)
+#define avro_datum_to_long(datum_)      container_of(datum_, struct avro_long_datum_t, obj)
+#define avro_datum_to_float(datum_)     container_of(datum_, struct avro_float_datum_t, obj)
+#define avro_datum_to_double(datum_)    container_of(datum_, struct avro_double_datum_t, obj)
+#define avro_datum_to_boolean(datum_)   container_of(datum_, struct avro_boolean_datum_t, obj)
+#define avro_datum_to_fixed(datum_)     container_of(datum_, struct avro_fixed_datum_t, obj)
+
+#endif

Added: hadoop/avro/trunk/lang/c/src/dump.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/dump.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/dump.c (added)
+++ hadoop/avro/trunk/lang/c/src/dump.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,70 @@
+/*
+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 "dump.h"
+#include <ctype.h>
+#include <string.h>
+#include <stdint.h>
+
+static void
+dump_line (FILE * out, const caddr_t addr, const long len)
+{
+  int i;
+  fprintf (out, "|");
+  for (i = 0; i < 16; i++)
+    {
+      if (i < len)
+	{
+	  fprintf (out, " %02X", ((uint8_t *) addr)[i]);
+	}
+      else
+	{
+	  fprintf (out, " ..");
+	}
+      if (!((i + 1) % 8))
+	{
+	  fprintf (out, " |");
+	}
+    }
+  fprintf (out, "\t");
+  for (i = 0; i < 16; i++)
+    {
+      char c = 0x7f & ((uint8_t *) addr)[i];
+      if (i < len && isprint (c))
+	{
+	  fprintf (out, "%c", c);
+	}
+      else
+	{
+	  fprintf (out, ".");
+	}
+    }
+}
+
+void
+dump (FILE * out, const caddr_t addr, const long len)
+{
+  int i;
+  for (i = 0; i < len; i += 16)
+    {
+      dump_line (out, addr + i, (len - i) < 16 ? (len - i) : 16);
+      fprintf (out, "\n");
+    }
+  fflush (out);
+}

Added: hadoop/avro/trunk/lang/c/src/dump.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/dump.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/dump.h (added)
+++ hadoop/avro/trunk/lang/c/src/dump.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,28 @@
+/*
+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.
+*/
+
+#ifndef DUMP_H
+#define DUMP_H
+
+#include <stdio.h>
+#include <sys/types.h>
+
+void dump (FILE * out, const caddr_t addr, const long len);
+
+#endif