celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [1/2] celix git commit: CELIX-316: Fix issue with 'N' descriptor
Date Thu, 03 Dec 2015 11:09:53 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 8f379dfe2 -> f26cc7864


CELIX-316: Fix issue with 'N' descriptor


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/e61ef6f3
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/e61ef6f3
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/e61ef6f3

Branch: refs/heads/develop
Commit: e61ef6f3ab49826fdff9f97321b9a3ae858e23e2
Parents: 8f379df
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Thu Dec 3 12:05:14 2015 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Thu Dec 3 12:05:14 2015 +0100

----------------------------------------------------------------------
 dfi/private/src/json_serializer.c          |   2 +-
 dfi/private/test/json_serializer_tests.cpp | 626 +++++++++++++-----------
 2 files changed, 338 insertions(+), 290 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/e61ef6f3/dfi/private/src/json_serializer.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_serializer.c b/dfi/private/src/json_serializer.c
index 8d42bb4..1a9b4b0 100644
--- a/dfi/private/src/json_serializer.c
+++ b/dfi/private/src/json_serializer.c
@@ -179,7 +179,7 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val)
{
             break;
         case 'N' :
             n = loc;
-            *n = (int) json_real_value(val);
+            *n = (int) json_integer_value(val);
             break;
         case 'B' :
             b = loc;

http://git-wip-us.apache.org/repos/asf/celix/blob/e61ef6f3/dfi/private/test/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/json_serializer_tests.cpp b/dfi/private/test/json_serializer_tests.cpp
index 70b0147..4df8fcf 100644
--- a/dfi/private/test/json_serializer_tests.cpp
+++ b/dfi/private/test/json_serializer_tests.cpp
@@ -33,12 +33,12 @@ extern "C" {
 #include "json_serializer.h"
 
 static void stdLog(void *handle, int level, const char *file, int line, const char *msg,
...) {
-    va_list ap;
-    const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
-    fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
-    va_start(ap, msg);
-    vfprintf(stderr, msg, ap);
-    fprintf(stderr, "\n");
+	va_list ap;
+	const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+	fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+	va_start(ap, msg);
+	vfprintf(stderr, msg, ap);
+	fprintf(stderr, "\n");
 }
 
 /*********** example 1 ************************/
@@ -54,20 +54,20 @@ const char *example1_input = "{ \
 }";
 
 struct example1 {
-    double a;   //0
-    int64_t b;  //1
-    int32_t c;  //2
-    int16_t d;  //3
-    float e;    //4
+	double a;   //0
+	int64_t b;  //1
+	int32_t c;  //2
+	int16_t d;  //3
+	float e;    //4
 };
 
 static void check_example1(void *data) {
-    struct example1 *ex = (struct example1 *)data;
-    CHECK_EQUAL(1.0, ex->a);
-    LONGS_EQUAL(22, ex->b);
-    LONGS_EQUAL(32, ex->c);
-    LONGS_EQUAL(42, ex->d);
-    CHECK_EQUAL(4.4f, ex->e);
+	struct example1 *ex = (struct example1 *)data;
+	CHECK_EQUAL(1.0, ex->a);
+	LONGS_EQUAL(22, ex->b);
+	LONGS_EQUAL(32, ex->c);
+	LONGS_EQUAL(42, ex->d);
+	CHECK_EQUAL(4.4f, ex->e);
 }
 
 /*********** example 2 ************************/
@@ -83,22 +83,22 @@ const char *example2_input = "{ \
 }";
 
 struct example2 {
-    char byte;      //0
-    int64_t long1;     //1
-    int64_t long2;     //2
-    double double1; //3
-    float float1;   //4
-    double double2; //5
+	char byte;      //0
+	int64_t long1;     //1
+	int64_t long2;     //2
+	double double1; //3
+	float float1;   //4
+	double double2; //5
 };
 
 static void check_example2(void *data) {
-    struct example2 *ex = (struct example2 *)data;
-    CHECK_EQUAL(42, ex->byte);
-    LONGS_EQUAL(232, ex->long1);
-    LONGS_EQUAL(242, ex->long2);
-    CHECK_EQUAL(4.2, ex->double1);
-    CHECK_EQUAL(3.2f, ex->float1);
-    CHECK_EQUAL(4.4, ex->double2);
+	struct example2 *ex = (struct example2 *)data;
+	CHECK_EQUAL(42, ex->byte);
+	LONGS_EQUAL(232, ex->long1);
+	LONGS_EQUAL(242, ex->long2);
+	CHECK_EQUAL(4.2, ex->double1);
+	CHECK_EQUAL(3.2f, ex->float1);
+	CHECK_EQUAL(4.4, ex->double2);
 }
 
 
@@ -111,19 +111,19 @@ const char *example3_input = "{ \
 }";
 
 struct example3 {
-    struct {
-        uint32_t cap;
-        uint32_t len;
-        int32_t *buf;
-    } numbers;
+	struct {
+		uint32_t cap;
+		uint32_t len;
+		int32_t *buf;
+	} numbers;
 };
 
 static void check_example3(void *data) {
-    struct example3 *ex = (struct example3 *)data;
-    CHECK_EQUAL(3, ex->numbers.len);
-    CHECK_EQUAL(22, ex->numbers.buf[0]);
-    CHECK_EQUAL(32, ex->numbers.buf[1]);
-    CHECK_EQUAL(42, ex->numbers.buf[2]);
+	struct example3 *ex = (struct example3 *)data;
+	CHECK_EQUAL(3, ex->numbers.len);
+	CHECK_EQUAL(22, ex->numbers.buf[0]);
+	CHECK_EQUAL(32, ex->numbers.buf[1]);
+	CHECK_EQUAL(42, ex->numbers.buf[2]);
 }
 
 /*********** example 4 ************************/
@@ -136,24 +136,24 @@ static const char *example4_input =  "{ \
 }";
 
 struct ex4_leaf {
-    int32_t index;
-    double val1;
-    double val2;
+	int32_t index;
+	double val1;
+	double val2;
 };
 
 struct example4 {
-    struct ex4_leaf left;
-    struct ex4_leaf right;
+	struct ex4_leaf left;
+	struct ex4_leaf right;
 };
 
 static void check_example4(void *data) {
-    struct example4 *ex = (struct example4 *)data;
-    CHECK_EQUAL(1, ex->left.index);
-    CHECK_EQUAL(1.0, ex->left.val1);
-    CHECK_EQUAL(2.0, ex->left.val2);
-    CHECK_EQUAL(2, ex->right.index);
-    CHECK_EQUAL(5.0, ex->right.val1);
-    CHECK_EQUAL(4.0, ex->right.val2);
+	struct example4 *ex = (struct example4 *)data;
+	CHECK_EQUAL(1, ex->left.index);
+	CHECK_EQUAL(1.0, ex->left.val1);
+	CHECK_EQUAL(2.0, ex->left.val2);
+	CHECK_EQUAL(2, ex->right.index);
+	CHECK_EQUAL(5.0, ex->right.val1);
+	CHECK_EQUAL(4.0, ex->right.val2);
 }
 
 
@@ -179,37 +179,37 @@ static const char *example5_input =  "{ \
 }";
 
 struct leaf {
-    const char *name;
-    uint16_t age;
+	const char *name;
+	uint16_t age;
 };
 
 struct node {
-    struct node *left;
-    struct node *right;
-    struct leaf *value;
+	struct node *left;
+	struct node *right;
+	struct leaf *value;
 };
 
 struct example5 {
-    struct node *head;
+	struct node *head;
 };
 
 static void check_example5(void *data) {
-    struct example5 *ex = (struct example5 *)data;
-    CHECK_TRUE(ex->head != NULL);
-
-    CHECK(ex->head->left != NULL);
-    CHECK(ex->head->left->value != NULL);
-    STRCMP_EQUAL("John", ex->head->left->value->name);
-    CHECK_EQUAL(44, ex->head->left->value->age);
-    CHECK(ex->head->left->left == NULL);
-    CHECK(ex->head->left->right == NULL);
-
-    CHECK(ex->head->right != NULL);
-    CHECK(ex->head->right->value != NULL);
-    STRCMP_EQUAL("Peter", ex->head->right->value->name);
-    CHECK_EQUAL(55, ex->head->right->value->age);
-    CHECK(ex->head->right->left == NULL);
-    CHECK(ex->head->right->right == NULL);
+	struct example5 *ex = (struct example5 *)data;
+	CHECK_TRUE(ex->head != NULL);
+
+	CHECK(ex->head->left != NULL);
+	CHECK(ex->head->left->value != NULL);
+	STRCMP_EQUAL("John", ex->head->left->value->name);
+	CHECK_EQUAL(44, ex->head->left->value->age);
+	CHECK(ex->head->left->left == NULL);
+	CHECK(ex->head->left->right == NULL);
+
+	CHECK(ex->head->right != NULL);
+	CHECK(ex->head->right->value != NULL);
+	STRCMP_EQUAL("Peter", ex->head->right->value->name);
+	CHECK_EQUAL(55, ex->head->right->value->age);
+	CHECK(ex->head->right->left == NULL);
+	CHECK(ex->head->right->right == NULL);
 }
 
 static const char *example6_descriptor = "Tsample={DD v1 v2};[lsample;";
@@ -217,25 +217,25 @@ static const char *example6_descriptor = "Tsample={DD v1 v2};[lsample;";
 static const char *example6_input = "[{\"v1\":0.1,\"v2\":0.2},{\"v1\":1.1,\"v2\":1.2},{\"v1\":2.1,\"v2\":2.2}]";
 
 struct ex6_sample {
-    double v1;
-    double v2;
+	double v1;
+	double v2;
 };
 
 struct ex6_sequence {
-    uint32_t cap;
-    uint32_t len;
-    struct ex6_sample *buf;
+	uint32_t cap;
+	uint32_t len;
+	struct ex6_sample *buf;
 };
 
 static void check_example6(struct ex6_sequence seq) {
-    CHECK_EQUAL(3, seq.cap);
-    CHECK_EQUAL(3, seq.len);
-    CHECK_EQUAL(0.1, seq.buf[0].v1);
-    CHECK_EQUAL(0.2, seq.buf[0].v2);
-    CHECK_EQUAL(1.1, seq.buf[1].v1);
-    CHECK_EQUAL(1.2, seq.buf[1].v2);
-    CHECK_EQUAL(2.1, seq.buf[2].v1);
-    CHECK_EQUAL(2.2, seq.buf[2].v2);
+	CHECK_EQUAL(3, seq.cap);
+	CHECK_EQUAL(3, seq.len);
+	CHECK_EQUAL(0.1, seq.buf[0].v1);
+	CHECK_EQUAL(0.2, seq.buf[0].v2);
+	CHECK_EQUAL(1.1, seq.buf[1].v1);
+	CHECK_EQUAL(1.2, seq.buf[1].v2);
+	CHECK_EQUAL(2.1, seq.buf[2].v1);
+	CHECK_EQUAL(2.2, seq.buf[2].v2);
 }
 
 
@@ -247,232 +247,280 @@ const char *example7_input = "{ \
 }";
 
 struct example7 {
-    char* a;   //0
+	char* a;   //0
 };
 
 static void check_example7(void *data) {
-    struct example7 *ex = (struct example7 *)data;
-    STRCMP_EQUAL("apache celix", ex->a);
+	struct example7 *ex = (struct example7 *)data;
+	STRCMP_EQUAL("apache celix", ex->a);
 }
 
+
+/*********** example 8 ************************/
+
+const char *example8_descriptor = "{ZbijNP a b c d e f}";
+
+const char *example8_input = "{ \
+    \"a\" : true, \
+    \"b\" : 4, \
+    \"c\" : 8, \
+    \"d\" : 16, \
+    \"e\" : 32 \
+}";
+
+struct example8 {
+	bool a;
+	unsigned char b;
+	uint32_t c;
+	uint64_t d;
+	int e;
+	void* f;
+};
+
+static void check_example8(void *data) {
+	struct example8 *ex = (struct example8 *)data;
+	CHECK_EQUAL(true,ex->a);
+	CHECK_EQUAL(4,ex->b);
+	CHECK_EQUAL(8,ex->c);
+	CHECK_EQUAL(16,ex->d);
+	CHECK_EQUAL(32,ex->e);
+}
+
+
 static void parseTests(void) {
-    dyn_type *type;
-    void *inst;
-    int rc;
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example1_descriptor, NULL, NULL, &type);    
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example1_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example1(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example2_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example2_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example2(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example3_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example3_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example3(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example4_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example4_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example4(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example5_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example5_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example5(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
-
-    type = NULL;
-    struct ex6_sequence *seq;
-    rc = dynType_parseWithStr(example6_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example6_input, (void **)&seq);
-    CHECK_EQUAL(0, rc);
-    check_example6((*seq));
-    dynType_free(type, seq);
-    dynType_destroy(type);
-
-
-    type = NULL;
-    inst = NULL;
-    rc = dynType_parseWithStr(example7_descriptor, NULL, NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_deserialize(type, example7_input, &inst);
-    CHECK_EQUAL(0, rc);
-    check_example7(inst);
-    dynType_free(type, inst);
-    dynType_destroy(type);
+	dyn_type *type;
+	void *inst;
+	int rc;
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example1_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example1_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example1(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example2_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example2_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example2(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example3_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example3_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example3(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example4_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example4_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example4(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example5_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example5_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example5(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	struct ex6_sequence *seq;
+	rc = dynType_parseWithStr(example6_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example6_input, (void **)&seq);
+	CHECK_EQUAL(0, rc);
+	check_example6((*seq));
+	dynType_free(type, seq);
+	dynType_destroy(type);
+
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example7_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example7_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example7(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
+
+	type = NULL;
+	inst = NULL;
+	rc = dynType_parseWithStr(example8_descriptor, NULL, NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_deserialize(type, example8_input, &inst);
+	CHECK_EQUAL(0, rc);
+	check_example8(inst);
+	dynType_free(type, inst);
+	dynType_destroy(type);
 }
 
-const char *write_example1_descriptor = "{BSIJsijFDN a b c d e f g h i j}";
+const char *write_example1_descriptor = "{BSIJsijFDNZb a b c d e f g h i j k l}";
 
 struct write_example1 {
-    char a;
-    int16_t b;
-    int32_t c;
-    int64_t d;
-    uint16_t e;
-    uint32_t f;
-    uint64_t g;
-    float h;
-    double i;
-    int j;
+	char a;
+	int16_t b;
+	int32_t c;
+	int64_t d;
+	uint16_t e;
+	uint32_t f;
+	uint64_t g;
+	float h;
+	double i;
+	int j;
+	bool k;
+	unsigned char l;
 };
 
 void writeTest1(void) {
-    struct write_example1 ex1;
-    ex1.a=1;
-    ex1.b=2;
-    ex1.c=3;
-    ex1.d=4;
-    ex1.e=5;
-    ex1.f=6;
-    ex1.g=7;
-    ex1.h=8.8f;
-    ex1.i=9.9;
-    ex1.j=10;
-
-    dyn_type *type = NULL;
-    char *result = NULL;
-    int rc = dynType_parseWithStr(write_example1_descriptor, "ex1", NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_serialize(type, &ex1, &result);
-    CHECK_EQUAL(0, rc);
-    STRCMP_CONTAINS("\"a\":1", result);
-    STRCMP_CONTAINS("\"b\":2", result);
-    STRCMP_CONTAINS("\"c\":3", result);
-    STRCMP_CONTAINS("\"d\":4", result);
-    STRCMP_CONTAINS("\"e\":5", result);
-    STRCMP_CONTAINS("\"f\":6", result);
-    STRCMP_CONTAINS("\"g\":7", result);
-    STRCMP_CONTAINS("\"h\":8.8", result);
-    STRCMP_CONTAINS("\"i\":9.9", result);
-    STRCMP_CONTAINS("\"j\":10", result);
-    //printf("example 1 result: '%s'\n", result);
-    dynType_destroy(type);
-    free(result);
+	struct write_example1 ex1;
+	ex1.a=1;
+	ex1.b=2;
+	ex1.c=3;
+	ex1.d=4;
+	ex1.e=5;
+	ex1.f=6;
+	ex1.g=7;
+	ex1.h=8.8f;
+	ex1.i=9.9;
+	ex1.j=10;
+	ex1.k=true;
+	ex1.l=12;
+
+	dyn_type *type = NULL;
+	char *result = NULL;
+	int rc = dynType_parseWithStr(write_example1_descriptor, "ex1", NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_serialize(type, &ex1, &result);
+	CHECK_EQUAL(0, rc);
+	STRCMP_CONTAINS("\"a\":1", result);
+	STRCMP_CONTAINS("\"b\":2", result);
+	STRCMP_CONTAINS("\"c\":3", result);
+	STRCMP_CONTAINS("\"d\":4", result);
+	STRCMP_CONTAINS("\"e\":5", result);
+	STRCMP_CONTAINS("\"f\":6", result);
+	STRCMP_CONTAINS("\"g\":7", result);
+	STRCMP_CONTAINS("\"h\":8.8", result);
+	STRCMP_CONTAINS("\"i\":9.9", result);
+	STRCMP_CONTAINS("\"j\":10", result);
+	STRCMP_CONTAINS("\"k\":true", result);
+	STRCMP_CONTAINS("\"l\":12", result);
+	//printf("example 1 result: '%s'\n", result);
+	dynType_destroy(type);
+	free(result);
 }
 
 const char *write_example2_descriptor = "{*{JJ a b}{SS c d} sub1 sub2}";
 
 struct write_example2_sub {
-        int64_t a;
-        int64_t b;
+	int64_t a;
+	int64_t b;
 };
 
 struct write_example2 {
-    struct write_example2_sub *sub1;
-    struct {
-        int16_t c;
-        int16_t d;
-    } sub2;
+	struct write_example2_sub *sub1;
+	struct {
+		int16_t c;
+		int16_t d;
+	} sub2;
 };
 
 void writeTest2(void) {
-    struct write_example2_sub sub1;
-    sub1.a = 1;
-    sub1.b = 2;
-
-    struct write_example2 ex;
-    ex.sub1=&sub1;
-    ex.sub2.c = 3;
-    ex.sub2.d = 4;
-
-    dyn_type *type = NULL;
-    char *result = NULL;
-    int rc = dynType_parseWithStr(write_example2_descriptor, "ex2", NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_serialize(type, &ex, &result);
-    CHECK_EQUAL(0, rc);
-    STRCMP_CONTAINS("\"a\":1", result);
-    STRCMP_CONTAINS("\"b\":2", result);
-    STRCMP_CONTAINS("\"c\":3", result);
-    STRCMP_CONTAINS("\"d\":4", result);
-    //printf("example 2 result: '%s'\n", result);
-    dynType_destroy(type);
-    free(result);
+	struct write_example2_sub sub1;
+	sub1.a = 1;
+	sub1.b = 2;
+
+	struct write_example2 ex;
+	ex.sub1=&sub1;
+	ex.sub2.c = 3;
+	ex.sub2.d = 4;
+
+	dyn_type *type = NULL;
+	char *result = NULL;
+	int rc = dynType_parseWithStr(write_example2_descriptor, "ex2", NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_serialize(type, &ex, &result);
+	CHECK_EQUAL(0, rc);
+	STRCMP_CONTAINS("\"a\":1", result);
+	STRCMP_CONTAINS("\"b\":2", result);
+	STRCMP_CONTAINS("\"c\":3", result);
+	STRCMP_CONTAINS("\"d\":4", result);
+	//printf("example 2 result: '%s'\n", result);
+	dynType_destroy(type);
+	free(result);
 }
 
 const char *write_example3_descriptor = "Tperson={ti name age};[Lperson;";
 
 struct write_example3_person {
-    const char *name;
-    uint32_t age;
+	const char *name;
+	uint32_t age;
 };
 
 struct write_example3 {
-    uint32_t cap;
-    uint32_t len;
-    struct write_example3_person **buf;
+	uint32_t cap;
+	uint32_t len;
+	struct write_example3_person **buf;
 };
 
 void writeTest3(void) {
-    struct write_example3_person p1;
-    p1.name = "John";
-    p1.age = 33;
-
-    struct write_example3_person p2;
-    p2.name = "Peter";
-    p2.age = 44;
-
-    struct write_example3_person p3;
-    p3.name = "Carol";
-    p3.age = 55;
-
-    struct write_example3_person p4;
-    p4.name = "Elton";
-    p4.age = 66;
-
-    struct write_example3 seq;
-    seq.buf = (struct write_example3_person **) calloc(4, sizeof(void *));
-    seq.len = seq.cap = 4;
-    seq.buf[0] = &p1;
-    seq.buf[1] = &p2;
-    seq.buf[2] = &p3;
-    seq.buf[3] = &p4;
-
-    dyn_type *type = NULL;
-    char *result = NULL;
-    int rc = dynType_parseWithStr(write_example3_descriptor, "ex3", NULL, &type);
-    CHECK_EQUAL(0, rc);
-    rc = jsonSerializer_serialize(type, &seq, &result);
-    CHECK_EQUAL(0, rc);
-    STRCMP_CONTAINS("\"age\":33", result);
-    STRCMP_CONTAINS("\"age\":44", result);
-    STRCMP_CONTAINS("\"age\":55", result);
-    STRCMP_CONTAINS("\"age\":66", result);
-    //printf("example 3 result: '%s'\n", result);
-    free(seq.buf);
-    dynType_destroy(type);
-    free(result);
+	struct write_example3_person p1;
+	p1.name = "John";
+	p1.age = 33;
+
+	struct write_example3_person p2;
+	p2.name = "Peter";
+	p2.age = 44;
+
+	struct write_example3_person p3;
+	p3.name = "Carol";
+	p3.age = 55;
+
+	struct write_example3_person p4;
+	p4.name = "Elton";
+	p4.age = 66;
+
+	struct write_example3 seq;
+	seq.buf = (struct write_example3_person **) calloc(4, sizeof(void *));
+	seq.len = seq.cap = 4;
+	seq.buf[0] = &p1;
+	seq.buf[1] = &p2;
+	seq.buf[2] = &p3;
+	seq.buf[3] = &p4;
+
+	dyn_type *type = NULL;
+	char *result = NULL;
+	int rc = dynType_parseWithStr(write_example3_descriptor, "ex3", NULL, &type);
+	CHECK_EQUAL(0, rc);
+	rc = jsonSerializer_serialize(type, &seq, &result);
+	CHECK_EQUAL(0, rc);
+	STRCMP_CONTAINS("\"age\":33", result);
+	STRCMP_CONTAINS("\"age\":44", result);
+	STRCMP_CONTAINS("\"age\":55", result);
+	STRCMP_CONTAINS("\"age\":66", result);
+	//printf("example 3 result: '%s'\n", result);
+	free(seq.buf);
+	dynType_destroy(type);
+	free(result);
 }
 
 
@@ -480,29 +528,29 @@ void writeTest3(void) {
 }
 
 TEST_GROUP(JsonSerializerTests) {
-    void setup() {
-        int lvl = 1;
-        dynCommon_logSetup(stdLog, NULL, lvl);
-        dynType_logSetup(stdLog, NULL,lvl);
-        jsonSerializer_logSetup(stdLog, NULL, lvl);
-    }
+	void setup() {
+		int lvl = 1;
+		dynCommon_logSetup(stdLog, NULL, lvl);
+		dynType_logSetup(stdLog, NULL,lvl);
+		jsonSerializer_logSetup(stdLog, NULL, lvl);
+	}
 };
 
 TEST(JsonSerializerTests, ParseTests) {
-    //TODO split up
-    parseTests();
+	//TODO split up
+	parseTests();
 }
 
 TEST(JsonSerializerTests, WriteTest1) {
-    writeTest1();
+	writeTest1();
 }
 
 TEST(JsonSerializerTests, WriteTest2) {
-    writeTest2();
+	writeTest2();
 }
 
 TEST(JsonSerializerTests, WriteTest3) {
-    writeTest3();
+	writeTest3();
 }
 
 


Mime
View raw message