Commit 1180ba9c authored by Benjamin REIS's avatar Benjamin REIS

Offer the choice to create a defaut logger or not a initialization

parents f89b7c23 b5b46a4c
......@@ -98,7 +98,7 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_TESTS_COMPONENT)
find_package(BCUnit 3.0 REQUIRED)
find_package(BcUnit REQUIRED)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${BCUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${BCUNIT_LIBRARIES})
......
############################################################################
# FindBCUnit.txt
# Copyright (C) 2015 Belledonne Communications, Grenoble France
#
############################################################################
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
#
# - Find the BCUnit include file and library
#
# BCUNIT_FOUND - system has BCUnit
# BCUNIT_INCLUDE_DIRS - the BCUnit include directory
# BCUNIT_LIBRARIES - The libraries needed to use BCUnit
include(CheckIncludeFile)
include(CheckLibraryExists)
find_path(BCUNIT_INCLUDE_DIRS
NAMES BCUnit/BCUnit.h
PATH_SUFFIXES include
)
if(BCUNIT_INCLUDE_DIRS)
set(HAVE_BCUNIT_BCUNIT_H 1)
endif()
if(HAVE_BCUNIT_BCUNIT_H)
if(BCUnit_FIND_VERSION)
list(APPEND BCUNIT_REQUIRED_VARS BCUNIT_VERSION)
file(STRINGS "${BCUNIT_INCLUDE_DIRS}/BCUnit/BCUnit.h" BCUNIT_VERSION_STR
REGEX "^#define[\t ]+CU_VERSION[\t ]+\"([0-9.]+).*\"$")
string(REGEX REPLACE "^.*CU_VERSION[\t ]+\"([0-9.]+).*\"$" "\\1" BCUNIT_VERSION "${BCUNIT_VERSION_STR}")
endif()
endif()
find_library(BCUNIT_LIBRARIES
NAMES bcunit
PATH_SUFFIXES bin lib
)
include(FindPackageHandleStandardArgs)
if(BCUnit_FIND_VERSION)
set(CHECK_VERSION_ARGS VERSION_VAR BCUNIT_VERSION)
endif()
find_package_handle_standard_args(BCUnit
REQUIRED_VARS BCUNIT_INCLUDE_DIRS BCUNIT_LIBRARIES
${CHECK_VERSION_ARGS}
)
mark_as_advanced(BCUNIT_INCLUDE_DIRS BCUNIT_LIBRARIES)
unset(CHECK_VERSION_ARGS)
......@@ -48,11 +48,11 @@ typedef enum {
BCTBX_LOG_LOGLEV_END=1<<6
} BctbxLogLevel;
typedef struct _BctoolboxLogHandler BctoolboxLogHandler;
typedef struct _bctbx_log_handler_t bctbx_log_handler_t;
typedef void (*BctoolboxLogFunc)(const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
typedef void (*BctoolboxLogHandlerFunc)(void *info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
typedef void (*BctoolboxLogHandlerDestroyFunc)(BctoolboxLogHandler* handler);
typedef void (*BctbxLogFunc)(const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
typedef void (*BctbxLogHandlerFunc)(void *info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
typedef void (*BctbxLogHandlerDestroyFunc)(bctbx_log_handler_t *handler);
/*
initialise logging functions, add default log handler for stdout output.
......@@ -67,19 +67,19 @@ BCTBX_PUBLIC void bctbx_uninit_logger(void);
/*
Default functions to free log handlers
@param[in] BctoolboxLogHandler* handler : the handler to free
@param[in] bctbx_log_handler_t* handler : the handler to free
*/
BCTBX_PUBLIC void bctbx_logv_out_destroy(BctoolboxLogHandler* handler);
BCTBX_PUBLIC void bctbx_logv_file_destroy(BctoolboxLogHandler* handler);
BCTBX_PUBLIC void bctbx_logv_out_destroy(bctbx_log_handler_t *handler);
BCTBX_PUBLIC void bctbx_logv_file_destroy(bctbx_log_handler_t *handler);
/*
Function to create a log handler
@param[in] BctoolboxLogHandlerFunc func : the function to call to handle a new line of log
@param[in] BctoolboxLogHandlerDestroyFunc destroy : the function to call to free this handler particuler its user_info field
@param[in] BctbxLogHandlerFunc func : the function to call to handle a new line of log
@param[in] BctbxLogHandlerDestroyFunc destroy : the function to call to free this handler particuler its user_info field
@param[in] void* user_info : complementary information to handle the logs if needed
@return a new BctoolboxLogHandler
@return a new bctbx_log_handler_t
*/
BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFunc func, BctoolboxLogHandlerDestroyFunc destroy, void* user_info);
BCTBX_PUBLIC bctbx_log_handler_t* bctbx_create_log_handler(BctbxLogHandlerFunc func, BctbxLogHandlerDestroyFunc destroy, void* user_info);
/*
Function to create a file log handler
......@@ -87,12 +87,12 @@ BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFu
@param[in] const char* path : the path where to put the log files
@param[in] const char* name : the name of the log files
@param[in] FILE* f : the file where to write the logs
@return a new BctoolboxLogHandler
@return a new bctbx_log_handler_t
*/
BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f);
BCTBX_PUBLIC bctbx_log_handler_t* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f);
BCTBX_PUBLIC void bctbx_add_log_handler(BctoolboxLogHandler* handler);
BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_handler(BctoolboxLogFunc func);
BCTBX_PUBLIC void bctbx_add_log_handler(bctbx_log_handler_t* handler);
BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_handler(BctbxLogFunc func);
BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_file(FILE* f);
BCTBX_PUBLIC bctbx_list_t* bctbx_get_log_handlers(void);
......
......@@ -368,6 +368,20 @@ BCTBX_PUBLIC char *bctbx_strcat_printf(char *dst, const char *fmt,...);
BCTBX_PUBLIC char *bctbx_strcat_vprintf(char *dst, const char *fmt, va_list ap);
BCTBX_PUBLIC char *bctbx_concat (const char *str, ...) ;
/**
* Portable version of the dirname function from libgen.h
* @param[in] path The full path for which we want to find the dirname
* @return NULL if no dirname is found, otherwise a copy of the dirname of path that needs to be freed with bctbx_free().
*/
BCTBX_PUBLIC char *bctbx_dirname(const char *path);
/**
* Portable version of the basename function from libgen.h
* @param[in] path The full path for which we want to find the basename
* @return NULL if no basename is found, otherwise a copy of the basename of path that needs to be freed with bctbx_free().
*/
BCTBX_PUBLIC char *bctbx_basename(const char *path);
BCTBX_PUBLIC int bctbx_file_exist(const char *pathname);
/**
......
......@@ -28,6 +28,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <sys/stat.h>
#include <sys/types.h>
#ifdef _MSC_VER
#ifndef access
#define access _access
#endif
#ifndef fileno
#define fileno _fileno
#endif
#endif
typedef struct{
char *domain;
......@@ -39,7 +48,7 @@ static void bctbx_log_domain_destroy(BctoolboxLogDomain *obj){
bctbx_free(obj);
}
typedef struct _BctoolboxLogger{
typedef struct _bctbx_logger_t {
bctbx_list_t *logv_outs;
unsigned int log_mask; /*the default log mask, if no per-domain settings are found*/
unsigned long log_thread_id;
......@@ -47,31 +56,32 @@ typedef struct _BctoolboxLogger{
bctbx_list_t *log_domains;
bctbx_mutex_t log_stored_messages_mutex;
bctbx_mutex_t domains_mutex;
}BctoolboxLogger;
} bctbx_logger_t;
struct _BctoolboxLogHandler{
BctoolboxLogHandlerFunc func;
BctoolboxLogHandlerDestroyFunc destroy;
struct _bctbx_log_handler_t {
BctbxLogHandlerFunc func;
BctbxLogHandlerDestroyFunc destroy;
void* user_info;
};
typedef struct _BctoolboxFileLogHandler{
typedef struct _bctbx_file_log_handler_t {
char* path;
char* name;
uint64_t max_size;
uint64_t size;
FILE* file;
}BctoolboxFileLogHandler;
} bctbx_file_log_handler_t;
static BctoolboxLogger __bctbx_logger = { NULL, BCTBX_LOG_WARNING|BCTBX_LOG_ERROR|BCTBX_LOG_FATAL, 0};
static bctbx_logger_t __bctbx_logger = { NULL, BCTBX_LOG_WARNING|BCTBX_LOG_ERROR|BCTBX_LOG_FATAL, 0};
static unsigned int bctbx_init_logger_refcount = 0;
void bctbx_init_logger(bool_t create){
if (bctbx_init_logger_refcount++ > 0) return; /*already initialized*/
bctbx_mutex_init(&__bctbx_logger.domains_mutex, NULL);
if(create) {
BctoolboxLogHandler* handler = bctbx_create_log_handler(bctbx_logv_out, bctbx_logv_out_destroy, NULL);
bctbx_log_handler_t* handler = bctbx_create_log_handler(bctbx_logv_out, bctbx_logv_out_destroy, NULL);
bctbx_add_log_handler(handler);
}
}
......@@ -79,7 +89,7 @@ void bctbx_init_logger(bool_t create){
void bctbx_log_handlers_free(void) {
bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
while (loggers) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
handler->destroy(handler);
loggers = loggers->next;
}
......@@ -95,17 +105,17 @@ void bctbx_uninit_logger(void){
}
}
BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFunc func, BctoolboxLogHandlerDestroyFunc destroy, void* user_info) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)bctbx_malloc(sizeof(BctoolboxLogHandler));
bctbx_log_handler_t* bctbx_create_log_handler(BctbxLogHandlerFunc func, BctbxLogHandlerDestroyFunc destroy, void* user_info) {
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)bctbx_malloc(sizeof(bctbx_log_handler_t));
handler->func = func;
handler->destroy = destroy;
handler->user_info = user_info;
return handler;
}
BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)bctbx_malloc0(sizeof(BctoolboxLogHandler));
BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler*)bctbx_malloc(sizeof(BctoolboxFileLogHandler));
bctbx_log_handler_t* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f) {
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)bctbx_malloc0(sizeof(bctbx_log_handler_t));
bctbx_file_log_handler_t* filehandler = (bctbx_file_log_handler_t*)bctbx_malloc(sizeof(bctbx_file_log_handler_t));
handler->func=bctbx_logv_file;
handler->destroy=bctbx_logv_file_destroy;
filehandler->max_size = max_size;
......@@ -123,30 +133,30 @@ BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char
*@param func: your logging function, compatible with the BctoolboxLogFunc prototype.
*
**/
void bctbx_add_log_handler(BctoolboxLogHandler* handler){
void bctbx_add_log_handler(bctbx_log_handler_t* handler){
if (!bctbx_list_find(__bctbx_logger.logv_outs, handler))
__bctbx_logger.logv_outs = bctbx_list_append(__bctbx_logger.logv_outs, (void*)handler);
/*else, already in*/
}
static void wrapper(void* info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args) {
BctoolboxLogFunc func = (BctoolboxLogFunc)info;
BctbxLogFunc func = (BctbxLogFunc)info;
func(domain, lev, fmt, args);
}
void bctbx_set_log_handler(BctoolboxLogFunc func){
static BctoolboxLogHandler handler;
void bctbx_set_log_handler(BctbxLogFunc func){
static bctbx_log_handler_t handler;
handler.func=wrapper;
handler.destroy=(BctoolboxLogHandlerDestroyFunc)bctbx_logv_out_destroy;
handler.destroy=(BctbxLogHandlerDestroyFunc)bctbx_logv_out_destroy;
handler.user_info=(void*)func;
bctbx_add_log_handler(&handler);
}
void bctbx_set_log_file(FILE* f){
static BctoolboxFileLogHandler filehandler;
static BctoolboxLogHandler handler;
static bctbx_file_log_handler_t filehandler;
static bctbx_log_handler_t handler;
handler.func=bctbx_logv_file;
handler.destroy=(BctoolboxLogHandlerDestroyFunc)bctbx_logv_file_destroy;
handler.destroy=(BctbxLogHandlerDestroyFunc)bctbx_logv_file_destroy;
filehandler.max_size = -1;
filehandler.file = f;
handler.user_info=(void*) &filehandler;
......@@ -339,7 +349,7 @@ void _bctbx_logv_flush(int dummy, ...) {
bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
#ifdef _WIN32
while (loggers) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
va_list cap;
va_copy(cap, empty_va_list);
handler->func(handler->user_info, l->domain, l->level, l->msg, cap);
......@@ -349,7 +359,7 @@ void _bctbx_logv_flush(int dummy, ...) {
#else
while (loggers) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
va_list cap;
va_copy(cap, empty_va_list);
handler->func(handler->user_info, l->domain, l->level, l->msg, cap);
......@@ -375,7 +385,7 @@ void bctbx_logv(const char *domain, BctbxLogLevel level, const char *fmt, va_lis
if (__bctbx_logger.log_thread_id == 0) {
bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
while (loggers) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
va_list tmp;
va_copy(tmp, args);
handler->func(handler->user_info, domain, level, fmt, tmp);
......@@ -387,7 +397,7 @@ void bctbx_logv(const char *domain, BctbxLogLevel level, const char *fmt, va_lis
bctbx_logv_flush();
loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
while (loggers) {
BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
va_list tmp;
va_copy(tmp, args);
handler->func(handler->user_info, domain, level, fmt, tmp);
......@@ -477,11 +487,11 @@ void bctbx_logv_out(void* user_info, const char *domain, BctbxLogLevel lev, cons
bctbx_free(msg);
}
void bctbx_logv_out_destroy(BctoolboxLogHandler* handler) {
void bctbx_logv_out_destroy(bctbx_log_handler_t* handler) {
handler->user_info=NULL;
}
static int _try_open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
static int _try_open_log_collection_file(bctbx_file_log_handler_t *filehandler) {
struct stat statbuf;
char *log_filename;
......@@ -502,7 +512,7 @@ static int _try_open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
return 0;
}
static void _rotate_log_collection_files(BctoolboxFileLogHandler* filehandler) {
static void _rotate_log_collection_files(bctbx_file_log_handler_t *filehandler) {
char *log_filename;
char *log_filename2;
int n = 1;
......@@ -544,14 +554,14 @@ static void _rotate_log_collection_files(BctoolboxFileLogHandler* filehandler) {
bctbx_free(log_filename2);
}
static void _open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
static void _open_log_collection_file(bctbx_file_log_handler_t *filehandler) {
if (_try_open_log_collection_file(filehandler) < 0) {
_rotate_log_collection_files(filehandler);
_try_open_log_collection_file(filehandler);
}
}
static void _close_log_collection_file(BctoolboxFileLogHandler* filehandler) {
static void _close_log_collection_file(bctbx_file_log_handler_t *filehandler) {
if (filehandler->file) {
fclose(filehandler->file);
filehandler->file = NULL;
......@@ -569,7 +579,7 @@ void bctbx_logv_file(void* user_info, const char *domain, BctbxLogLevel lev, con
#endif
time_t tt;
int ret = -1;
BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler *) user_info;
bctbx_file_log_handler_t *filehandler = (bctbx_file_log_handler_t *) user_info;
FILE *f = filehandler->file;
bctbx_gettimeofday(&tp,NULL);
tt = (time_t)tp.tv_sec;
......@@ -634,8 +644,8 @@ void bctbx_logv_file(void* user_info, const char *domain, BctbxLogLevel lev, con
bctbx_free(msg);
}
void bctbx_logv_file_destroy(BctoolboxLogHandler* handler) {
BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler *) handler->user_info;
void bctbx_logv_file_destroy(bctbx_log_handler_t* handler) {
bctbx_file_log_handler_t *filehandler = (bctbx_file_log_handler_t *) handler->user_info;
fclose(filehandler->file);
bctbx_free(filehandler->path);
bctbx_free(filehandler->name);
......
......@@ -107,6 +107,37 @@ char * bctbx_strdup(const char *tmp){
return ret;
}
char * bctbx_dirname(const char *path) {
char *ptr;
char *dname = bctbx_strdup(path);
bool_t found = FALSE;
ptr = strchr(path, '/');
if (ptr != NULL) {
dname[ptr - path + 1] = '\0';
found = TRUE;
} else {
ptr = strchr(path, '\\');
if (ptr != NULL) {
dname[ptr - path + 1] = '\0';
found = TRUE;
}
}
if (found == FALSE) {
bctbx_free(dname);
return NULL;
}
return dname;
}
char * bctbx_basename(const char *path) {
char *ptr = strrchr(path, '/');
if (ptr == NULL) ptr = strrchr(path, '\\');
if (ptr == NULL) return NULL;
return bctbx_strdup(ptr + 1);
}
/*
* this method is an utility method that calls fnctl() on UNIX or
* ioctlsocket on Win32.
......
......@@ -20,7 +20,6 @@
#endif
#include "bctoolbox/logging.h"
#include "bctoolbox_tester.h"
#include <libgen.h>
static FILE * log_file = NULL;
static const char *log_domain = "bctoolbox-tester";
......@@ -57,7 +56,7 @@ void bctoolbox_tester_before_each() {
}
int bctoolbox_tester_set_log_file(const char *filename) {
BctoolboxLogHandler* filehandler;
bctbx_log_handler_t* filehandler;
char* dir;
char* base;
if (log_file) {
......@@ -68,13 +67,13 @@ int bctoolbox_tester_set_log_file(const char *filename) {
bctbx_error("Cannot open file [%s] for writing logs because [%s]", filename, strerror(errno));
return -1;
}
dir = bctbx_strdup(filename);
base = bctbx_strdup(filename);
dir = bctbx_dirname(filename);
base = bctbx_basename(filename);
bctbx_message("Redirecting traces to file [%s]", filename);
filehandler = bctbx_create_file_log_handler(0, dirname(dir), basename(base), log_file);
filehandler = bctbx_create_file_log_handler(0, dir, base, log_file);
bctbx_add_log_handler(filehandler);
bctbx_free(dir);
bctbx_free(base);
if (dir) bctbx_free(dir);
if (base) bctbx_free(base);
return 0;
}
......
......@@ -18,6 +18,7 @@
*/
#include <stdio.h>
#include <inttypes.h>
#include "bctoolbox_tester.h"
#include "bctoolbox/port.h"
......@@ -77,9 +78,9 @@ static void bytesToFromHexaStrings(void) {
bctbx_uint64ToStr(outputString, 0xfedcba9876543210);
BC_ASSERT_NSTRING_EQUAL(outputString, "fedcba9876543210", 16);
BC_ASSERT_EQUAL(bctbx_strToUint64("fa5c37643cde8de0"), 0xfa5c37643cde8de0, uint64_t, "0x%016lx");
BC_ASSERT_EQUAL(bctbx_strToUint64("0123456789abcdef"), 0x0123456789abcdef, uint64_t, "0x%016lx");
BC_ASSERT_EQUAL(bctbx_strToUint64("fedcba9876543210"), 0xfedcba9876543210, uint64_t, "0x%016lx");
BC_ASSERT_EQUAL(bctbx_strToUint64("fa5c37643cde8de0"), 0xfa5c37643cde8de0, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL(bctbx_strToUint64("0123456789abcdef"), 0x0123456789abcdef, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL(bctbx_strToUint64("fedcba9876543210"), 0xfedcba9876543210, uint64_t, "0x%" PRIx64);
}
static void timeFunctions(void) {
......@@ -93,20 +94,20 @@ static void timeFunctions(void) {
memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
BC_ASSERT_EQUAL(bctbx_timespec_compare(&y2k, &testTs), 0, int, "%d");
bctbx_timespec_add(&testTs, 604800);
BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec+604800, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec+604800, int64_t, "%" PRIi64);
BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%" PRIi64);
BC_ASSERT_TRUE(bctbx_timespec_compare(&y2k, &testTs)<0);
memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
bctbx_timespec_add(&testTs, -604800);
BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec-604800, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec-604800, int64_t, "%" PRIi64);
BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%" PRIi64);
BC_ASSERT_TRUE(bctbx_timespec_compare(&y2k, &testTs)>0);
memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
bctbx_timespec_add(&testTs, -946684801);
BC_ASSERT_EQUAL(testTs.tv_sec, 0, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_nsec, 0, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_sec, 0, int64_t, "%" PRIi64);
BC_ASSERT_EQUAL(testTs.tv_nsec, 0, int64_t, "%" PRIi64);
/* test the get utc time function
* there is no easy way to ensure we get the correct time, just check it is at least not the time from last boot,
......
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