2 This file is part of GNUnet
3 (C) 2015, 2016 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
18 * @file json/test_jsonapi.c
19 * @brief Tests for jsonapi conversion functions
20 * @author Martin Schanzenbach
23 #include "gnunet_util_lib.h"
24 #include "gnunet_jsonapi_lib.h"
25 #include "gnunet_json_lib.h"
30 struct GNUNET_JSONAPI_Object *obj;
31 char* data = "{\"data\":[{\"id\":\"1\", \"type\":\"test\"}]}";
36 struct GNUNET_JSON_Specification jsonapispec[] = {
37 GNUNET_JSON_spec_jsonapi (&obj),
38 GNUNET_JSON_spec_end()
40 data_js = json_loads (data, JSON_DECODE_ANY, &err);
41 GNUNET_assert (NULL != data_js);
42 GNUNET_assert (GNUNET_OK ==
43 GNUNET_JSON_parse (data_js, jsonapispec,
45 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_data_serialize (obj,
47 GNUNET_JSON_parse_free (jsonapispec);
48 tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err);
49 GNUNET_assert (NULL != tmp_data_js);
50 GNUNET_assert (0 != json_equal (tmp_data_js, data_js));
51 json_decref (data_js);
52 json_decref (tmp_data_js);
53 GNUNET_free (tmp_data);
58 * Test rsa conversions from/to JSON.
60 * @return 0 on success
65 struct GNUNET_JSONAPI_Object *obj;
66 struct GNUNET_JSONAPI_Resource *res;
67 const char* data = "{\"data\":{\"id\":\"1\", \"type\":\"test\"}}";
71 struct GNUNET_JSON_Specification jsonapispec[] = {
72 GNUNET_JSON_spec_jsonapi (&obj),
73 GNUNET_JSON_spec_end()
75 data_js = json_loads (data, JSON_DECODE_ANY, &err);
76 GNUNET_assert (NULL != data_js);
77 GNUNET_assert (GNUNET_OK ==
78 GNUNET_JSON_parse (data_js, jsonapispec,
80 json_decref (data_js);
81 res = GNUNET_JSONAPI_object_get_resource (obj, 0);
82 GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_id (res, "1"));
83 GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_type (res, "test"));
84 GNUNET_assert (1 == GNUNET_JSONAPI_object_resource_count (obj));
85 GNUNET_JSON_parse_free (jsonapispec);
92 const char *const argv[])
94 GNUNET_log_setup ("test-jsonapi",
97 if (0 != test_spec_jsonapi ())
99 if (0 != test_serialize ())
104 /* end of test_json.c */