gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37129 - gnunet/src/jsonapi


From: gnunet
Subject: [GNUnet-SVN] r37129 - gnunet/src/jsonapi
Date: Thu, 5 May 2016 12:35:48 +0200

Author: schanzen
Date: 2016-05-05 12:35:48 +0200 (Thu, 05 May 2016)
New Revision: 37129

Modified:
   gnunet/src/jsonapi/jsonapi_document.c
   gnunet/src/jsonapi/jsonapi_error.c
   gnunet/src/jsonapi/test_jsonapi.c
Log:
- add test, bugfix


Modified: gnunet/src/jsonapi/jsonapi_document.c
===================================================================
--- gnunet/src/jsonapi/jsonapi_document.c       2016-05-05 10:18:01 UTC (rev 
37128)
+++ gnunet/src/jsonapi/jsonapi_document.c       2016-05-05 10:35:48 UTC (rev 
37129)
@@ -53,8 +53,21 @@
 {
   struct GNUNET_JSONAPI_Resource *res;
   struct GNUNET_JSONAPI_Resource *res_next;
-  
+  struct GNUNET_JSONAPI_Error *err;
+  struct GNUNET_JSONAPI_Error *err_next;
 
+
+  for (err = doc->err_list_head;
+       err != NULL;)
+  {
+    err_next = err->next;
+    GNUNET_CONTAINER_DLL_remove (doc->err_list_head,
+                                 doc->err_list_tail,
+                                 err);
+    GNUNET_JSONAPI_error_delete (err);
+    err = err_next;
+  }
+
   for (res = doc->res_list_head;
        res != NULL;)
   {
@@ -65,6 +78,9 @@
     GNUNET_JSONAPI_resource_delete (res);
     res = res_next;
   }
+
+  if (NULL != doc->meta)
+    json_decref (doc->meta);
   GNUNET_free (doc);
   doc = NULL;
 }
@@ -95,7 +111,7 @@
  */
 void
 GNUNET_JSONAPI_document_error_add (struct GNUNET_JSONAPI_Document *doc,
-                                      struct GNUNET_JSONAPI_Error *err)
+                                   struct GNUNET_JSONAPI_Error *err)
 {
   GNUNET_CONTAINER_DLL_insert (doc->err_list_head,
                                doc->err_list_tail,
@@ -113,7 +129,7 @@
  */
 void
 GNUNET_JSONAPI_document_resource_add (struct GNUNET_JSONAPI_Document *doc,
-                                         struct GNUNET_JSONAPI_Resource *res)
+                                      struct GNUNET_JSONAPI_Resource *res)
 {
   GNUNET_CONTAINER_DLL_insert (doc->res_list_head,
                                doc->res_list_tail,
@@ -310,7 +326,7 @@
       GNUNET_assert (GNUNET_OK ==
                      GNUNET_JSONAPI_error_to_json (error,
                                                    &res_json_tmp));
-      json_array_append (res_json, res_json_tmp);
+      json_array_append_new (res_json, res_json_tmp);
     }
     json_object_set_new (*root_json,
                          GNUNET_JSONAPI_KEY_ERRORS,

Modified: gnunet/src/jsonapi/jsonapi_error.c
===================================================================
--- gnunet/src/jsonapi/jsonapi_error.c  2016-05-05 10:18:01 UTC (rev 37128)
+++ gnunet/src/jsonapi/jsonapi_error.c  2016-05-05 10:35:48 UTC (rev 37129)
@@ -149,22 +149,22 @@
   struct GNUNET_JSONAPI_Error *error;
   error = GNUNET_new (struct GNUNET_JSONAPI_Error);
 
-  GNUNET_assert (NULL != id);
-  error->id = GNUNET_strdup (id);
-  GNUNET_assert (NULL != status);
-  error->status = GNUNET_strdup (status);
-  GNUNET_assert (NULL != code);
-  error->code = GNUNET_strdup (code);
-  GNUNET_assert (NULL != title);
-  error->title = GNUNET_strdup (title);
-  GNUNET_assert (NULL != detail);
-  error->detail = GNUNET_strdup (detail);
-  GNUNET_assert (NULL != links);
-  error->links = json_deep_copy (links);
-  GNUNET_assert (NULL != source);
-  error->source = json_deep_copy (source);
-  GNUNET_assert (NULL != meta);
-  error->meta = json_deep_copy (meta);
+  if (NULL != id)
+    error->id = GNUNET_strdup (id);
+  if (NULL != status)
+    error->status = GNUNET_strdup (status);
+  if (NULL != code)
+    error->code = GNUNET_strdup (code);
+  if (NULL != title)
+    error->title = GNUNET_strdup (title);
+  if (NULL != detail)
+    error->detail = GNUNET_strdup (detail);
+  if (NULL != links)
+    error->links = json_deep_copy (links);
+  if (NULL != source)
+    error->source = json_deep_copy (source);
+  if (NULL != meta)
+    error->meta = json_deep_copy (meta);
   return error;
 }
 /**

Modified: gnunet/src/jsonapi/test_jsonapi.c
===================================================================
--- gnunet/src/jsonapi/test_jsonapi.c   2016-05-05 10:18:01 UTC (rev 37128)
+++ gnunet/src/jsonapi/test_jsonapi.c   2016-05-05 10:35:48 UTC (rev 37129)
@@ -26,7 +26,47 @@
 
 #define TEST_JSONAPI_DOCUMENT 
"{\"data\":{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}}"
 
+#define TEST_JSONAPI_DOCUMENT_ERR 
"{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", 
\"title\":\"Error\", \"detail\":\"Error details\"}]}"
+
 static int
+test_document_error ()
+{
+  struct GNUNET_JSONAPI_Document *obj;
+  struct GNUNET_JSONAPI_Error *error;
+  json_t *doc_json;
+  json_t *data_js;
+  json_error_t err;
+
+  obj = GNUNET_JSONAPI_document_new ();
+  error = GNUNET_JSONAPI_error_new ("1",
+                                    "403",
+                                    "23",
+                                    "Error",
+                                    "Error details",
+                                    NULL,
+                                    NULL,
+                                    NULL);
+
+
+  GNUNET_JSONAPI_document_error_add (obj,
+                                     error);
+
+  GNUNET_assert (GNUNET_OK == 
+                 GNUNET_JSONAPI_document_to_json (obj,
+                                                  &doc_json));
+  data_js = json_loads (TEST_JSONAPI_DOCUMENT_ERR,
+                        JSON_DECODE_ANY,
+                        &err);
+  GNUNET_assert (NULL != data_js);
+  GNUNET_assert (0 != json_equal (data_js, doc_json));
+  GNUNET_JSONAPI_document_delete (obj);
+  json_decref (data_js);
+  json_decref (doc_json);
+  return 0;
+}
+
+
+static int
 test_document ()
 {
   struct GNUNET_JSONAPI_Document *obj;
@@ -38,7 +78,7 @@
   obj = GNUNET_JSONAPI_document_new ();
   res = GNUNET_JSONAPI_resource_new ("bar",
                                      "1");
-  
+
   GNUNET_assert (GNUNET_OK == 
                  GNUNET_JSONAPI_resource_add_attr (res,
                                                    "foo",
@@ -138,6 +178,8 @@
     return 1;
   if (0 != test_document ())
     return 1;
+  if (0 != test_document_error ())
+    return 1;
   return 0;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]