Commit fbe1ae17 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Implemented a key-value storage in the belle_sip_object_t structure.

Added a belle_sip_dict_t that has base accessors over this storage, and the appropriate unit tests.
parent 91edb97c
......@@ -20,6 +20,7 @@ bellesip_HEADERS=\
belle-sip.h \
refresher.h \
defs.h \
resolver.h
resolver.h \
dict.h
EXTRA_DIST=$(bellesip_HEADERS)
......@@ -22,6 +22,7 @@
#include "belle-sip/defs.h"
#include "belle-sip/object.h"
#include "belle-sip/dict.h"
/**
* This enum declares all object types used in belle-sip (see belle_sip_object_t)
......@@ -113,7 +114,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_signing_key_t),
BELLE_SIP_TYPE_ID(belle_sip_dns_srv_t),
BELLE_SIP_TYPE_ID(belle_sip_simple_resolver_context_t),
BELLE_SIP_TYPE_ID(belle_sip_combined_resolver_context_t)
BELLE_SIP_TYPE_ID(belle_sip_combined_resolver_context_t),
BELLE_SIP_TYPE_ID(belle_sip_dict_t)
BELLE_SIP_DECLARE_TYPES_END
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DICT_H
#define DICT_H
#include <sys/types.h>
#include "object.h"
typedef struct belle_sip_dict belle_sip_dict_t;
#define BELLE_SIP_DICT(obj) BELLE_SIP_CAST(obj,belle_sip_dict_t)
/**
* @brief belle_sip_dict_create
* @return an instance of a belle_sip_dict_t object.
* @note The object is not owned by default.
* @note all belle_sip_dict_set_* functions will overwrite existing values.
*/
belle_sip_dict_t* belle_sip_dict_create();
/**
* @brief belle_sip_dict_set_int stores an integer into the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to store
* @param value value to store
*/
void belle_sip_dict_set_int(belle_sip_dict_t* obj, const char* key, int value);
/**
* @brief belle_sip_dict_get_int retrieves an integer from the dictionary
* @param obj the dictionary instance
* @param key name of the integer to retrieve
* @param default_value value to return if the key is not found
* @return the searched integer if the key exists, default_value if not found
*/
int belle_sip_dict_get_int(belle_sip_dict_t* obj, const char* key, int default_value);
/**
* @brief belle_sip_dict_set_string stores a string into the dictionary
* @param obj the dictionary instance
* @param key the name of the string to store
* @param value value to store
*/
void belle_sip_dict_set_string(belle_sip_dict_t* obj, const char* key, const char*value);
/**
* @brief belle_sip_dict_get_string retrieves a string from the dictionary
* @param obj the dictionary instance
* @param key the name of the string to retrieve
* @param default_value
* @return the searched string if the key exists, default_value if not found
*/
const char* belle_sip_dict_get_string(belle_sip_dict_t* obj, const char* key, const char* default_value);
/**
* @brief belle_sip_dict_set_int64 stores an int64 in the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to store
* @param value value to store
*/
void belle_sip_dict_set_int64(belle_sip_dict_t* obj, const char* key, int64_t value);
/**
* @brief belle_sip_dict_get_int64 retrieves an int64 from the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to retrieve
* @param default_value value to return if the key is not found
* @return the searched int64 if the key exists, default_value if not found
*/
int64_t belle_sip_dict_get_int64(belle_sip_dict_t* obj, const char* key, int64_t default_value);
/**
* @brief belle_sip_dict_remove will erase the value for a key
* @param obj the dictionary instance
* @param key the name of the integer to remove
* @return 0 if the key was found, 1 otherwise
*/
int belle_sip_dict_remove(belle_sip_dict_t* obj, const char* key);
/**
* @brief belle_sip_dict_clear will clear the object's dictionary.
* @param obj the dictionary instance
*/
void belle_sip_dict_clear(belle_sip_dict_t* obj);
/**
* @brief belle_sip_dict_haskey tells if a key exists in the dictionary.
* @param obj the dictionary instance
* @param key the key to look for
* @return 1 if the key exists, 0 otherwise
* @todo create unit test
*/
int belle_sip_dict_haskey(belle_sip_dict_t* obj, const char* key);
#endif // DICT_H
This diff is collapsed.
......@@ -62,7 +62,8 @@ libbellesip_la_SOURCES= \
transports/stream_channel.h \
transports/stream_listeningpoint.c \
refresher.c \
dns.c dns.h
dns.c dns.h \
belle_sip_dict.c
if BUILD_TUNNEL
libbellesip_la_SOURCES+= transports/tunnel_listeningpoint.c \
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle-sip/dict.h"
#include "belle-sip/object.h"
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
#define BELLE_SIP_DICT(obj) BELLE_SIP_CAST(obj,belle_sip_dict_t)
static void belle_sip_dict_string_destroy( void* data )
{
belle_sip_free(data);
}
belle_sip_dict_t* belle_sip_dict_create()
{
return belle_sip_object_new(belle_sip_dict_t);
}
static void belle_sip_dict_destroy( belle_sip_dict_t* obj)
{
}
void belle_sip_dict_set_int(belle_sip_dict_t* obj, const char* key, int value)
{
char tmp[30];
snprintf(tmp,sizeof(tmp),"%i",value);
belle_sip_dict_set_string(obj, key, tmp);
}
int belle_sip_dict_get_int(belle_sip_dict_t* obj, const char* key, int default_value)
{
const char *str=belle_sip_object_data_get(BELLE_SIP_OBJECT(obj),key);
if (str!=NULL) {
int ret=0;
if (strstr(str,"0x")==str){
sscanf(str,"%x",&ret);
}else ret=atoi(str);
return ret;
}
else return default_value;
}
void belle_sip_dict_set_string(belle_sip_dict_t* obj, const char*key, const char*value)
{
belle_sip_object_data_set( BELLE_SIP_OBJECT(obj), key, (void*)belle_sip_strdup(value), belle_sip_dict_string_destroy );
}
const char* belle_sip_dict_get_string(belle_sip_dict_t* obj, const char* key, const char* default_value)
{
void* data = belle_sip_object_data_get( BELLE_SIP_OBJECT(obj), key );
if( data ) return (const char *)data;
else return default_value;
}
void belle_sip_dict_set_int64(belle_sip_dict_t* obj, const char* key, int64_t value)
{
char tmp[30];
snprintf(tmp,sizeof(tmp),"%lli",(long long)value);
belle_sip_dict_set_string(obj,key,tmp);
}
int64_t belle_sip_dict_get_int64(belle_sip_dict_t* obj, const char* key, int64_t default_value)
{
const char *str= belle_sip_object_data_get( BELLE_SIP_OBJECT(obj), key );
if (str!=NULL) {
#ifdef WIN32
return (int64_t)_atoi64(str);
#else
return atoll(str);
#endif
}
else return default_value;
}
int belle_sip_dict_remove(belle_sip_dict_t* obj, const char*key)
{
return belle_sip_object_data_remove(BELLE_SIP_OBJECT(obj), key);
}
int belle_sip_dict_haskey(belle_sip_dict_t* obj, const char* key)
{
return belle_sip_object_data_exists(BELLE_SIP_OBJECT(obj), key);
}
void belle_sip_dict_clear(belle_sip_dict_t* obj)
{
return belle_sip_object_data_clear(BELLE_SIP_OBJECT(obj));
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_dict_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_dict_t, belle_sip_object_t,
belle_sip_dict_destroy,
NULL,
NULL,
TRUE);
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef belle_utils_h
#define belle_utils_h
......@@ -124,7 +124,6 @@ void belle_sip_object_pool_remove(belle_sip_object_pool_t *pool, belle_sip_objec
/*list of all vptrs (classes) used in belle-sip*/
BELLE_SIP_DECLARE_VPTR(belle_sip_object_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_stack_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_datagram_listening_point_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_provider_t);
......@@ -190,6 +189,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_privacy_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_certificates_chain_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_signing_key_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dns_srv_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dict_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
......@@ -237,7 +237,7 @@ void belle_sip_source_uninit(belle_sip_source_t *s);
#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
belle_sip_list_t *belle_sip_list_new(void *data);
belle_sip_list_t* belle_sip_list_append_link(belle_sip_list_t* elem,belle_sip_list_t *new_elem);
belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip_compare_func compare_func, const void *user_data);
......@@ -245,7 +245,10 @@ belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip
#define belle_sip_list_next(elem) ((elem)->next)
/* dictionary */
struct belle_sip_dict {
belle_sip_object_t base;
};
#undef MIN
......@@ -404,7 +407,7 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
return l_object;\
}
#define BELLE_SIP_NEW_HEADER(object_type,super_type,name) BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,header)
#define BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,init_type) \
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_##object_type##_t); \
......@@ -528,8 +531,8 @@ void belle_sip_provider_add_client_transaction(belle_sip_provider_t *prov, belle
belle_sip_client_transaction_t *belle_sip_provider_find_matching_client_transaction(belle_sip_provider_t *prov, belle_sip_response_t *resp);
void belle_sip_provider_remove_client_transaction(belle_sip_provider_t *prov, belle_sip_client_transaction_t *t);
void belle_sip_provider_add_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
belle_sip_server_transaction_t * belle_sip_provider_find_matching_server_transaction(belle_sip_provider_t *prov,
belle_sip_request_t *req);
belle_sip_server_transaction_t * belle_sip_provider_find_matching_server_transaction(belle_sip_provider_t *prov,
belle_sip_request_t *req);
void belle_sip_provider_remove_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, belle_sip_transaction_t *t);
belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, const belle_sip_hop_t *hop);
......@@ -560,7 +563,7 @@ struct _belle_sip_message {
char* body;
unsigned int body_length;
};
struct _belle_sip_request {
belle_sip_message_t message;
char* method;
......@@ -569,7 +572,7 @@ struct _belle_sip_request {
char *rfc2543_branch; /*computed 'branch' id in case we receive this request from an old RFC2543 stack*/
unsigned char dialog_queued;
};
/*
belle_sip_transaction_t
*/
......@@ -585,7 +588,7 @@ struct belle_sip_transaction{
belle_sip_transaction_state_t state;
void *appdata;
unsigned char is_internal;
unsigned char timed_out;
unsigned char timed_out;
};
......@@ -718,7 +721,7 @@ belle_sip_nist_t * belle_sip_nist_new(belle_sip_provider_t *prov, belle_sip_requ
/*
* Dialogs
*/
*/
struct belle_sip_dialog{
belle_sip_object_t base;
void *appdata;
......
......@@ -158,13 +158,14 @@ belle_sip_object_vptr_t belle_sip_object_t_vptr={
void belle_sip_object_delete(void *ptr){
belle_sip_object_t *obj=BELLE_SIP_OBJECT(ptr);
belle_sip_object_vptr_t *vptr;
belle_sip_object_loose_weak_refs(obj);
vptr=obj->vptr;
while(vptr!=NULL){
if (vptr->destroy) vptr->destroy(obj);
vptr=vptr->parent;
}
belle_sip_object_data_clear(obj);
belle_sip_free(obj);
}
......@@ -216,6 +217,127 @@ belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj
return belle_sip_object_ref(belle_sip_object_clone(obj));
}
struct belle_sip_object_data{
char* name;
void* data;
belle_sip_data_destroy destroy_func;
};
static int belle_sip_object_data_find(const void* a, const void* b)
{
struct belle_sip_object_data* da = (struct belle_sip_object_data*)a;
return strcmp(da->name, (const char*)b);
}
static void belle_sip_object_data_destroy(void* data)
{
struct belle_sip_object_data* da = (struct belle_sip_object_data*)data;
if(da->destroy_func ) da->destroy_func(da->data);
belle_sip_free(da->name);
}
int belle_sip_object_data_set( belle_sip_object_t *obj, const char* name, void* data, belle_sip_data_destroy destroy_func )
{
int ret = 0;
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
if( entry == NULL){
entry = belle_sip_malloc0(sizeof( struct belle_sip_object_data));
obj->data_store = belle_sip_list_append(obj->data_store, entry);
}
else {
// clean previous data
if( entry->destroy_func ) entry->destroy_func(entry->data);
belle_sip_free(entry->name);
ret = 1;
}
if( entry ){
entry->data = data;
entry->name = belle_sip_strdup(name);
entry->destroy_func = destroy_func;
} else {
ret = -1;
}
return ret;
}
void* belle_sip_object_data_get( belle_sip_object_t *obj, const char* name )
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
return entry? entry->data : NULL;
}
int belle_sip_object_data_remove( belle_sip_object_t *obj, const char* name)
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
if( entry ){
belle_sip_free(entry->name);
if( entry->destroy_func ) entry->destroy_func(entry->data);
belle_sip_free(entry);
}
if( list_entry ) obj->data_store = belle_sip_list_remove_link(obj->data_store, list_entry);
return !(list_entry!= NULL);
}
int belle_sip_object_data_exists( belle_sip_object_t *obj, const char* name )
{
return (belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name) != NULL);
}
void* belle_sip_object_data_grab( belle_sip_object_t* obj, const char* name)
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
void* data =NULL;
if( entry ){
belle_sip_free(entry->name);
data = entry->data;
}
obj->data_store = belle_sip_list_remove_link(obj->data_store, list_entry);
belle_sip_free(entry);
return data;
}
void belle_sip_object_data_clear( belle_sip_object_t* obj )
{
belle_sip_list_for_each(obj->data_store, belle_sip_object_data_destroy);
obj->data_store = belle_sip_list_free(obj->data_store);
}
void belle_sip_object_data_clone( belle_sip_object_t* src, belle_sip_object_t* dst, belle_sip_data_clone clone_func)
{
belle_sip_object_data_clear(dst);
belle_sip_object_data_merge(src, dst, clone_func);
}
void belle_sip_object_data_merge( belle_sip_object_t* src, belle_sip_object_t* dst, belle_sip_data_clone clone_func)
{
struct _belle_sip_list* list = src->data_store;
struct belle_sip_object_data* it = NULL;
void* cloned_data = NULL;
while( list ){
it = list->data;
if( it ){
cloned_data = (clone_func)? clone_func( it->name, it->data ) : it->data;
belle_sip_object_data_set(dst, it->name, cloned_data, it->destroy_func);
}
list = list->next;
}
}
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno){
if (obj!=NULL){
if (has_type(obj,id)==0){
......
......@@ -14,6 +14,7 @@ belle_sip_tester_SOURCES= belle_sip_tester.c belle_sip_tester.h\
belle_sip_dialog_tester.c \
belle_sip_refresher_tester.c \
belle_sip_resolver_tester.c \
belle_sip_core_tester.c \
register_tester.h
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS) $(TLS_CFLAGS)
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h"
#include "belle-sip/object.h"
#include "belle-sip/dict.h"
#include "belle_sip_tester.h"
#include "belle_sip_internal.h"
#include "register_tester.h"
static int destroy_called = 0;
static int clone_called = 0;
static void test_object_data_string_destroy(void* data){
belle_sip_free(data);
destroy_called++;
}
static void* test_object_data_string_clone(const char*name, void* data){
clone_called++;
if( strcmp(name, "test_str") == 0)
return belle_sip_strdup(data);
else
return data;
}
static void test_object_data(void)
{
belle_sip_object_t* obj = belle_sip_object_new(belle_sip_object_t);
belle_sip_object_t* cloned = belle_sip_object_new(belle_sip_object_t);
int i = 123;
const char* str = "toto", *str2 = "titi";
/* normal insertion with no destroy callback */
// should return 0
CU_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_i", (void*)i, NULL), 0);
// should return the value we put in it
CU_ASSERT_EQUAL( (int)belle_sip_object_data_get(obj, "test_i"), i);
/*
* Overwriting insertion
*/
// overwrite data: should return 1 when set()
i = 124;
CU_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_i", (void*)i, NULL), 1 );
// should return the value we put in it
CU_ASSERT_EQUAL( (int)belle_sip_object_data_get(obj, "test_i"), i);
/*
* normal insertion with destroy callback
*/
CU_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_str",
(void*)belle_sip_strdup(str),
test_object_data_string_destroy),
0);
// we should get back the same string
CU_ASSERT_STRING_EQUAL( (const char*)belle_sip_object_data_get(obj, "test_str"),
str );
CU_ASSERT_EQUAL(belle_sip_object_data_remove(obj, "test_str"),0);
// we expect the destroy() function to be called on removal
CU_ASSERT_EQUAL(destroy_called, 1);
destroy_called = 0;
/*
* string insertion and replace
*/
belle_sip_object_data_set(obj, "test_str",
(void*)belle_sip_strdup(str),
test_object_data_string_destroy);
belle_sip_object_data_set(obj, "test_str",
(void*)belle_sip_strdup(str2),
test_object_data_string_destroy);
CU_ASSERT_EQUAL(destroy_called, 1); // we expect the dtor to have been called to free the first string
/*
* Get non-existent key
*/
CU_ASSERT_EQUAL(belle_sip_object_data_get(obj, "non-exist"),NULL);
/*
* test cloning the dictionary
*/
belle_sip_object_data_clone(obj, cloned, test_object_data_string_clone);
CU_ASSERT_EQUAL(clone_called,2); // we expect the clone function to be called for "test_i" and "test_str"
// the values should be equal
CU_ASSERT_EQUAL( (int)belle_sip_object_data_get(obj, "test_i"),
(int)belle_sip_object_data_get(cloned, "test_i"));
CU_ASSERT_STRING_EQUAL( (const char*)belle_sip_object_data_get(obj, "test_str"),
(const char*)belle_sip_object_data_get(cloned, "test_str"));
// but the string pointers should be different
CU_ASSERT_NOT_EQUAL( (const char*)belle_sip_object_data_get(obj, "test_str"),
(const char*)belle_sip_object_data_get(cloned, "test_str"));
belle_sip_object_unref(obj);
belle_sip_object_unref(cloned);
}
static void test_dictionary(void)
{
belle_sip_dict_t* obj = belle_sip_object_new(belle_sip_dict_t);
const char* str = "";
int i = 5;
int64_t i64 = 0x1234567890;
belle_sip_dict_set_int(obj, "test_i", i);
CU_ASSERT_EQUAL(belle_sip_dict_get_int(obj,"test_i",-1),i);
// return default int value
CU_ASSERT_EQUAL(belle_sip_dict_get_int(obj,"unexistent",-1),-1);
// remove existing entry
CU_ASSERT_EQUAL(belle_sip_dict_remove(obj, "test_i"),0);
// test_i should't be present anymore
CU_ASSERT_EQUAL(belle_sip_dict_get_int(obj,"test_i",-1),-1);
// remove unknown entry
CU_ASSERT_NOT_EQUAL(belle_sip_dict_remove(obj, "unexistent"),0);
belle_sip_dict_set_string(obj, "test_str", str);
CU_ASSERT_STRING_EQUAL( (const char*)belle_sip_dict_get_string(obj, "test_str", ""),str);
// unknown string value
CU_ASSERT_STRING_EQUAL( (const char*)belle_sip_dict_get_string(obj, "unexistent", "toto"),"toto");
belle_sip_dict_set_int64(obj, "test_i64", i64);
CU_ASSERT_EQUAL(belle_sip_dict_get_int64(obj,"test_i64",-1),i64);
belle_sip_dict_clear(obj);
// test_str shouldn't exist anymore
CU_ASSERT_EQUAL(belle_sip_dict_get_string(obj,"test_str","toto"),"toto");
belle_sip_object_unref(obj);
}
test_t core_tests[] = {
{ "Object Data", test_object_data },
{ "Dictionary", test_dictionary }
};
test_suite_t core_test_suite = {
"Core",
NULL,
NULL,
sizeof(core_tests) / sizeof(core_tests[0]),
core_tests
};
......@@ -104,6 +104,7 @@ void belle_sip_tester_init(void) {
add_test_suite(&cast_test_suite);
add_test_suite(&uri_test_suite);
add_test_suite(&headers_test_suite);
add_test_suite(&core_test_suite);
add_test_suite(&sdp_test_suite);
add_test_suite(&resolver_test_suite);
add_test_suite(&message_test_suite);
......
......@@ -47,6 +47,7 @@ extern "C" {
extern test_suite_t cast_test_suite;
extern test_suite_t uri_test_suite;
extern test_suite_t headers_test_suite;
extern test_suite_t core_test_suite;
extern test_suite_t sdp_test_suite;
extern test_suite_t resolver_test_suite;
extern test_suite_t message_test_suite;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment