[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r37112 - in gnunet/src: identity include jsonapi namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r37112 - in gnunet/src: identity include jsonapi namestore |
Date: |
Tue, 3 May 2016 11:33:02 +0200 |
Author: schanzen
Date: 2016-05-03 11:33:01 +0200 (Tue, 03 May 2016)
New Revision: 37112
Added:
gnunet/src/jsonapi/test_jsonapi.c
Modified:
gnunet/src/identity/plugin_rest_identity.c
gnunet/src/include/gnunet_jsonapi_lib.h
gnunet/src/jsonapi/Makefile.am
gnunet/src/namestore/plugin_rest_namestore.c
Log:
- add jsonapi tests
Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c 2016-05-03 05:30:25 UTC (rev
37111)
+++ gnunet/src/identity/plugin_rest_identity.c 2016-05-03 09:33:01 UTC (rev
37112)
@@ -504,7 +504,8 @@
}
term_data[handle->data_size] = '\0';
memcpy (term_data, handle->data, handle->data_size);
- json_obj = GNUNET_JSONAPI_object_parse (term_data);
+ GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data,
+ &json_obj));
if (NULL == json_obj)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -618,7 +619,8 @@
term_data[handle->data_size] = '\0';
memcpy (term_data, handle->data, handle->data_size);
- json_obj = GNUNET_JSONAPI_object_parse (term_data);
+ GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data,
+ &json_obj));
if (NULL == json_obj)
{
Modified: gnunet/src/include/gnunet_jsonapi_lib.h
===================================================================
--- gnunet/src/include/gnunet_jsonapi_lib.h 2016-05-03 05:30:25 UTC (rev
37111)
+++ gnunet/src/include/gnunet_jsonapi_lib.h 2016-05-03 09:33:01 UTC (rev
37112)
@@ -36,8 +36,8 @@
*
* @param jsonapi_obj where to store the jsonapi object
*/
-struct GNUNET_JSONAPI_Specification
-GNUNET_JSONAPI_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj);
+struct GNUNET_JSON_Specification
+GNUNET_JSON_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj);
/**
* Create a JSON API resource
@@ -122,10 +122,12 @@
* Create a JSON API primary data from a string
*
* @param data the string of the JSON API data
- * @return a new JSON API resource or NULL on error.
+ * @param Pointer where to store new jsonapi Object.
+ * @return GNUNET_OK on success
*/
-struct GNUNET_JSONAPI_Object*
-GNUNET_JSONAPI_object_parse (const char* data);
+int
+GNUNET_JSONAPI_object_parse (const char* data,
+ struct GNUNET_JSONAPI_Object** obj);
/**
Modified: gnunet/src/jsonapi/Makefile.am
===================================================================
--- gnunet/src/jsonapi/Makefile.am 2016-05-03 05:30:25 UTC (rev 37111)
+++ gnunet/src/jsonapi/Makefile.am 2016-05-03 09:33:01 UTC (rev 37112)
@@ -20,15 +20,15 @@
-ljansson \
$(XLIB)
-#check_PROGRAMS = \
-# test_json
+check_PROGRAMS = \
+ test_jsonapi
-#TESTS = \
-# $(check_PROGRAMS)
+TESTS = \
+ $(check_PROGRAMS)
-#test_json_SOURCES = \
-# test_json.c
-#test_json_LDADD = \
-# libgnunetjson.la \
-# $(top_builddir)/src/util/libgnunetutil.la \
-# -ljansson
+test_jsonapi_SOURCES = \
+ test_jsonapi.c
+test_jsonapi_LDADD = \
+ libgnunetjsonapi.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ -ljansson
Added: gnunet/src/jsonapi/test_jsonapi.c
===================================================================
--- gnunet/src/jsonapi/test_jsonapi.c (rev 0)
+++ gnunet/src/jsonapi/test_jsonapi.c 2016-05-03 09:33:01 UTC (rev 37112)
@@ -0,0 +1,104 @@
+/*
+ This file is part of GNUnet
+ (C) 2015, 2016 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNUnet; see the file COPYING. If not, If not, see
<http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file json/test_jsonapi.c
+ * @brief Tests for jsonapi conversion functions
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_jsonapi_lib.h"
+#include "gnunet_json_lib.h"
+
+static int
+test_serialize ()
+{
+ struct GNUNET_JSONAPI_Object *obj;
+ char* data = "{\"data\":[{\"id\":\"1\", \"type\":\"test\"}]}";
+ char* tmp_data;
+ json_t* data_js;
+ json_t* tmp_data_js;
+ json_error_t err;
+ struct GNUNET_JSON_Specification jsonapispec[] = {
+ GNUNET_JSON_spec_jsonapi (&obj),
+ GNUNET_JSON_spec_end()
+ };
+ data_js = json_loads (data, JSON_DECODE_ANY, &err);
+ GNUNET_assert (NULL != data_js);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_JSON_parse (data_js, jsonapispec,
+ NULL, NULL));
+ GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_data_serialize (obj,
+ &tmp_data));
+ GNUNET_JSON_parse_free (jsonapispec);
+ tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err);
+ GNUNET_assert (NULL != tmp_data_js);
+ GNUNET_assert (0 != json_equal (tmp_data_js, data_js));
+ json_decref (data_js);
+ json_decref (tmp_data_js);
+ GNUNET_free (tmp_data);
+ return 0;
+}
+
+/**
+ * Test rsa conversions from/to JSON.
+ *
+ * @return 0 on success
+ */
+static int
+test_spec_jsonapi ()
+{
+ struct GNUNET_JSONAPI_Object *obj;
+ struct GNUNET_JSONAPI_Resource *res;
+ const char* data = "{\"data\":{\"id\":\"1\", \"type\":\"test\"}}";
+ json_t* data_js;
+ json_error_t err;
+
+ struct GNUNET_JSON_Specification jsonapispec[] = {
+ GNUNET_JSON_spec_jsonapi (&obj),
+ GNUNET_JSON_spec_end()
+ };
+ data_js = json_loads (data, JSON_DECODE_ANY, &err);
+ GNUNET_assert (NULL != data_js);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_JSON_parse (data_js, jsonapispec,
+ NULL, NULL));
+ json_decref (data_js);
+ res = GNUNET_JSONAPI_object_get_resource (obj, 0);
+ GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_id (res, "1"));
+ GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_type (res,
"test"));
+ GNUNET_assert (1 == GNUNET_JSONAPI_object_resource_count (obj));
+ GNUNET_JSON_parse_free (jsonapispec);
+ return 0;
+}
+
+
+int
+main(int argc,
+ const char *const argv[])
+{
+ GNUNET_log_setup ("test-jsonapi",
+ "WARNING",
+ NULL);
+ if (0 != test_spec_jsonapi ())
+ return 1;
+ if (0 != test_serialize ())
+ return 1;
+ return 0;
+}
+
+/* end of test_json.c */
Modified: gnunet/src/namestore/plugin_rest_namestore.c
===================================================================
--- gnunet/src/namestore/plugin_rest_namestore.c 2016-05-03 05:30:25 UTC
(rev 37111)
+++ gnunet/src/namestore/plugin_rest_namestore.c 2016-05-03 09:33:01 UTC
(rev 37112)
@@ -744,7 +744,8 @@
}
term_data[handle->data_size] = '\0';
memcpy (term_data, handle->data, handle->data_size);
- json_obj = GNUNET_JSONAPI_object_parse (term_data);
+ GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data,
+ &json_obj));
if (NULL == json_obj)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r37112 - in gnunet/src: identity include jsonapi namestore,
gnunet <=