aboutsummaryrefslogtreecommitdiff
path: root/test/suites/api/test_dump.c
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2010-05-12 15:41:09 +0300
committerPetri Lehtinen <petri@digip.org>2010-05-14 09:05:56 +0300
commit2630980f49088a06c32cebdc866e4f518106af29 (patch)
tree89c38ee9c5287d604ce49ce2bbaea9ec8e7600b2 /test/suites/api/test_dump.c
parentf9475f9577bd62b4e1586fbefcbcf70a460b9e61 (diff)
downloadjansson-2630980f49088a06c32cebdc866e4f518106af29.zip
jansson-2630980f49088a06c32cebdc866e4f518106af29.tar.gz
jansson-2630980f49088a06c32cebdc866e4f518106af29.tar.bz2
Zero the visited flag after encoding an empty array or object
Encoding an empty array or object worked, but encoding it again (possibly after adding some items) failed, because the visited flag (used for detecting circular references) wasn't zeroed.
Diffstat (limited to 'test/suites/api/test_dump.c')
-rw-r--r--test/suites/api/test_dump.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c
new file mode 100644
index 0000000..c471159
--- /dev/null
+++ b/test/suites/api/test_dump.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2009, 2010 Petri Lehtinen <petri@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;
+ char *result;
+
+ /* Encode an empty object/array, add an item, encode again */
+
+ json = json_object();
+ result = json_dumps(json, 0);
+ if(!result || strcmp(result, "{}"))
+ fail("json_dumps failed");
+
+ json_object_set_new(json, "foo", json_integer(5));
+ result = json_dumps(json, 0);
+ if(!result || strcmp(result, "{\"foo\": 5}"))
+ fail("json_dumps failed");
+
+ json_decref(json);
+
+ json = json_array();
+ result = json_dumps(json, 0);
+ if(!result || strcmp(result, "[]"))
+ fail("json_dumps failed");
+ free(result);
+
+ json_array_append_new(json, json_integer(5));
+ result = json_dumps(json, 0);
+ if(!result || strcmp(result, "[5]"))
+ fail("json_dumps failed");
+ free(result);
+
+ json_decref(json);
+
+ return 0;
+}