Fix absolute paths in test_util_file that vary depending on where it is run.
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
#include "json_util.h"
|
#include "json_util.h"
|
||||||
|
|
||||||
static void test_read_valid_with_fd(const char *testdir);
|
static void test_read_valid_with_fd(const char *testdir);
|
||||||
static void test_read_nonexistant(const char *testdir);
|
static void test_read_nonexistant();
|
||||||
static void test_read_closed(void);
|
static void test_read_closed(void);
|
||||||
|
|
||||||
static void test_write_to_file();
|
static void test_write_to_file();
|
||||||
@@ -89,42 +89,39 @@ int main(int argc, char **argv)
|
|||||||
testdir = argv[1];
|
testdir = argv[1];
|
||||||
|
|
||||||
test_read_valid_with_fd(testdir);
|
test_read_valid_with_fd(testdir);
|
||||||
test_read_nonexistant(testdir);
|
test_read_nonexistant();
|
||||||
test_read_closed();
|
test_read_closed();
|
||||||
test_write_to_file();
|
test_write_to_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_read_valid_with_fd(const char *testdir)
|
static void test_read_valid_with_fd(const char *testdir)
|
||||||
{
|
{
|
||||||
char file_buf[4096];
|
const char *filename = "./valid.json";
|
||||||
(void)snprintf(file_buf, sizeof(file_buf), "%s/valid.json", testdir);
|
|
||||||
|
|
||||||
int d = open(file_buf, O_RDONLY, 0);
|
int d = open(filename, O_RDONLY, 0);
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FAIL: unable to open %s: %s\n", file_buf, strerror(errno));
|
fprintf(stderr, "FAIL: unable to open %s: %s\n", filename, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
json_object *jso = json_object_from_fd(d);
|
json_object *jso = json_object_from_fd(d);
|
||||||
if (jso != NULL)
|
if (jso != NULL)
|
||||||
{
|
{
|
||||||
printf("OK: json_object_from_fd(%s)=%s\n", file_buf, json_object_to_json_string(jso));
|
printf("OK: json_object_from_fd(%s)=%s\n", filename, json_object_to_json_string(jso));
|
||||||
json_object_put(jso);
|
json_object_put(jso);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FAIL: unable to parse contents of %s: %s\n", file_buf, json_util_get_last_err());
|
fprintf(stderr, "FAIL: unable to parse contents of %s: %s\n", filename, json_util_get_last_err());
|
||||||
}
|
}
|
||||||
close(d);
|
close(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_read_nonexistant(const char *testdir)
|
static void test_read_nonexistant()
|
||||||
{
|
{
|
||||||
char file_buf[4096];
|
const char *filename = "./not_present.json";
|
||||||
const char *filename = "not_present.json";
|
|
||||||
(void)snprintf(file_buf, sizeof(file_buf), "%s/%s", testdir, filename);
|
|
||||||
|
|
||||||
json_object *jso = json_object_from_file(file_buf);
|
json_object *jso = json_object_from_file(filename);
|
||||||
if (jso != NULL)
|
if (jso != NULL)
|
||||||
{
|
{
|
||||||
printf("FAIL: json_object_from_file(%s) returned %p when NULL expected\n", filename, jso);
|
printf("FAIL: json_object_from_file(%s) returned %p when NULL expected\n", filename, jso);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
OK: json_object_from_fd(/home/erh/json-c/json-c/tests/valid.json)={ "foo": 123 }
|
OK: json_object_from_fd(./valid.json)={ "foo": 123 }
|
||||||
OK: json_object_from_file(not_present.json) correctly returned NULL: json_object_from_file: error opening file /home/erh/json-c/json-c/tests/not_present.json: ERRNO=ENOENT
|
OK: json_object_from_file(./not_present.json) correctly returned NULL: json_object_from_file: error opening file ./not_present.json: ERRNO=ENOENT
|
||||||
|
|
||||||
OK: json_object_from_fd(closed_fd), expecting NULL, EBADF, got:0x0, json_object_from_fd: error reading fd 3: ERRNO=EBADF
|
OK: json_object_from_fd(closed_fd), expecting NULL, EBADF, got:0x0, json_object_from_fd: error reading fd 3: ERRNO=EBADF
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ if test -z "$srcdir"; then
|
|||||||
fi
|
fi
|
||||||
. "$srcdir/test-defs.sh"
|
. "$srcdir/test-defs.sh"
|
||||||
|
|
||||||
|
cp -f "$srcdir/valid.json" .
|
||||||
run_output_test test_util_file "$srcdir"
|
run_output_test test_util_file "$srcdir"
|
||||||
_err=$?
|
_err=$?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user