From 26202831866276bcb5d205093173f7853ccc718d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 29 Dec 2015 13:56:27 +0100 Subject: [PATCH] Add isds_box_state_period structure This structure describes box state period that will be an item of list returned by GetDataBoxActivityStatus service. --- doc/libisds.xml | 25 ++++++++++++ src/isds.c | 24 ++++++++++++ src/isds.h | 16 ++++++++ test/offline/Makefile.am | 5 +++ test/offline/isds_box_state_period_duplicate.c | 54 ++++++++++++++++++++++++++ test/offline/isds_box_state_period_free.c | 35 +++++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 test/offline/isds_box_state_period_duplicate.c create mode 100644 test/offline/isds_box_state_period_free.c diff --git a/doc/libisds.xml b/doc/libisds.xml index c6d4dde..233d391 100644 --- a/doc/libisds.xml +++ b/doc/libisds.xml @@ -1531,6 +1531,31 @@ err = isds_cleanup(); + + struct <structname>isds_box_state_period</structname> + struct isds_box_state_period; + A box state valid in the time range. Members are: + + + struct timeval *from; + Time range beginning. + + + + struct timeval *to; + Time range end. + + + + long int dbState; + Box state. 1 means the box is + accessible. Other values mean the box is inaccessible. You can + use isds_DbState enum to identify some + states. + + + + diff --git a/src/isds.c b/src/isds.c index 580141c..98a1b39 100644 --- a/src/isds.c +++ b/src/isds.c @@ -461,6 +461,13 @@ void isds_fulltext_result_free( } +/* Deallocate struct isds_box_state_period recursively and NULL it */ +void isds_box_state_period_free(struct isds_box_state_period **period) { + if (NULL == period || NULL == *period) return; + zfree(*period); +} + + /* *DUP_OR_ERROR macros needs error label */ #define STRDUP_OR_ERROR(new, template) { \ if (!template) { \ @@ -670,6 +677,23 @@ error: return NULL; } + +/* Copy structure isds_box_state_period recursively */ +struct isds_box_state_period *isds_box_state_period_duplicate( + const struct isds_box_state_period *src) { + struct isds_box_state_period *new = NULL; + if (!src) return NULL; + + new = calloc(1, sizeof(*new)); + if (!new) return NULL; + + memcpy(&new->from, &src->from, sizeof(src->from)); + memcpy(&new->to, &src->to, sizeof(src->to)); + new->dbState = src->dbState; + + return new; +} + #undef FLATDUP_OR_ERROR #undef STRDUP_OR_ERROR diff --git a/src/isds.h b/src/isds.h index fed01be..631d333 100644 --- a/src/isds.h +++ b/src/isds.h @@ -837,6 +837,15 @@ struct isds_fulltext_result { into this box */ }; +/* A box state valid in the time range */ +struct isds_box_state_period { + struct timeval from; /* Time range beginning */ + struct timeval to; /* Time range end */ + long int dbState; /* Box state; 1 <=> active box, otherwise + inaccessible; use isds_DbState enum to + identify some states. */ +}; + /* Initialize ISDS library. * Global function, must be called before other functions. * If it fails you can not use ISDS library and must call isds_cleanup() to @@ -1875,6 +1884,9 @@ void isds_credentials_delivery_free( void isds_fulltext_result_free( struct isds_fulltext_result **result); +/* Deallocate struct isds_box_state_period recursively and NULL it */ +void isds_box_state_period_free(struct isds_box_state_period **period); + /* Copy structure isds_PersonName recursively */ struct isds_PersonName *isds_PersonName_duplicate( const struct isds_PersonName *src); @@ -1891,6 +1903,10 @@ struct isds_DbOwnerInfo *isds_DbOwnerInfo_duplicate( struct isds_DbUserInfo *isds_DbUserInfo_duplicate( const struct isds_DbUserInfo *src); +/* Copy structure isds_box_state_period recursively */ +struct isds_box_state_period *isds_box_state_period_duplicate( + const struct isds_box_state_period *src); + #ifdef __cplusplus /* For C++ linker sake */ } #endif diff --git a/test/offline/Makefile.am b/test/offline/Makefile.am index 53a5a3e..56b9452 100644 --- a/test/offline/Makefile.am +++ b/test/offline/Makefile.am @@ -28,8 +28,10 @@ TESTS = prepare_environment \ isds_message_copy_free isds_message_status_change_free isds_approval_free \ isds_commercial_permission_free isds_credentials_delivery_free \ isds_credit_event_free isds_fulltext_result_free \ + isds_box_state_period_free \ isds_PersonName_duplicate isds_Address_duplicate \ isds_DbOwnerInfo_duplicate isds_DbUserInfo_duplicate \ + isds_box_state_period_duplicate \ isds-filemetatype isds-hash_algorithm \ isds-timestring2timeval \ isds-uint2isds_message_status isds-eventstring2event \ @@ -172,10 +174,13 @@ isds_credentials_delivery_free_SOURCES = isds_credentials_delivery_free.c \ $(common) isds_credit_event_free_SOURCES = isds_credit_event_free.c $(common) isds_fulltext_result_free_SOURCES = isds_fulltext_result_free.c $(common) +isds_box_state_period_free_SOURCES = isds_box_state_period_free.c $(common) isds_PersonName_duplicate_SOURCES = isds_PersonName_duplicate.c $(common) isds_Address_duplicate_SOURCES = isds_Address_duplicate.c $(common) isds_DbOwnerInfo_duplicate_SOURCES = isds_DbOwnerInfo_duplicate.c $(common) isds_DbUserInfo_duplicate_SOURCES = isds_DbUserInfo_duplicate.c $(common) +isds_box_state_period_duplicate_SOURCES = isds_box_state_period_duplicate.c \ + $(common) # Access static symbols from isds.c isds_dbtype_SOURCES = isds-dbtype.c $(isds_common) diff --git a/test/offline/isds_box_state_period_duplicate.c b/test/offline/isds_box_state_period_duplicate.c new file mode 100644 index 0000000..bf351cc --- /dev/null +++ b/test/offline/isds_box_state_period_duplicate.c @@ -0,0 +1,54 @@ +#include "../test.h" +#include "isds.h" +#include + +static int test_isds_box_state_period_duplicate(struct isds_box_state_period *origin) { + struct isds_box_state_period *copy = isds_box_state_period_duplicate(origin); + TEST_DESTRUCTOR((void (*)(void *))isds_box_state_period_free, ©); + + if (!origin) { + if (copy) + FAIL_TEST("Duplicate of NULL should be NULL"); + PASS_TEST; + } + + if (!copy) + FAIL_TEST("isds_box_state_period_duplicate() returned NULL instead of " + "pointer to copy"); + + TEST_TIMEVALPTR_DUPLICITY(&origin->from, ©->from); + TEST_TIMEVALPTR_DUPLICITY(&origin->to, ©->to); + TEST_INT_DUPLICITY(origin->dbState, copy->dbState); + + PASS_TEST; +} + + +int main(void) { + INIT_TEST("isds_box_state_period_duplicate()"); + if (isds_init()) + ABORT_UNIT("isds_init() failed"); + + TEST("NULL", test_isds_box_state_period_duplicate, NULL); + + struct isds_box_state_period empty; + memset(&empty, 0, sizeof(empty)); + TEST("Empty structure", test_isds_box_state_period_duplicate, &empty); + + /* Full structure */ + struct isds_box_state_period full = { + .from = { + .tv_sec = 1, + .tv_usec = 2 + }, + .to = { + .tv_sec = 3, + .tv_usec = 4 + }, + .dbState = 42 + }; + TEST("Full structure", test_isds_box_state_period_duplicate, &full); + + isds_cleanup(); + SUM_TEST(); +} diff --git a/test/offline/isds_box_state_period_free.c b/test/offline/isds_box_state_period_free.c new file mode 100644 index 0000000..e2747e0 --- /dev/null +++ b/test/offline/isds_box_state_period_free.c @@ -0,0 +1,35 @@ +#include "../test.h" +#include "isds.h" + +static int test_isds_box_state_period_free( + struct isds_box_state_period **period) { + isds_box_state_period_free(period); + if (!period) PASS_TEST; + + if (*period) + FAIL_TEST("isds_box_state_period_free() did not null pointer"); + + PASS_TEST; +} + + +int main(void) { + + INIT_TEST("isds_box_state_period_free()"); + if (isds_init()) + ABORT_UNIT("isds_init() failed"); + + struct isds_box_state_period *period = NULL; + TEST("NULL", test_isds_box_state_period_free, NULL); + TEST("*NULL", test_isds_box_state_period_free, &period); + + TEST_CALLOC(period); + TEST("Empty structure", test_isds_box_state_period_free, &period); + + /* Full structure */ + TEST_CALLOC(period); + TEST("Full structure", test_isds_box_state_period_free, &period); + + isds_cleanup(); + SUM_TEST(); +} -- 2.11.4.GIT