}
struct ast_json *ast_json_object_get(struct ast_json *object, const char *key)
{
- if (key) {
- return (struct ast_json *)json_object_get((json_t *)object, key);
+ if (!key) {
+ return NULL;
}
- return NULL;
+ return (struct ast_json *)json_object_get((json_t *)object, key);
}
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
{
int ast_json_dump_file(struct ast_json *root, FILE *output)
{
- if (root && output) {
- return json_dumpf((json_t *)root, output, dump_flags());
+ if (!root || !output) {
+ return -1;
}
- return -1;
+ return json_dumpf((json_t *)root, output, dump_flags());
}
int ast_json_dump_new_file(struct ast_json *root, const char *path)
{
+ if (!root || !path) {
+ return -1;
+ }
return json_dump_file((json_t *)root, path, dump_flags());
}
ast_test_validate(test, 0 == uut_res);
ast_test_validate(test, LLONG_MIN == ast_json_integer_get(uut));
- ast_json_unref(uut);
-
return AST_TEST_PASS;
}
ast_test_validate(test, AST_JSON_ARRAY == ast_json_typeof(uut));
ast_test_validate(test, 0 == ast_json_array_size(uut));
- ast_json_unref(uut);
-
return AST_TEST_PASS;
}
return AST_TEST_PASS;
}
+AST_TEST_DEFINE(json_test_pack_ownership)
+{
+ RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
+ RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "pack_ownership";
+ info->category = "/main/json/";
+ info->summary = "Testing json_pack failure conditions.";
+ info->description = "Test JSON abstraction library.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ uut = ast_json_pack("[o]", ast_json_string_create("Am I freed?"));
+
+ return AST_TEST_PASS;
+}
+
AST_TEST_DEFINE(json_test_pack_errors)
{
RAII_VAR(void *, alloc_debug, json_test_init(test), json_test_finish);
/* circular reference testing */
/* Cannot add self */
uut = ast_json_object_create();
- uut_res = ast_json_object_set(uut, "myself", uut);
+ uut_res = ast_json_object_set(uut, "myself", ast_json_ref(uut));
ast_test_validate(test, -1 == uut_res);
ast_test_validate(test, 0 == ast_json_object_size(uut));
}
uut = ast_json_array_create();
- uut_res = ast_json_object_set(uut, "myself", uut);
+ ast_test_validate(test, 0 == ast_json_array_size(uut));
+ uut_res = ast_json_array_append(uut, ast_json_ref(uut));
ast_test_validate(test, -1 == uut_res);
ast_test_validate(test, 0 == ast_json_array_size(uut));
AST_TEST_UNREGISTER(json_test_dump_load_null);
AST_TEST_UNREGISTER(json_test_parse_errors);
AST_TEST_UNREGISTER(json_test_pack);
+ AST_TEST_UNREGISTER(json_test_pack_ownership);
AST_TEST_UNREGISTER(json_test_pack_errors);
AST_TEST_UNREGISTER(json_test_copy);
AST_TEST_UNREGISTER(json_test_deep_copy);
AST_TEST_REGISTER(json_test_dump_load_null);
AST_TEST_REGISTER(json_test_parse_errors);
AST_TEST_REGISTER(json_test_pack);
+ AST_TEST_REGISTER(json_test_pack_ownership);
AST_TEST_REGISTER(json_test_pack_errors);
AST_TEST_REGISTER(json_test_copy);
AST_TEST_REGISTER(json_test_deep_copy);
return AST_MODULE_LOAD_SUCCESS;
}
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "JSON testing.");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "JSON testing",
+ .load = load_module,
+ .unload = unload_module,
+ .nonoptreq = "res_json");