aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2009-10-27 17:46:57 +0200
committerPetri Lehtinen <petri@digip.org>2009-10-27 17:56:02 +0200
commitf243930b6843295b81a4e4025497e40f19ff53ac (patch)
treee0264f44ed83067650f8bf5811c346cc164af0c2 /test
parent15d992cb6a6eeab8c2f4c7d00fa06a52fca62287 (diff)
downloadjansson-f243930b6843295b81a4e4025497e40f19ff53ac.zip
jansson-f243930b6843295b81a4e4025497e40f19ff53ac.tar.gz
jansson-f243930b6843295b81a4e4025497e40f19ff53ac.tar.bz2
json_load_file: Initialize the error struct properly
Failing to do this has the effect that the error message is not returned when the input file cannot be opened (e.g. if it doesn't exist). Thanks to Martin Vopatek for reporting.
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore1
-rw-r--r--test/testprogs/Makefile.am3
-rw-r--r--test/testprogs/test_load.c24
3 files changed, 27 insertions, 1 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 09dfb4d..ac70552 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -3,6 +3,7 @@ loads_dumps
load_file_dump_file
testlogs
testprogs/test_array
+testprogs/test_load
testprogs/test_number
testprogs/test_object
testprogs/test_simple
diff --git a/test/testprogs/Makefile.am b/test/testprogs/Makefile.am
index 400a998..41807ed 100644
--- a/test/testprogs/Makefile.am
+++ b/test/testprogs/Makefile.am
@@ -1,6 +1,7 @@
-check_PROGRAMS = test_array test_simple test_number test_object
+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
diff --git a/test/testprogs/test_load.c b/test/testprogs/test_load.c
new file mode 100644
index 0000000..4d8fa88
--- /dev/null
+++ b/test/testprogs/test_load.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2009 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;
+ 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;
+}