Skip to content

Commit

Permalink
added parson wrapper-4
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <[email protected]>
  • Loading branch information
NishantBansal2003 committed Dec 4, 2024
1 parent d0ef2dc commit c0c5f30
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 56 deletions.
41 changes: 23 additions & 18 deletions include/grass/defs/gparson.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
#ifndef GRASS_GPARSONDEFS_H
#define GRASS_GPARSONDEFS_H

#include <grass/parson.h>
/* *************************************************************** */
/* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */
/* *************************************************************** */
extern void G_json_set_float_serialization_format(const char *);
extern JSON_Status G_json_serialize_to_buffer(const JSON_Value *, char *,
size_t);
extern JSON_Status G_json_serialize_to_file(const JSON_Value *, const char *);
extern char *G_json_serialize_to_string(const JSON_Value *);
extern JSON_Status G_json_serialize_to_buffer_pretty(const JSON_Value *, char *,
size_t);
extern JSON_Status G_json_serialize_to_file_pretty(const JSON_Value *,
const char *);

/* Serialization Functions */
extern char *G_json_serialize_to_string_pretty(const JSON_Value *);
extern void G_json_free_serialized_string(char *);
extern JSON_Value *G_json_object_get_value(const JSON_Object *, const char *);
extern const char *G_json_object_get_string(const JSON_Object *, const char *);
extern size_t G_json_object_get_string_len(const JSON_Object *, const char *);

/* JSON Value Creation and Freeing */
extern JSON_Value *G_json_value_init_object(void);
extern JSON_Value *G_json_value_init_array(void);
extern JSON_Value *G_json_value_init_string(const char *);
extern JSON_Value *G_json_value_init_number(double);
extern JSON_Value *G_json_value_init_boolean(int);
extern void G_json_value_free(JSON_Value *);

/* JSON Object Access Functions */
extern JSON_Object *G_json_value_get_object(const JSON_Value *);
extern JSON_Object *G_json_object(const JSON_Value *);
extern JSON_Object *G_json_object_get_object(const JSON_Object *, const char *);
extern JSON_Array *G_json_object_get_array(const JSON_Object *, const char *);
extern JSON_Value *G_json_object_get_value(const JSON_Object *, const char *);
extern const char *G_json_object_get_string(const JSON_Object *, const char *);
extern double G_json_object_get_number(const JSON_Object *, const char *);
extern int G_json_object_get_boolean(const JSON_Object *, const char *);
extern JSON_Value *G_json_object_get_wrapping_value(const JSON_Object *);

/* JSON Object Modification Functions */
extern JSON_Status G_json_object_set_value(JSON_Object *, const char *,
JSON_Value *);
extern JSON_Status G_json_object_set_string(JSON_Object *, const char *,
Expand All @@ -35,16 +42,14 @@ extern JSON_Status G_json_object_dotset_string(JSON_Object *, const char *,
const char *);
extern JSON_Status G_json_object_dotset_number(JSON_Object *, const char *,
double);

/* JSON Array Functions */
extern JSON_Array *G_json_array(const JSON_Value *);
extern JSON_Value *G_json_array_get_value(const JSON_Array *, size_t);
extern JSON_Status G_json_array_append_value(JSON_Array *, JSON_Value *);
extern JSON_Status G_json_array_append_string(JSON_Array *, const char *);
extern JSON_Status G_json_array_append_number(JSON_Array *, double);
extern JSON_Status G_json_array_append_boolean(JSON_Array *, int);
extern JSON_Status G_json_array_append_null(JSON_Array *);
extern JSON_Value *G_json_value_init_object(void);
extern JSON_Value *G_json_value_init_array(void);
extern JSON_Value *G_json_value_init_string(const char *);
extern JSON_Value *G_json_value_init_number(double);
extern JSON_Value *G_json_value_init_boolean(int);
extern void G_json_value_free(JSON_Value *);

#endif /* GRASS_GPARSONDEFS_H */
66 changes: 28 additions & 38 deletions lib/gparson/parson_grass_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,11 @@
#include <grass/parson.h>
#endif

void G_json_set_float_serialization_format(const char *format)
{
json_set_float_serialization_format(format);
}

JSON_Status G_json_serialize_to_buffer(const JSON_Value *value, char *buf,
size_t buf_size)
{
return json_serialize_to_buffer(value, buf, buf_size);
}

JSON_Status G_json_serialize_to_file(const JSON_Value *value,
const char *filename)
{
return json_serialize_to_file(value, filename);
}

char *G_json_serialize_to_string(const JSON_Value *value)
{
return json_serialize_to_string(value);
}

JSON_Status G_json_serialize_to_buffer_pretty(const JSON_Value *value,
char *buf, size_t buf_size)
{
return json_serialize_to_buffer_pretty(value, buf, buf_size);
}

JSON_Status G_json_serialize_to_file_pretty(const JSON_Value *value,
const char *filename)
{
return json_serialize_to_file_pretty(value, filename);
}
/* *************************************************************** */
/* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */
/* *************************************************************** */

/* Serialization Functions */
char *G_json_serialize_to_string_pretty(const JSON_Value *value)
{
return json_serialize_to_string_pretty(value);
Expand All @@ -63,6 +34,7 @@ void G_json_free_serialized_string(char *string)
json_free_serialized_string(string);
}

/* JSON Object Access Functions */
JSON_Value *G_json_object_get_value(const JSON_Object *object, const char *name)
{
return json_object_get_value(object, name);
Expand All @@ -74,11 +46,6 @@ const char *G_json_object_get_string(const JSON_Object *object,
return json_object_get_string(object, name);
}

size_t G_json_object_get_string_len(const JSON_Object *object, const char *name)
{
return json_object_get_string_len(object, name);
}

JSON_Object *G_json_object_get_object(const JSON_Object *object,
const char *name)
{
Expand All @@ -105,6 +72,7 @@ JSON_Value *G_json_object_get_wrapping_value(const JSON_Object *object)
return json_object_get_wrapping_value(object);
}

/* JSON Object Modification Functions */
JSON_Status G_json_object_set_value(JSON_Object *object, const char *name,
JSON_Value *value)
{
Expand Down Expand Up @@ -146,6 +114,7 @@ JSON_Status G_json_object_dotset_number(JSON_Object *object, const char *name,
return json_object_dotset_number(object, name, number);
}

/* JSON Array Functions */
JSON_Status G_json_array_append_value(JSON_Array *array, JSON_Value *value)
{
return json_array_append_value(array, value);
Expand All @@ -171,11 +140,32 @@ JSON_Status G_json_array_append_null(JSON_Array *array)
return json_array_append_null(array);
}

/* JSON Value Creation and Freeing */
JSON_Value *G_json_value_init_object(void)
{
return json_value_init_object();
}

JSON_Object *G_json_value_get_object(const JSON_Value *value)
{
return json_value_get_object(value);
}

JSON_Object *G_json_object(const JSON_Value *value)
{
return json_object(value);
}

JSON_Array *G_json_array(const JSON_Value *value)
{
return json_array(value);
}

JSON_Value *G_json_array_get_value(const JSON_Array *array, size_t index)
{
return json_array_get_value(array, index);
}

JSON_Value *G_json_value_init_array(void)
{
return json_value_init_array();
Expand Down
10 changes: 10 additions & 0 deletions lib/gparson/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MODULE_TOPDIR = ../../..

PGM=test.gparson.lib

LIBES = $(PARSONLIB) $(GPARSONLIB) $(GISLIB)
DEPENDENCIES = $(PARSONDEP) $(GPARSONDEP) $(GISDEP)

include $(MODULE_TOPDIR)/include/Make/Module.make

default: cmd
3 changes: 3 additions & 0 deletions lib/gparson/test/test.gparson.lib.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


Take a look at the module command line help for more information.
23 changes: 23 additions & 0 deletions lib/gparson/test/test_gparson_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*****************************************************************************
*
* MODULE: Grass gparson Library
*
* PURPOSE: Unit tests
*
* COPYRIGHT: (C) 2000 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/

#ifndef _TEST_GPARSON_LIB_H_
#define _TEST_GPARSON_LIB_H_

#include <grass/gparson.h>

/* parson wrapper tests */
int unit_test_parson_wrapper(void);

#endif
53 changes: 53 additions & 0 deletions lib/gparson/test/test_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/****************************************************************************
*
* MODULE: test.gparson.lib
*
*
* PURPOSE: Unit tests for the gparson library
*
* COPYRIGHT: (C) 2007 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with
* GRASS for details.
*
*****************************************************************************/

#include <stdlib.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/gparson.h>
#include "test_gparson_lib.h"
#include "grass/gparson.h"

/* ************************************************************************* */

/* ************************************************************************* */
/* ************************************************************************* */

/* ************************************************************************* */
int main(int argc, char *argv[])
{
struct GModule *module;
int returnstat = 0;

/* Initialize GRASS */
G_gisinit(argv[0]);

module = G_define_module();
module->description = _("Performs unit tests "
"for the gparson library");

if (G_parser(argc, argv))
exit(EXIT_FAILURE);

/*Run the unit tests */
returnstat += unit_test_parson_wrapper();

if (returnstat != 0)
G_warning("Errors detected while testing the gparson lib");
else
G_message("\n-- gparson lib tests finished successfully --");

return (returnstat);
}
Loading

0 comments on commit c0c5f30

Please sign in to comment.