X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=test%2Fsuites%2Fapi%2Ftest_pack.c;h=772afb19c522db9f18f7f1bd68530f1b254b0069;hb=5df7b7939794abc9e8a826919d84d27385a6679d;hp=8968dc7a33cd3662a927b33f9e0089957aff736b;hpb=3a7512d2b05af82c43578477941e92db72f0f57b;p=jansson.git diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c index 8968dc7..772afb1 100644 --- a/test/suites/api/test_pack.c +++ b/test/suites/api/test_pack.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2009, 2010 Petri Lehtinen - * Copyright (c) 2010 Graeme Smecher + * Copyright (c) 2009-2011 Petri Lehtinen + * Copyright (c) 2010-2011 Graeme Smecher * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -22,101 +22,101 @@ int main() */ /* true */ - value = json_pack(&error, "b", 1); + value = json_pack_ex(&error, 0, "b", 1); if(!json_is_true(value)) - fail("json_pack boolean failed"); + fail("json_pack boolean failed"); if(value->refcount != (ssize_t)-1) - fail("json_pack boolean refcount failed"); + fail("json_pack boolean refcount failed"); json_decref(value); /* false */ - value = json_pack(&error, "b", 0); + value = json_pack_ex(&error, 0, "b", 0); if(!json_is_false(value)) - fail("json_pack boolean failed"); + fail("json_pack boolean failed"); if(value->refcount != (ssize_t)-1) - fail("json_pack boolean refcount failed"); + fail("json_pack boolean refcount failed"); json_decref(value); /* null */ - value = json_pack(&error, "n"); + value = json_pack_ex(&error, 0, "n"); if(!json_is_null(value)) - fail("json_pack null failed"); + fail("json_pack null failed"); if(value->refcount != (ssize_t)-1) - fail("json_pack null refcount failed"); + fail("json_pack null refcount failed"); json_decref(value); /* integer */ - value = json_pack(&error, "i", 1); + value = json_pack_ex(&error, 0, "i", 1); if(!json_is_integer(value) || json_integer_value(value) != 1) - fail("json_pack integer failed"); + fail("json_pack integer failed"); if(value->refcount != (ssize_t)1) - fail("json_pack integer refcount failed"); + fail("json_pack integer refcount failed"); json_decref(value); /* real */ - value = json_pack(&error, "f", 1.0); + value = json_pack_ex(&error, 0, "f", 1.0); if(!json_is_real(value) || json_real_value(value) != 1.0) - fail("json_pack real failed"); + fail("json_pack real failed"); if(value->refcount != (ssize_t)1) - fail("json_pack real refcount failed"); + fail("json_pack real refcount failed"); json_decref(value); /* string */ - value = json_pack(&error, "s", "test"); + value = json_pack_ex(&error, 0, "s", "test"); if(!json_is_string(value) || strcmp("test", json_string_value(value))) - fail("json_pack string failed"); + fail("json_pack string failed"); if(value->refcount != (ssize_t)1) - fail("json_pack string refcount failed"); + fail("json_pack string refcount failed"); json_decref(value); /* empty object */ - value = json_pack(&error, "{}", 1.0); + value = json_pack_ex(&error, 0, "{}", 1.0); if(!json_is_object(value) || json_object_size(value) != 0) - fail("json_pack empty object failed"); + fail("json_pack empty object failed"); if(value->refcount != (ssize_t)1) - fail("json_pack empty object refcount failed"); + fail("json_pack empty object refcount failed"); json_decref(value); /* empty list */ - value = json_pack(&error, "[]", 1.0); + value = json_pack_ex(&error, 0, "[]", 1.0); if(!json_is_array(value) || json_array_size(value) != 0) - fail("json_pack empty list failed"); + fail("json_pack empty list failed"); if(value->refcount != (ssize_t)1) - fail("json_pack empty list failed"); + fail("json_pack empty list failed"); json_decref(value); /* non-incref'd object */ - value = json_pack(&error, "o", json_integer(1)); + value = json_pack_ex(&error, 0, "o", json_integer(1)); if(!json_is_integer(value) || json_integer_value(value) != 1) - fail("json_pack object failed"); + fail("json_pack object failed"); if(value->refcount != (ssize_t)1) - fail("json_pack integer refcount failed"); + fail("json_pack integer refcount failed"); json_decref(value); /* incref'd object */ - value = json_pack(&error, "O", json_integer(1)); + value = json_pack_ex(&error, 0, "O", json_integer(1)); if(!json_is_integer(value) || json_integer_value(value) != 1) - fail("json_pack object failed"); + fail("json_pack object failed"); if(value->refcount != (ssize_t)2) - fail("json_pack integer refcount failed"); + fail("json_pack integer refcount failed"); json_decref(value); json_decref(value); /* simple object */ - value = json_pack(&error, "{s:[]}", "foo"); + value = json_pack_ex(&error, 0, "{s:[]}", "foo"); if(!json_is_object(value) || json_object_size(value) != 1) - fail("json_pack array failed"); + fail("json_pack array failed"); if(!json_is_array(json_object_get(value, "foo"))) - fail("json_pack array failed"); + fail("json_pack array failed"); if(json_object_get(value, "foo")->refcount != (ssize_t)1) - fail("json_pack object refcount failed"); + fail("json_pack object refcount failed"); json_decref(value); /* simple array */ - value = json_pack(&error, "[i,i,i]", 0, 1, 2); + value = json_pack_ex(&error, 0, "[i,i,i]", 0, 1, 2); if(!json_is_array(value) || json_array_size(value) != 3) - fail("json_pack object failed"); + fail("json_pack object failed"); for(i=0; i<3; i++) { if(!json_is_integer(json_array_get(value, i)) || @@ -127,21 +127,21 @@ int main() json_decref(value); /* Whitespace; regular string */ - value = json_pack(&error, " s ", "test"); + value = json_pack_ex(&error, 0, " s ", "test"); if(!json_is_string(value) || strcmp("test", json_string_value(value))) - fail("json_pack string (with whitespace) failed"); + fail("json_pack string (with whitespace) failed"); json_decref(value); /* Whitespace; empty array */ - value = json_pack(&error, "[ ]"); + value = json_pack_ex(&error, 0, "[ ]"); if(!json_is_array(value) || json_array_size(value) != 0) - fail("json_pack empty array (with whitespace) failed"); + fail("json_pack empty array (with whitespace) failed"); json_decref(value); /* Whitespace; array */ - value = json_pack(&error, "[ i , i, i ] ", 1, 2, 3); + value = json_pack_ex(&error, 0, "[ i , i, i ] ", 1, 2, 3); if(!json_is_array(value) || json_array_size(value) != 3) - fail("json_pack array (with whitespace) failed"); + fail("json_pack array (with whitespace) failed"); json_decref(value); /* @@ -149,60 +149,55 @@ int main() */ /* mismatched open/close array/object */ - if(json_pack(&error, "[}")) + if(json_pack_ex(&error, 0, "[}")) fail("json_pack failed to catch mismatched '}'"); if(error.line != 1 || error.column != 2) fail("json_pack didn't get the error coordinates right!"); - if(json_pack(&error, "{]")) + if(json_pack_ex(&error, 0, "{]")) fail("json_pack failed to catch mismatched ']'"); if(error.line != 1 || error.column != 2) fail("json_pack didn't get the error coordinates right!"); /* missing close array */ - if(json_pack(&error, "[")) + if(json_pack_ex(&error, 0, "[")) fail("json_pack failed to catch missing ']'"); if(error.line != 1 || error.column != 2) fail("json_pack didn't get the error coordinates right!"); /* missing close object */ - if(json_pack(&error, "{")) + if(json_pack_ex(&error, 0, "{")) fail("json_pack failed to catch missing '}'"); if(error.line != 1 || error.column != 2) fail("json_pack didn't get the error coordinates right!"); /* NULL string */ - if(json_pack(&error, "s", NULL)) + if(json_pack_ex(&error, 0, "s", NULL)) fail("json_pack failed to catch null argument string"); if(error.line != 1 || error.column != 1) fail("json_pack didn't get the error coordinates right!"); /* NULL format */ - if(json_pack(&error, NULL)) + if(json_pack_ex(&error, 0, NULL)) fail("json_pack failed to catch NULL format string"); - if(error.line != 1 || error.column != 1) + if(error.line != -1 || error.column != -1) fail("json_pack didn't get the error coordinates right!"); /* More complicated checks for row/columns */ - if(json_pack(&error, "{ {}: s }", "foo")) + if(json_pack_ex(&error, 0, "{ {}: s }", "foo")) fail("json_pack failed to catch object as key"); if(error.line != 1 || error.column != 3) fail("json_pack didn't get the error coordinates right!"); - if(json_pack(&error, "{ s: {}, s:[ii{} }", "foo", "bar", 12, 13)) + if(json_pack_ex(&error, 0, "{ s: {}, s:[ii{} }", "foo", "bar", 12, 13)) fail("json_pack failed to catch missing ]"); - if(error.line != 1 || error.column != 13) + if(error.line != 1 || error.column != 19) fail("json_pack didn't get the error coordinates right!"); - if(json_pack(&error, "[[[[[ [[[[[ [[[[ }]]]] ]]]] ]]]]]")) - fail("json_pack failed to catch missing ]"); + if(json_pack_ex(&error, 0, "[[[[[ [[[[[ [[[[ }]]]] ]]]] ]]]]]")) + fail("json_pack failed to catch extra }"); if(error.line != 1 || error.column != 21) fail("json_pack didn't get the error coordinates right!"); - return(0); - - //fprintf(stderr, "%i/%i: %s %s\n", error.line, error.column, error.source, error.text); + return 0; } - -/* vim: ts=4:expandtab:sw=4 - */