aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge Zaitsev <devnull@localhost>2010-11-24 00:54:21 +0200
committerSerge Zaitsev <devnull@localhost>2010-11-24 00:54:21 +0200
commit508bf43fa001486025b5be6fbdc3d943e3d56ac4 (patch)
treebae264bef4891c9490310aef5f1527768e5b9016
parentf88240ac2e081b94454203a2d8595b8598a037b3 (diff)
Test framework implemented
-rw-r--r--test.sh117
1 files changed, 117 insertions, 0 deletions
diff --git a/test.sh b/test.sh
new file mode 100644
index 000000000..874904744
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+#
+# Test script is organized like this:
+# o two variables (PASSED and FAILED) hold the total
+# number of passed/faled tests
+# o expect() function performs a single test. First
+# argument of the function is the variable name and
+# the second is an expected value. PASSED/FAILED
+# values are updated automatically
+#
+# Most tests look like:
+# |
+# | expect "varName" "expectedValue" << JSON_END
+# | ..json data here...
+# | JSON_END
+# |
+#
+
+PASSED=0
+FAILED=0
+
+function expect() {
+ ret=$(./jsmn_demo -t 10 -b 256 - | grep -A 1 $1 | tail -n 1 | cut -c 15-)
+ if [ "x$ret" = "x$2" ]; then
+ PASSED=$(($PASSED+1))
+ else
+ echo "Failed: $1 != $2"
+ FAILED=$(($FAILED+1))
+ fi
+}
+
+#
+# TEST SET: Basic types (simple values)
+#
+expect 'boolVar' 'true' << JSON_END
+"boolVal" : true
+JSON_END
+
+expect 'boolVar' 'false'<< JSON_END
+"boolVar" : false
+JSON_END
+
+expect 'intVar' '12345' << JSON_END
+"intVar" : 12345
+JSON_END
+
+expect 'floatVar' '12.345' << JSON_END
+"floatVar" : 12.345
+JSON_END
+
+expect 'nullVar' 'null' << JSON_END
+"nullVar" : null
+JSON_END
+
+expect 'strVar' 'hello' << JSON_END
+"strVar" : "hello"
+JSON_END
+
+#
+# TEST SET: Simple types (boundary values)
+#
+
+expect 'intVar' '0' << JSON_END
+"intVar" : 0
+JSON_END
+
+expect 'intVar' '-0' << JSON_END
+"intVar" : -0
+JSON_END
+
+expect 'floarVar' '-0.0' << JSON_END
+"floarVar" : -0.0
+JSON_END
+
+expect 'strVar' '\n\r\b\t \u1234' << JSON_END
+"strVar" : "\n\r\b\t \u1234"
+JSON_END
+
+expect 'strVar' '' << JSON_END
+"strVar" : ""
+JSON_END
+
+#
+# TEST SET: Array types
+#
+expect 'arr' '[1,2,3,4,5]' << JSON_END
+"arr" : [1,2,3,4,5]
+JSON_END
+
+expect 'arr' '[1, 2.3, "4", null, true]' << JSON_END
+"arr" : [1, 2.3, "4", null, true]
+JSON_END
+
+expect 'arr' '[]' << JSON_END
+"arr" : []
+JSON_END
+
+#
+# TEST SET: Object types
+#
+expect 'obj' '{"a":"b"}' << JSON_END
+"obj":{"a":"b"}
+JSON_END
+
+expect 'objField' 'value' << JSON_END
+{
+ "foo" : "bar",
+ "objField" : "value"
+}
+JSON_END
+
+echo
+echo "Passed: $PASSED"
+echo "Failed: $FAILED"
+echo
+