aboutsummaryrefslogtreecommitdiff
path: root/src/jsonapi
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-04 21:11:04 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-04 21:11:04 +0100
commit9ce720648614dbb0901052719a989d40dc6534ab (patch)
tree93fe055aa7995da4aa610f589ba3b21acf9f8c4a /src/jsonapi
parentaa44baaf619738676f9515ab85b518187cca3041 (diff)
downloadgnunet-9ce720648614dbb0901052719a989d40dc6534ab.tar.gz
gnunet-9ce720648614dbb0901052719a989d40dc6534ab.zip
-fix test
Diffstat (limited to 'src/jsonapi')
-rw-r--r--src/jsonapi/test_jsonapi.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/jsonapi/test_jsonapi.c b/src/jsonapi/test_jsonapi.c
index 379dab9af..36c7b5c6c 100644
--- a/src/jsonapi/test_jsonapi.c
+++ b/src/jsonapi/test_jsonapi.c
@@ -1,18 +1,18 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2015, 2016 GNUnet e.V. 3 (C) 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 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 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. 7 Foundation; either version 3, or (at your option) any later version.
8 8
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 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 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. 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 12
13 You should have received a copy of the GNU General Public License along with 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/> 14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
15*/ 15 */
16 16
17/** 17/**
18 * @file json/test_jsonapi.c 18 * @file json/test_jsonapi.c
@@ -24,7 +24,7 @@
24#include "gnunet_jsonapi_lib.h" 24#include "gnunet_jsonapi_lib.h"
25#include "gnunet_json_lib.h" 25#include "gnunet_json_lib.h"
26 26
27#define TEST_JSONAPI_DOCUMENT "{\"data\":{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}}" 27#define TEST_JSONAPI_DOCUMENT "{\"data\":[{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}]}"
28 28
29#define TEST_JSONAPI_DOCUMENT_ERR "{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", \"title\":\"Error\", \"detail\":\"Error details\"}]}" 29#define TEST_JSONAPI_DOCUMENT_ERR "{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", \"title\":\"Error\", \"detail\":\"Error details\"}]}"
30 30
@@ -74,7 +74,8 @@ test_document ()
74 json_t *doc_json; 74 json_t *doc_json;
75 json_t *data_js; 75 json_t *data_js;
76 json_error_t err; 76 json_error_t err;
77 77 int ret;
78
78 obj = GNUNET_JSONAPI_document_new (); 79 obj = GNUNET_JSONAPI_document_new ();
79 res = GNUNET_JSONAPI_resource_new ("bar", 80 res = GNUNET_JSONAPI_resource_new ("bar",
80 "1"); 81 "1");
@@ -94,11 +95,11 @@ test_document ()
94 JSON_DECODE_ANY, 95 JSON_DECODE_ANY,
95 &err); 96 &err);
96 GNUNET_assert (NULL != data_js); 97 GNUNET_assert (NULL != data_js);
97 GNUNET_assert (0 != json_equal (data_js, doc_json)); 98 ret = json_equal (data_js, doc_json) ? 0 : 1;
98 GNUNET_JSONAPI_document_delete (obj); 99 GNUNET_JSONAPI_document_delete (obj);
99 json_decref (data_js); 100 json_decref (data_js);
100 json_decref (doc_json); 101 json_decref (doc_json);
101 return 0; 102 return ret;
102} 103}
103 104
104static int 105static int
@@ -106,6 +107,7 @@ test_serialize ()
106{ 107{
107 struct GNUNET_JSONAPI_Document *obj; 108 struct GNUNET_JSONAPI_Document *obj;
108 char* tmp_data; 109 char* tmp_data;
110 int ret;
109 json_t* data_js; 111 json_t* data_js;
110 json_t* tmp_data_js; 112 json_t* tmp_data_js;
111 json_error_t err; 113 json_error_t err;
@@ -125,11 +127,11 @@ test_serialize ()
125 GNUNET_JSON_parse_free (jsonapispec); 127 GNUNET_JSON_parse_free (jsonapispec);
126 tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err); 128 tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err);
127 GNUNET_assert (NULL != tmp_data_js); 129 GNUNET_assert (NULL != tmp_data_js);
128 GNUNET_assert (0 != json_equal (tmp_data_js, data_js)); 130 ret = (1 == json_equal (tmp_data_js, data_js)) ? 0 : 1;
129 json_decref (data_js); 131 json_decref (data_js);
130 json_decref (tmp_data_js); 132 json_decref (tmp_data_js);
131 GNUNET_free (tmp_data); 133 GNUNET_free (tmp_data);
132 return 0; 134 return ret;
133} 135}
134 136
135/** 137/**