Browse files

add a custom api test facility

  • Loading branch information...
1 parent cf658fa commit 71ce86b48b60040835531493465be02923b21acb @lloyd committed Feb 15, 2014
View
6 CMakeLists.txt
@@ -74,6 +74,8 @@ INCLUDE(YAJLDoc.cmake)
# a test target
ADD_CUSTOM_TARGET(test
- ./run_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/test/yajl_test
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
+ ./run_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/test/parsing/yajl_test
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/parsing)
+ADD_CUSTOM_TARGET(test-api ${CMAKE_CURRENT_SOURCE_DIR}/test/api/run_tests.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/api)
View
2 src/yajl_gen.c
@@ -172,7 +172,7 @@ yajl_gen_free(yajl_gen g)
if (++(g->depth) >= YAJL_MAX_DEPTH) return yajl_max_depth_exceeded;
#define DECREMENT_DEPTH \
- if (--(g->depth) >= YAJL_MAX_DEPTH) return yajl_gen_error;
+ if (--(g->depth) >= YAJL_MAX_DEPTH) return yajl_gen_generation_complete;
#define APPENDED_ATOM \
switch (g->state[g->depth]) { \
View
16 test/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright (c) 2007-2014, Lloyd Hilaiel <lloyd@hilaiel.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ADD_SUBDIRECTORY(parsing)
+ADD_SUBDIRECTORY(api)
View
25 test/api/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright (c) 2007-2014, Lloyd Hilaiel <lloyd@hilaiel.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+SET (TESTS gen-extra-close.c
+)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../../${YAJL_DIST_NAME}/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../../${YAJL_DIST_NAME}/lib)
+
+# for each test, we'll create a target, and make the api-tests target depend on it
+FOREACH (test ${TESTS})
+ GET_FILENAME_COMPONENT(testProg ${test} NAME_WE)
+ ADD_EXECUTABLE(${testProg} ${test})
+ TARGET_LINK_LIBRARIES(${testProg} yajl)
+ENDFOREACH()
View
19 test/api/gen-extra-close.c
@@ -0,0 +1,19 @@
+/* ensure that if we try to generate an extra closing brace
+ * we get the expected error */
+
+#include <yajl/yajl_gen.h>
+#include <stdio.h>
+
+#define CHK(x) if (x != yajl_gen_status_ok) return 1;
+
+int main(void) {
+ yajl_gen yg;
+ yajl_gen_status s;
+
+ yg = yajl_gen_alloc(NULL);
+ CHK(yajl_gen_map_open(yg));
+ CHK(yajl_gen_map_close(yg));
+ s = yajl_gen_map_close(yg);
+
+ return (yajl_gen_generation_complete == s);
+}
View
23 test/api/run_tests.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+echo Running api tests:
+
+tests=0
+passed=0
+
+for file in `ls`; do
+ [ ! -x $file -o -d $file ] && continue
+ tests=`expr 1 + $tests`
+ printf " %s:\t" $file
+ ./$file
+ if [ $? ]; then
+ passed=`expr 1 + $passed`
+ echo 'SUCCESS'
+ else
+ echo 'FAILURE'
+ fi
+done
+
+echo "$passed/$tests passed"
+
+exit 0
View
4 test/parsing/CMakeLists.txt
@@ -15,8 +15,8 @@
SET (SRCS yajl_test.c)
# use the library we build, duh.
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
-LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../../${YAJL_DIST_NAME}/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(yajl_test ${SRCS})
View
10 test/parsing/run_tests.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh
ECHO=`which echo`
@@ -16,13 +16,13 @@ fi
# find test binary on both platforms. allow the caller to force a
# particular test binary (useful for non-cmake build systems).
if [ -z "$testBin" ]; then
- testBin="../build/test/Release/yajl_test.exe"
+ testBin="../build/test/parsing/Release/yajl_test.exe"
if [ ! -x $testBin ] ; then
- testBin="../build/test/Debug/yajl_test.exe"
+ testBin="../build/test/parsing/Debug/yajl_test.exe"
if [ ! -x $testBin ] ; then
- testBin="../build/test/yajl_test"
+ testBin="../build/test/parsing/yajl_test"
if [ ! -x $testBin ] ; then
- ${ECHO} "cannot execute test binary: '$testBin'"
+ ${ECHO} "cannot execute test binary: '$testBin'"
exit 1;
fi
fi

0 comments on commit 71ce86b

Please sign in to comment.