Expand test coverage

Now all public API functions are tested (at least on some level) in
the test-api suite.
This commit is contained in:
Petri Lehtinen 2009-09-06 14:06:02 +03:00
parent fd259ff68c
commit 6ffb04f0d4
3 changed files with 109 additions and 2 deletions

View File

@ -1,6 +1,7 @@
check_PROGRAMS = test_array test_number test_object check_PROGRAMS = test_array test_simple test_number test_object
test_array_SOURCES = test_array.c util.h test_array_SOURCES = test_array.c util.h
test_simple_SOURCES = test_simple.c util.h
test_number_SOURCES = test_number.c util.h test_number_SOURCES = test_number.c util.h
test_object_SOURCES = test_number.c util.h test_object_SOURCES = test_number.c util.h

View File

@ -29,6 +29,17 @@ int main()
if(json_object_set(object, "a", string)) if(json_object_set(object, "a", string))
fail("unable to set value"); fail("unable to set value");
iter = json_object_iter(object);
if(!iter)
fail("unable to get iterator");
if(strcmp(json_object_iter_key(iter), "a"))
fail("iterating failed: wrong key");
if(json_object_iter_value(iter) != string)
fail("iterating failed: wrong value");
if(json_object_iter_next(object, iter) != NULL)
fail("able to iterate over the end");
/* invalid UTF-8 in key */ /* invalid UTF-8 in key */
if(!json_object_set(object, "a\xefz", string)) if(!json_object_set(object, "a\xefz", string))
fail("able to set invalid unicode key"); fail("able to set invalid unicode key");
@ -39,7 +50,7 @@ int main()
if(value != string) if(value != string)
fail("got different value than what was added"); fail("got different value than what was added");
/* "a", "lp" and "px" collide with a five-bucket hashtable */ /* "a", "lp" and "px" collide in a five-bucket hashtable */
if(json_object_set(object, "b", string) || if(json_object_set(object, "b", string) ||
json_object_set(object, "lp", string) || json_object_set(object, "lp", string) ||
json_object_set(object, "px", string)) json_object_set(object, "px", string))

View File

@ -0,0 +1,95 @@
/*
* 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 <string.h>
#include <jansson.h>
#include "util.h"
/* Call the simple functions not covered by other tests of the public API */
int main()
{
json_t *value;
value = json_integer(1);
if(json_typeof(value) != JSON_INTEGER)
fail("json_typeof failed");
if(json_is_object(value))
fail("json_is_object failed");
if(json_is_array(value))
fail("json_is_array failed");
if(json_is_string(value))
fail("json_is_string failed");
if(!json_is_integer(value))
fail("json_is_integer failed");
if(json_is_real(value))
fail("json_is_real failed");
if(!json_is_number(value))
fail("json_is_number failed");
if(json_is_true(value))
fail("json_is_true failed");
if(json_is_false(value))
fail("json_is_false failed");
if(json_is_boolean(value))
fail("json_is_boolean failed");
if(json_is_null(value))
fail("json_is_null failed");
json_decref(value);
value = json_string("foo");
if(!value)
fail("json_string failed");
if(strcmp(json_string_value(value), "foo"))
fail("invalid string value");
json_decref(value);
value = json_integer(123);
if(!value)
fail("json_integer failed");
if(json_integer_value(value) != 123)
fail("invalid integer value");
if(json_number_value(value) != 123.0)
fail("invalid number value");
json_decref(value);
value = json_real(123.123);
if(!value)
fail("json_real failed");
if(json_real_value(value) != 123.123)
fail("invalid integer value");
if(json_number_value(value) != 123.123)
fail("invalid number value");
json_decref(value);
value = json_true();
if(!value)
fail("json_true failed");
json_decref(value);
value = json_false();
if(!value)
fail("json_false failed");
json_decref(value);
value = json_null();
if(!value)
fail("json_null failed");
json_decref(value);
return 0;
}