add new repo to handle json
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
|
||||
|
||||
NAME_TEST=is_good
|
||||
CC=gcc
|
||||
ROOT_DIR=$(PWD)
|
||||
YTESTDIR=$(PWD)/../../ytest_t
|
||||
LISTDIR=$(PWD)/../../list_t
|
||||
INCLUDE_LIST=$(LISTDIR)/src
|
||||
|
||||
INCLUDE_DIR=$(PWD)/../src
|
||||
CFLAGS=-I$(INCLUDE_DIR) -I$(INCLUDE_LIST) -I$(YTESTDIR)/include_ytest/include
|
||||
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||
|
||||
#SRC_DIR=$(ROOT_DIR)/src
|
||||
#SRC=$(wildcard */*/*.c)
|
||||
SRC=$(wildcard **/**/*.c)
|
||||
#HEADS=$(OBJS:.o=.h)
|
||||
TEST_DIR=$(PWD)
|
||||
EXECSRC=$(NAME_TEST).c
|
||||
EXEC=launch_$(NAME_TEST)_m
|
||||
|
||||
|
||||
LISTSRC_O=$(LISTDIR)/src/list_t/list_t.o
|
||||
|
||||
JSONDIR=$(PWD)/..
|
||||
JSONSRC=$(JSONDIR)/src/json_t/json_t.c
|
||||
JSONSRC_O=$(JSONDIR)/src/json_t/json_t.o
|
||||
|
||||
|
||||
TOPTARGETS := all clean
|
||||
|
||||
DEPS=$(LISTDIR) $(YTESTDIR) $(JSONDIR)
|
||||
|
||||
$(TOPTARGETS): $(DEPS)
|
||||
|
||||
$(DEPS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
|
||||
#LISTSRC_O=$(LISTSRC:.c=.o)
|
||||
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||
|
||||
OBJ=$(SRC:.c=.o) $(JSONSRC_O)
|
||||
#$(LISTSRC_O)
|
||||
|
||||
|
||||
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||
|
||||
all: $(EXEC) $(LIB_YTEST)
|
||||
|
||||
$(EXEC): $(EXECSRC) $(OBJ)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(EXEC)
|
||||
|
||||
run: $(EXEC)
|
||||
$(EXEC) -h
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$#" -le 0 ] ; then
|
||||
echo "Usage: $0 is_good.c" >&2
|
||||
echo "for example to compile: is_good.c" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$#" -le 1 ] ; then
|
||||
echo "Usage: $0 $1" >&2
|
||||
echo " we can add more option for example '-D DEBUG=1' to have debug print, '-D HK' to have gtest like prompt, od '-g' to gbd" >&2
|
||||
echo "for example: $0 $1 \"-D DEBUG=1 -D HK -g\""
|
||||
fi
|
||||
|
||||
DIR_YTEST=$PWD/../../ytest_t
|
||||
SRC=../src
|
||||
|
||||
gcc -o launch_is_good_c $1 -L$DIR_YTEST $2 -lytest -I$DIR_YTEST/include_ytest/include $SRC/list_t/list_t.c -I$SRC
|
||||
#gcc -o launch_is_good_c $1 $2 -lytest -I../include_ytest src/list_t/list_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
||||
|
||||
export LD_LIBRARY_PATH=$DIR_YTEST/:LD_LIBRARY_PATH
|
||||
|
||||
|
||||
#gcc $1 src/ftest/ftest.c src/fmock/fmock.c src/tools_t/tools_t.c src/bar_progress/bar_progress.c src/list_t/list_t.c src/set_theoric_t/set_theoric_t.c -I./include $2 -o launch_is_good_c -lpthread
|
||||
@@ -0,0 +1,211 @@
|
||||
#include "ftest/ftest.h"
|
||||
#include "fmock/fmock.h"
|
||||
|
||||
|
||||
#include "json_t/json_t.h"
|
||||
|
||||
TEST(string_val){
|
||||
|
||||
char *val = "\"Hello! it's a string\"";
|
||||
|
||||
struct js_value *js = create_js_value_string(val, NULL);
|
||||
|
||||
LOG("js type = %d\n",js->code_type);
|
||||
LOG("js len = %ld\n",js->length);
|
||||
LOG(" js val = %s\n", js->type.string);
|
||||
|
||||
free_js_value(js);
|
||||
}
|
||||
TEST(number){
|
||||
|
||||
char *val = "3.14";
|
||||
|
||||
struct js_value *js = create_js_value_number(val, NULL);
|
||||
|
||||
LOG("js type = %d\n",js->code_type);
|
||||
LOG("js len = %ld\n",js->length);
|
||||
LOG(" js val = %Lf\n", js->type.number);
|
||||
|
||||
free_js_value(js);
|
||||
}
|
||||
TEST(object_val){
|
||||
|
||||
char *val = "{ \"message\" : \"Hello! it's a string\" , \"age\" : 48 , \"speaker\" : \" the president \" }";
|
||||
struct js_value *js = create_js_value_object(val, NULL);
|
||||
|
||||
LOG("key : %s\n lenKey: %ld \n",js->type.object.key, js->type.object.key_length);
|
||||
|
||||
/*
|
||||
LOG("value : %s\n",js->type.object.value->type.string);
|
||||
LOG("value : %Lf\n",js->type.object.next_object->type.object.value->type.number);
|
||||
LOG("value : %s\n",js->type.object.next_object->type.object.next_object->type.object.value->type.string);
|
||||
*/
|
||||
|
||||
print_value(js);
|
||||
|
||||
char *rrjson = original_string_js_value(js);
|
||||
printf("original :%s\n",rrjson);
|
||||
char *rrjson1 = original_string_js_value(js->type.object.next_object);
|
||||
printf("original 1 :%s\n",rrjson1);
|
||||
|
||||
free_js_value(js);
|
||||
|
||||
free(rrjson);
|
||||
free(rrjson1);
|
||||
|
||||
LOG("line %d\n",__LINE__);
|
||||
}
|
||||
TEST(array_val){
|
||||
|
||||
char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 , \"speaker\" : \" the president \" }, 45 , true ]";
|
||||
//char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 } , {\"speaker\" : \" the president \" } , 25, \"tttt\" ]";
|
||||
struct js_value *js = create_js_value_array(val, NULL);
|
||||
|
||||
// LOG("key : %s\n lenKey: %ld \n",js->type.object.key, js->type.object.key_length);
|
||||
|
||||
/*
|
||||
LOG("value : %s\n",js->type.object.value->type.string);
|
||||
LOG("value : %Lf\n",js->type.object.next_object->type.object.value->type.number);
|
||||
LOG("value : %s\n",js->type.object.next_object->type.object.next_object->type.object.value->type.string);
|
||||
*/
|
||||
|
||||
print_value(js);
|
||||
|
||||
/*
|
||||
char *rrjson = original_string_js_value(js);
|
||||
printf("original :%s\n",rrjson);
|
||||
char *rrjson1 = original_string_js_value(js->type.array.next_element);
|
||||
printf("original 1 :%s\n",rrjson1);
|
||||
*/
|
||||
free_js_value(js);
|
||||
|
||||
// free(rrjson);
|
||||
// free(rrjson1);
|
||||
//LOG("%s\n",__LINE__);
|
||||
LOG("line %d\n",__LINE__);
|
||||
|
||||
}
|
||||
TEST(general_val){
|
||||
|
||||
char *val = "{ \"array\" : [ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 , \"speaker\" : \" the president \" }, 45 , true ] }";
|
||||
//char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 } , {\"speaker\" : \" the president \" } , 25, \"tttt\" ]";
|
||||
struct js_value *js = create_js_value(val, NULL);
|
||||
|
||||
// LOG("key : %s\n lenKey: %ld \n",js->type.object.key, js->type.object.key_length);
|
||||
|
||||
/*
|
||||
LOG("value : %s\n",js->type.object.value->type.string);
|
||||
LOG("value : %Lf\n",js->type.object.next_object->type.object.value->type.number);
|
||||
LOG("value : %s\n",js->type.object.next_object->type.object.next_object->type.object.value->type.string);
|
||||
*/
|
||||
|
||||
print_value(js);
|
||||
|
||||
/*
|
||||
char *rrjson = original_string_js_value(js);
|
||||
printf("original :%s\n",rrjson);
|
||||
char *rrjson1 = original_string_js_value(js->type.array.next_element);
|
||||
printf("original 1 :%s\n",rrjson1);
|
||||
*/
|
||||
free_js_value(js);
|
||||
|
||||
// free(rrjson);
|
||||
// free(rrjson1);
|
||||
LOG("line %d\n",__LINE__);
|
||||
|
||||
}
|
||||
|
||||
TEST(general_val2){
|
||||
|
||||
char *val = "{ \"array\" : [ \"message\" , \"Hello! it's a string\" , [{},{},[ [ ] ] ] , { \"age\" : 48 , \"speaker\" : \" the president \" } , 45 , true ] , \"second\" : 324.1 , \"person\" : { \"name\" : \"Fana\" , \"age\" : 37 , \"genre\" : \"male\" , \"married\" : false , \"note\" : [2.1,4.45,4,10, { \"math\" : 17.1, \"malagasy\" : 12, \"eps\" : [ 5, 6 , 4 ] }] } , \"nul\" : { } }";
|
||||
//char *val = "{ \"array\" : [ \"message\", \"Hello! it's a string\", { \"age\" : 48, \"speaker\" : \" the president \" }, 45, true ], \"second\" : [ 324.1, 1 , { \"math\" : 17.1 } ] }";
|
||||
//char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 } , {\"speaker\" : \" the president \" } , 25, \"tttt\" ]";
|
||||
struct js_value *js = create_js_value(val, NULL);
|
||||
|
||||
// LOG("key : %s\n lenKey: %ld \n",js->type.object.key, js->type.object.key_length);
|
||||
|
||||
/*
|
||||
LOG("value : %s\n",js->type.object.value->type.string);
|
||||
LOG("value : %Lf\n",js->type.object.next_object->type.object.value->type.number);
|
||||
LOG("value : %s\n",js->type.object.next_object->type.object.next_object->type.object.value->type.string);
|
||||
*/
|
||||
|
||||
print_value(js);
|
||||
|
||||
/*
|
||||
char *rrjson = original_string_js_value(js);
|
||||
printf("original :%s\n",rrjson);
|
||||
char *rrjson1 = original_string_js_value(js->type.array.next_element);
|
||||
printf("original 1 :%s\n",rrjson1);
|
||||
*/
|
||||
free_js_value(js);
|
||||
LOG("line %d\n",__LINE__);
|
||||
|
||||
// free(rrjson);
|
||||
// free(rrjson1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(add_val){
|
||||
|
||||
char *val = "{ \"array\" : [ \"message\" , \"Hello! it's a string\" , [{},{},[ [ ] ] ] , { \"age\" : 48 , \"speaker\" : \" the president \" } , 45 , true ] , \"second\" : 324.1 , \"person\" : { \"name\" : \"Fana\" , \"age\" : 37 , \"genre\" : \"male\" , \"married\" : false , \"note\" : [2.1,4.45,4,10, { \"math\" : 17.1, \"malagasy\" : 12, \"eps\" : [ 5, 6 , 4 ] }] } , \"nul\" : { } }";
|
||||
//char *val = "{ \"array\" : [ \"message\", \"Hello! it's a string\", { \"age\" : 48, \"speaker\" : \" the president \" }, 45, true ], \"second\" : [ 324.1, 1 , { \"math\" : 17.1 } ] }";
|
||||
//char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 } , {\"speaker\" : \" the president \" } , 25, \"tttt\" ]";
|
||||
|
||||
struct js_value *js = create_js_value(val, NULL);
|
||||
|
||||
char *add ="{ \"add0\" : 0.0 , \"addname\" : \"Fanasina\" }";
|
||||
|
||||
struct js_value *js_add = create_js_value(add, NULL);
|
||||
|
||||
|
||||
print_value(js);
|
||||
add_js_value_index(10, js_add, &js);
|
||||
print_value(js);
|
||||
free_js_value(js);
|
||||
LOG("line %d\n",__LINE__);
|
||||
|
||||
// free(rrjson);
|
||||
// free(rrjson1);
|
||||
|
||||
}
|
||||
TEST(append_val){
|
||||
|
||||
char *val = "{ \"array\" : [ \"message\" , \"Hello! it's a string\" , [{},{},[ [ ] ] ] , { \"age\" : 48 , \"speaker\" : \" the president \" } , 45 , true ] , \"second\" : 324.1 , \"person\" : { \"name\" : \"Fana\" , \"age\" : 37 , \"genre\" : \"male\" , \"married\" : false , \"note\" : [2.1,4.45,4,10, { \"math\" : 17.1, \"malagasy\" : 12, \"eps\" : [ 5, 6 , 4 ] }] } , \"nul\" : { } }";
|
||||
//char *val = "{ \"array\" : [ \"message\", \"Hello! it's a string\", { \"age\" : 48, \"speaker\" : \" the president \" }, 45, true ], \"second\" : [ 324.1, 1 , { \"math\" : 17.1 } ] }";
|
||||
//char *val = "[ \"message\" , \"Hello! it's a string\" , { \"age\" : 48 } , {\"speaker\" : \" the president \" } , 25, \"tttt\" ]";
|
||||
|
||||
struct js_value *js = create_js_value(val, NULL);
|
||||
|
||||
char *add ="{ \"add0\" : 0.0 }";
|
||||
|
||||
// struct js_value *js_add = create_js_value(add, NULL);
|
||||
|
||||
|
||||
print_value(js);
|
||||
// add_js_value_index(10, js_add, &js);
|
||||
append_js_value(js,add);
|
||||
print_value(js);
|
||||
|
||||
char *add_arr ="{ \"array\" : [ 0.0 ] }";
|
||||
append_js_value(js,add_arr);
|
||||
print_value(js);
|
||||
|
||||
|
||||
free_js_value(js);
|
||||
LOG("line %d\n",__LINE__);
|
||||
|
||||
// free(rrjson);
|
||||
// free(rrjson1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
run_all_tests_args(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user