From ae5751fe25355bc1ddbc1604bb1d60e6465f1110 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Fri, 18 Nov 2011 00:01:31 +0100 Subject: [PATCH] <> class definition --- ChangeLog | 14 +++++++++++++- createToken.c | 27 ++++++++++++++------------- include/token/cclass.h | 31 ++++++++++++++++++++++--------- include/token/crypt.h | 28 ++++++++-------------------- include/token/dyntype.h | 13 +++++-------- include/token/dyntype/hash.h | 20 ++++++-------------- include/token/packet.h | 28 ++++++++-------------------- src/cclass.c | 10 +++++----- src/crypt.c | 12 ++++++------ src/dyntype.c | 12 ++++++------ src/dyntype/hash.c | 34 +++++++++++++++------------------- src/packet.c | 24 +++++++++--------------- tests/cclassTest.c | 2 +- tests/cryptTest.c | 2 +- tests/mock/class.c | 12 ++++++------ tests/mock/class.h | 11 +++++------ tests/packet.c | 23 ++++++++++++----------- tests/packetTest.c | 2 +- tests/runtest.h | 2 +- 19 files changed, 144 insertions(+), 163 deletions(-) diff --git a/ChangeLog b/ChangeLog index 554f5ae..934b4e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,18 @@ +2011-11-18 00:01:31 +0100 Georg Hopp + + * <> class definition (HEAD, master) + +2011-11-17 14:33:33 +0100 Georg Hopp + + * Merge branch 'master' of 192.168.10.10:/var/lib/git/token (origin/master, origin/HEAD) + +2011-11-17 14:32:08 +0100 Georg Hopp + + * add extra dist files to Makefile.am + 2011-11-17 14:32:08 +0100 Georg Hopp - * add extra dist files to Makefile.am (HEAD, origin/master, origin/HEAD, master) + * add extra dist files to Makefile.am 2011-11-17 13:32:46 +0100 Georg Hopp diff --git a/createToken.c b/createToken.c index a36691b..b90d487 100644 --- a/createToken.c +++ b/createToken.c @@ -10,27 +10,27 @@ void -setHashString(struct DYNTYPE_HASH * hash, const char * const key, const char * value) +setHashString(DYNTYPE_HASH hash, const char * const key, const char * value) { - struct DYNTYPE * dyn; + DYNTYPE dyn; dyn = new(DYNTYPE, DYNTYPE_TYPE_STRING, strlen(value), value); dyntype_hash_set(hash, key, dyn); } void -setHashInt(struct DYNTYPE_HASH * hash, const char * const key, const int value) +setHashInt(DYNTYPE_HASH hash, const char * const key, const int value) { - struct DYNTYPE * dyn; + DYNTYPE dyn; dyn = new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), value); dyntype_hash_set(hash, key, dyn); } void -deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key) +deleteHashValue(DYNTYPE_HASH hash, const char * const key) { - struct DYNTYPE * dyn = dyntype_hash_get(hash, key); + DYNTYPE dyn = dyntype_hash_get(hash, key); delete(&dyn); } @@ -38,10 +38,11 @@ deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key) int main(int argc, char * argv[]) { - struct CRYPT * crypt; - struct PACKET * packet; - struct DYNTYPE_HASH * data; - struct DYNTYPE * _clear; + CRYPT crypt; + PACKET packet; + DYNTYPE_HASH data; + DYNTYPE _clear; + struct json_object * json; const char * json_str; char * encrypted; @@ -49,13 +50,13 @@ main(int argc, char * argv[]) char pass[] = "1234"; size_t length; - packet = new(PACKET); + packet = new(PACKET, NULL); packet_setHeader( packet, new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), time(NULL))); - data = new(DYNTYPE_HASH); + data = new(DYNTYPE_HASH, NULL); setHashString(data, "#C#", "this comes from C"); setHashString(data, "usr", "ppohg"); @@ -66,7 +67,7 @@ main(int argc, char * argv[]) packet, new(DYNTYPE, DYNTYPE_TYPE_HASH, - sizeof(struct DYNTYPE_HASH *), + sizeof(DYNTYPE_HASH), data)); json = toJson(packet); diff --git a/include/token/cclass.h b/include/token/cclass.h index db386ed..d93981f 100644 --- a/include/token/cclass.h +++ b/include/token/cclass.h @@ -22,17 +22,26 @@ #include #include +#define SWAP(a, b) a ^= b; b ^= a; a ^= b; + #define CCLASS_MAGIC 0xFEFE -#define INIT_CCLASS(name, jsonConst, toJson) \ - static const struct CCLASS _##name = { \ +#define CLASS(_class) \ + typedef struct _##_class { \ + const _CCLASS const class; + +#define ENDC(_class) } * _class; \ + extern const _CCLASS const __##_class; + +#define INIT_CCLASS(class, jsonConst, toJson) \ + static const struct CCLASS _class = { \ CCLASS_MAGIC, \ - sizeof(struct name), \ + sizeof(struct _##class), \ (ctor)__construct, \ (jCtor)jsonConst, \ (dtor)__destruct, \ (jTo)toJson \ - }; const struct CCLASS * const name = &_##name + }; const _CCLASS const __##class = &_class @@ -42,23 +51,27 @@ typedef void (* jCtor)(void *, struct json_object *); typedef struct json_object * (* jTo)(void *); -struct CCLASS { +typedef struct CCLASS { const int magic; size_t size; void (* __construct)(void * _this, va_list * params); void (* __jsonConst)(void * _this, struct json_object * json); void (* __destruct)(void * _this); struct json_object * (* __toJson)(void * _this); -}; +} * _CCLASS; #define CCLASS_PTR_SIZE sizeof(struct CCLASS *) #define CCLASS_SIZE sizeof(struct CCLASS) -void * new(const void * _class, ...); -void * newFromJson(const void * _class, struct json_object * json); +void * _new(const void * _class, ...); +void * _newFromJson(const void * _class, struct json_object * json); void delete(void * _object); struct json_object * toJson(void * _object); int isObject(void * _object); -int instanceOf(const void * _class, void * _object); +int _instanceOf(const void * _class, void * _object); + +#define new(class, ...) _new((__##class), __VA_ARGS__) +#define newFromJson(class, json) _newFromJson((__##class), (json)) +#define instanceOf(class, object) _instanceOf((__##class), (object)) #endif//__CCLASS_H__ diff --git a/include/token/crypt.h b/include/token/crypt.h index 3a5545c..faf4a8d 100644 --- a/include/token/crypt.h +++ b/include/token/crypt.h @@ -23,44 +23,32 @@ #include "token/cclass.h" -struct CRYPT { - const struct CCLASS * const class; +CLASS(CRYPT) const char * algorithm; const char * mode; MCRYPT mcrypt; size_t ivsize; size_t keysize; void * iv; -}; +ENDC(CRYPT) -extern const struct CCLASS * const CRYPT; void * crypt_encrypt( - struct CRYPT * _this, + CRYPT _this, const void * const data, const char * const password, size_t * length); void * crypt_decrypt( - struct CRYPT * _this, + CRYPT _this, const void * const data, const char * const password, size_t * length); -void * crypt_createIv( - struct CRYPT * _this); - -void crypt_setIv( - struct CRYPT * _this, - const void * const iv); - -void crypt_setIvsize( - struct CRYPT * _this, - const size_t size); - -void crypt_setKeysize( - struct CRYPT * _this, - const size_t size); +void * crypt_createIv(CRYPT _this); +void crypt_setIv(CRYPT _this, const void * const iv); +void crypt_setIvsize(CRYPT _this, const size_t size); +void crypt_setKeysize(CRYPT _this, const size_t size); #endif//__CRYPT_H__ // vim: set et ts=4 sw=4: diff --git a/include/token/dyntype.h b/include/token/dyntype.h index 49ecb9d..87f11cf 100644 --- a/include/token/dyntype.h +++ b/include/token/dyntype.h @@ -22,7 +22,7 @@ #include "token/cclass.h" -struct DYNTYPE; +struct _DYNTYPE; #include "token/dyntype/hash.h" @@ -38,8 +38,7 @@ enum DYNTYPE_TYPES { }; -struct DYNTYPE { - const struct CCLASS * const class; +CLASS(DYNTYPE) enum DYNTYPE_TYPES type; size_t size; union _data { @@ -47,12 +46,10 @@ struct DYNTYPE { int _int; double _float; char * _string; - struct DYNTYPE ** _array; - struct DYNTYPE_HASH * _hash; + struct _DYNTYPE ** _array; + DYNTYPE_HASH _hash; } data; -}; - -extern const struct CCLASS * const DYNTYPE; +ENDC(DYNTYPE) #endif//__DYNTYPE_H__ diff --git a/include/token/dyntype/hash.h b/include/token/dyntype/hash.h index 8c8f63e..7096fbc 100644 --- a/include/token/dyntype/hash.h +++ b/include/token/dyntype/hash.h @@ -24,25 +24,17 @@ #include "token/dyntype.h" -struct DYNTYPE_HASH { - const struct CCLASS * const class; +CLASS(DYNTYPE_HASH) char ** keys; - struct DYNTYPE ** values; + struct _DYNTYPE ** values; size_t size; size_t used; -}; +ENDC(DYNTYPE_HASH) -extern const struct CCLASS * const DYNTYPE_HASH; -void dyntype_hash_set(struct DYNTYPE_HASH * _this, - const char * key, - struct DYNTYPE * value); - -struct DYNTYPE * -dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key); - -struct DYNTYPE * -dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key); +void dyntype_hash_set(DYNTYPE_HASH _this, const char * key, struct _DYNTYPE * value); +struct _DYNTYPE * dyntype_hash_get(DYNTYPE_HASH _this, const char * key); +struct _DYNTYPE * dyntype_hash_del(DYNTYPE_HASH _this, const char * key); #endif//__DYNTYPE_HASH_H__ diff --git a/include/token/packet.h b/include/token/packet.h index f63b5ef..905ee39 100644 --- a/include/token/packet.h +++ b/include/token/packet.h @@ -27,29 +27,17 @@ enum PACKET_CONTENT_KEYS { PACKET_DATA }; -struct PACKET { - const struct CCLASS * const class; - struct DYNTYPE * content[2]; -}; - -extern const struct CCLASS * const PACKET; - -struct DYNTYPE * packet_getHeader( - struct PACKET * _this); - -struct DYNTYPE * packet_getData( - struct PACKET * _this); -void packet_setHeader( - struct PACKET * _this, - struct DYNTYPE * header); +CLASS(PACKET) + DYNTYPE content[2]; +ENDC(PACKET) -void packet_setData( - struct PACKET * _this, - struct DYNTYPE * data); -void packet_set_default_content( - struct PACKET * _this); +DYNTYPE packet_getHeader(PACKET _this); +DYNTYPE packet_getData(PACKET _this); +void packet_setHeader(PACKET _this, DYNTYPE header); +void packet_setData(PACKET _this, DYNTYPE data); +void packet_set_default_content(PACKET _this); #endif//__PACKET_H__ diff --git a/src/cclass.c b/src/cclass.c index 12e53fb..41bc04b 100644 --- a/src/cclass.c +++ b/src/cclass.c @@ -24,10 +24,10 @@ void * -new(const void * _class, ...) +_new(const void * _class, ...) { - const struct CCLASS * class = _class; - void * object = calloc(1, class->size); + const _CCLASS class = _class; + void * object = calloc(1, class->size); * (const struct CCLASS **) object = class; @@ -43,7 +43,7 @@ new(const void * _class, ...) } void * -newFromJson(const void * _class, struct json_object * json) +_newFromJson(const void * _class, struct json_object * json) { const struct CCLASS * class = _class; void * object = calloc(1, class->size); @@ -91,7 +91,7 @@ isObject(void * _object) } int -instanceOf(const void * _class, void * _object) +_instanceOf(const void * _class, void * _object) { const struct CCLASS ** class = _object; diff --git a/src/crypt.c b/src/crypt.c index baf3a83..e056e6f 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -30,7 +30,7 @@ static void -__construct(struct CRYPT * _this, va_list * params) +__construct(CRYPT _this, va_list * params) { _this->algorithm = va_arg(* params, const char * const); _this->mode = va_arg(* params, const char * const); @@ -47,7 +47,7 @@ __construct(struct CRYPT * _this, va_list * params) static void -__destruct(struct CRYPT * _this) +__destruct(CRYPT _this) { if (_this->iv) { free(_this->iv); @@ -59,7 +59,7 @@ __destruct(struct CRYPT * _this) INIT_CCLASS(CRYPT, NULL, NULL); void * -crypt_createIv(struct CRYPT * _this) +crypt_createIv(CRYPT _this) { int urandom; size_t rsize = 0; @@ -80,7 +80,7 @@ crypt_createIv(struct CRYPT * _this) static void * -createKey(struct CRYPT * _this, const char * const password) +createKey(CRYPT _this, const char * const password) { void * key = NULL; @@ -102,7 +102,7 @@ createKey(struct CRYPT * _this, const char * const password) void * crypt_encrypt( - struct CRYPT * _this, + CRYPT _this, const void * const data, const char * const password, size_t * length) @@ -138,7 +138,7 @@ crypt_encrypt( void * crypt_decrypt( - struct CRYPT * _this, + CRYPT _this, const void * const data, const char * const password, size_t * length) diff --git a/src/dyntype.c b/src/dyntype.c index 91a1ecd..e764e76 100644 --- a/src/dyntype.c +++ b/src/dyntype.c @@ -26,7 +26,7 @@ static void -__construct(struct DYNTYPE * _this, va_list * params) +__construct(DYNTYPE _this, va_list * params) { _this->type = va_arg(* params, enum DYNTYPE_TYPES); _this->size = va_arg(* params, size_t); @@ -42,7 +42,7 @@ __construct(struct DYNTYPE * _this, va_list * params) break; case DYNTYPE_TYPE_HASH: - (_this->data)._hash = va_arg(* params, struct DYNTYPE_HASH *); + (_this->data)._hash = va_arg(* params, DYNTYPE_HASH); break; default: @@ -52,7 +52,7 @@ __construct(struct DYNTYPE * _this, va_list * params) static void -__jsonConst(struct DYNTYPE * _this, struct json_object * json) +__jsonConst(DYNTYPE _this, struct json_object * json) { switch (json_object_get_type(json)) { case json_type_int: @@ -75,7 +75,7 @@ __jsonConst(struct DYNTYPE * _this, struct json_object * json) case json_type_object: _this->type = DYNTYPE_TYPE_HASH; - _this->size = sizeof(struct DYNTYPE_HASH *); + _this->size = sizeof(DYNTYPE_HASH); (_this->data)._hash = newFromJson(DYNTYPE_HASH, json); break; @@ -88,7 +88,7 @@ __jsonConst(struct DYNTYPE * _this, struct json_object * json) static void -__destruct(struct DYNTYPE * _this) +__destruct(DYNTYPE _this) { if (_this) { switch(_this->type) { @@ -108,7 +108,7 @@ __destruct(struct DYNTYPE * _this) static struct json_object * -__toJson(struct DYNTYPE * _this) +__toJson(DYNTYPE _this) { struct json_object * json = NULL; diff --git a/src/dyntype/hash.c b/src/dyntype/hash.c index faba9ed..dc2aa1e 100644 --- a/src/dyntype/hash.c +++ b/src/dyntype/hash.c @@ -27,11 +27,11 @@ #define HASH_ENTRY_CHUNK_SIZE 128 -static void _updateHashSize(struct DYNTYPE_HASH * _this); +static void _updateHashSize(DYNTYPE_HASH _this); static void -__construct(struct DYNTYPE_HASH * _this, va_list * params) +__construct(DYNTYPE_HASH _this, va_list * params) { _this->size = 0; _this->used = 0; @@ -40,7 +40,7 @@ __construct(struct DYNTYPE_HASH * _this, va_list * params) static void -__jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json) +__jsonConst(DYNTYPE_HASH _this, struct json_object * json) { __construct(_this, NULL); @@ -55,7 +55,7 @@ __jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json) static void -__destruct(struct DYNTYPE_HASH * _this) +__destruct(DYNTYPE_HASH _this) { size_t index; @@ -69,7 +69,7 @@ __destruct(struct DYNTYPE_HASH * _this) static struct json_object * -__toJson(struct DYNTYPE_HASH * _this) +__toJson(DYNTYPE_HASH _this) { size_t index; struct json_object * json = json_object_new_object(); @@ -88,7 +88,7 @@ INIT_CCLASS(DYNTYPE_HASH, __jsonConst, __toJson); static void -_updateHashSize(struct DYNTYPE_HASH * _this) +_updateHashSize(DYNTYPE_HASH _this) { if (_this->used == _this->size) { _this->size += HASH_ENTRY_CHUNK_SIZE; @@ -100,16 +100,16 @@ _updateHashSize(struct DYNTYPE_HASH * _this) _this->values = realloc( _this->values, - sizeof(struct DYNTYPE *) * _this->size); - memset(_this->values + (_this->used * sizeof(struct DYNTYPE *)), + sizeof(DYNTYPE) * _this->size); + memset(_this->values + (_this->used * sizeof(DYNTYPE)), 0, - HASH_ENTRY_CHUNK_SIZE * sizeof(struct DYNTYPE *)); + HASH_ENTRY_CHUNK_SIZE * sizeof(DYNTYPE)); } } static size_t -_getHashIdx(struct DYNTYPE_HASH * _this, const char * key) +_getHashIdx(DYNTYPE_HASH _this, const char * key) { size_t index; @@ -121,9 +121,7 @@ _getHashIdx(struct DYNTYPE_HASH * _this, const char * key) } void -dyntype_hash_set(struct DYNTYPE_HASH * _this, - const char * key, - struct DYNTYPE * value) +dyntype_hash_set(DYNTYPE_HASH _this, const char * key, DYNTYPE value) { size_t index = _getHashIdx(_this, key); @@ -139,8 +137,7 @@ dyntype_hash_set(struct DYNTYPE_HASH * _this, _updateHashSize(_this); } -struct DYNTYPE * -dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key) +DYNTYPE dyntype_hash_get(DYNTYPE_HASH _this, const char * key) { size_t index = _getHashIdx(_this, key); @@ -151,10 +148,9 @@ dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key) return _this->values[index]; } -struct DYNTYPE * -dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key) +DYNTYPE dyntype_hash_del(DYNTYPE_HASH _this, const char * key) { - struct DYNTYPE * found = NULL; + DYNTYPE found = NULL; size_t index = _getHashIdx(_this, key); if (index == _this->used) { @@ -169,7 +165,7 @@ dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key) memmove(_this->values + index + 1, _this->values + index, - (_this->size - index) * sizeof(struct DYNTYPE *)); + (_this->size - index) * sizeof(DYNTYPE)); _this->used -= 1; } diff --git a/src/packet.c b/src/packet.c index 4717ec6..3367564 100644 --- a/src/packet.c +++ b/src/packet.c @@ -22,14 +22,14 @@ static void -__construct(struct PACKET * _this, va_list * params) +__construct(PACKET _this, va_list * params) { packet_set_default_content(_this); } static void -__jsonConst(struct PACKET * _this, struct json_object * json) +__jsonConst(PACKET _this, struct json_object * json) { struct json_object * header = NULL; struct json_object * data = NULL; @@ -53,13 +53,13 @@ __jsonConst(struct PACKET * _this, struct json_object * json) static void -__destruct(struct PACKET * _this) +__destruct(PACKET _this) { } static struct json_object * -__toJson(struct PACKET * _this) +__toJson(PACKET _this) { struct json_object * json = json_object_new_array(); @@ -71,36 +71,30 @@ __toJson(struct PACKET * _this) INIT_CCLASS(PACKET, __jsonConst, __toJson); -struct DYNTYPE * -packet_getHeader(struct PACKET * _this) +DYNTYPE packet_getHeader(PACKET _this) { return _this->content[PACKET_HEADER]; } -struct DYNTYPE * -packet_getData(struct PACKET * _this) +DYNTYPE packet_getData(PACKET _this) { return _this->content[PACKET_DATA]; } void -packet_setHeader( - struct PACKET * _this, - struct DYNTYPE * header) +packet_setHeader(PACKET _this, DYNTYPE header) { _this->content[PACKET_HEADER] = header; } void -packet_setData( - struct PACKET * _this, - struct DYNTYPE * data) +packet_setData(PACKET _this, DYNTYPE data) { _this->content[PACKET_DATA] = data; } void -packet_set_default_content(struct PACKET * _this) +packet_set_default_content(PACKET _this) { _this->content[PACKET_HEADER] = NULL; _this->content[PACKET_DATA] = NULL; diff --git a/tests/cclassTest.c b/tests/cclassTest.c index be24b4f..4b69753 100644 --- a/tests/cclassTest.c +++ b/tests/cclassTest.c @@ -7,7 +7,7 @@ const char testname[] = "cclassTest"; -struct MOCK_CLASS * mock = NULL; +MOCK_CLASS mock = NULL; static int diff --git a/tests/cryptTest.c b/tests/cryptTest.c index 4c5e5f7..5bc0622 100644 --- a/tests/cryptTest.c +++ b/tests/cryptTest.c @@ -12,7 +12,7 @@ const char testname[] = "cryptTest"; -struct CRYPT * crypt = NULL; +CRYPT crypt = NULL; static diff --git a/tests/mock/class.c b/tests/mock/class.c index 04c6388..237a93a 100644 --- a/tests/mock/class.c +++ b/tests/mock/class.c @@ -15,7 +15,7 @@ _reset() static void -__construct(struct MOCK_CLASS * _this, va_list * params) +__construct(MOCK_CLASS _this, va_list * params) { _called = 1; _this->value = va_arg(* params, int); @@ -23,7 +23,7 @@ __construct(struct MOCK_CLASS * _this, va_list * params) static void -__jsonConst(struct MOCK_CLASS * _this, json_object * json) +__jsonConst(MOCK_CLASS _this, json_object * json) { _called = 1; assert(json_type_int == json_object_get_type(json)); @@ -33,14 +33,14 @@ __jsonConst(struct MOCK_CLASS * _this, json_object * json) static void -__destruct(struct MOCK_CLASS * _this) +__destruct(MOCK_CLASS _this) { _called = 1; } static struct json_object * -__toJson(struct MOCK_CLASS * _this) +__toJson(MOCK_CLASS _this) { struct json_object * json = json_object_new_int(_this->value); @@ -55,13 +55,13 @@ INIT_CCLASS(MOCK_CLASS, __jsonConst, __toJson); */ int -mock_class_getValue(struct MOCK_CLASS * _this) +mock_class_getValue(MOCK_CLASS _this) { return _this->value; } void -mock_class_setValue(struct MOCK_CLASS * _this, int value) +mock_class_setValue(MOCK_CLASS _this, int value) { _this->value = value; } diff --git a/tests/mock/class.h b/tests/mock/class.h index 6501d45..e56dfca 100644 --- a/tests/mock/class.h +++ b/tests/mock/class.h @@ -8,19 +8,18 @@ extern char _called; extern void inline _reset(); -struct MOCK_CLASS { - const struct CCLASS * const class; +CLASS(MOCK_CLASS) int value; -}; +ENDC(MOCK_CLASS) -extern const struct CCLASS * const MOCK_CLASS; +extern const _CCLASS const __MOCK_CLASS; /** * ~~~ method declarations ~~~~~~~~ */ -int mock_class_getValue(struct MOCK_CLASS * _this); -void mock_class_setValue(struct MOCK_CLASS * _this, int value); +int mock_class_getValue(MOCK_CLASS _this); +void mock_class_setValue(MOCK_CLASS _this, int value); #endif//__MOCK_CLASS_H__ // vim: set et ts=4 sw=4: diff --git a/tests/packet.c b/tests/packet.c index 09f0e6b..ef6174f 100644 --- a/tests/packet.c +++ b/tests/packet.c @@ -11,27 +11,27 @@ void -setHashString(struct DYNTYPE_HASH * hash, const char * const key, const char * value) +setHashString(DYNTYPE_HASH hash, const char * const key, const char * value) { - struct DYNTYPE * dyn; + DYNTYPE dyn; dyn = new(DYNTYPE, DYNTYPE_TYPE_STRING, strlen(value), value); dyntype_hash_set(hash, key, dyn); } void -setHashInt(struct DYNTYPE_HASH * hash, const char * const key, const int value) +setHashInt(DYNTYPE_HASH hash, const char * const key, const int value) { - struct DYNTYPE * dyn; + DYNTYPE dyn; dyn = new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), value); dyntype_hash_set(hash, key, dyn); } void -deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key) +deleteHashValue(DYNTYPE_HASH hash, const char * const key) { - struct DYNTYPE * dyn = dyntype_hash_get(hash, key); + DYNTYPE dyn = dyntype_hash_get(hash, key); delete(&dyn); } @@ -39,19 +39,20 @@ deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key) int main(int argc, char * argv[]) { - struct PACKET * packet; - struct DYNTYPE_HASH * data; - struct DYNTYPE * _clear; + PACKET packet; + DYNTYPE_HASH data; + DYNTYPE _clear; + struct json_object * json; char * json_str; - packet = new(PACKET); + packet = new(PACKET, NULL); packet_setHeader( packet, new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), time(NULL))); - data = new(DYNTYPE_HASH); + data = new(DYNTYPE_HASH, NULL); setHashString(data, "#C#", "this comes from C"); setHashString(data, "usr", "ppohg"); diff --git a/tests/packetTest.c b/tests/packetTest.c index 009c981..7b97be8 100644 --- a/tests/packetTest.c +++ b/tests/packetTest.c @@ -12,7 +12,7 @@ static int __setUp() { - packet = new(PACKET); + packet = new(PACKET, NULL); ASSERT_INSTANCE_OF(PACKET, packet); return TEST_OK; diff --git a/tests/runtest.h b/tests/runtest.h index 4f9d804..401f4b9 100644 --- a/tests/runtest.h +++ b/tests/runtest.h @@ -30,7 +30,7 @@ enum RESULT_TYPES { #define ASSERT_OBJECT_NULL(val) if (! isObjectNull((val))) return TEST_FAILED #define ASSERT_OBJECT_NOT_NULL(val) if (isObjectNull((val))) return TEST_FAILED #define ASSERT_INSTANCE_OF(class, val) \ - if (! instanceOf((class), (val))) return TEST_FAILED + if (! instanceOf(class, val)) return TEST_FAILED typedef int (* const testfunc)(void);