From c963d75dfdeec11f82e79e727062fbf89afa2c04 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 22 Apr 2012 09:19:23 +1000 Subject: Update EFL to latest beta. --- libraries/eina/src/tests/Makefile.am | 3 +- libraries/eina/src/tests/Makefile.in | 48 +++-- libraries/eina/src/tests/eina_suite.c | 3 + libraries/eina/src/tests/eina_suite.h | 1 + libraries/eina/src/tests/eina_test_clist.c | 2 +- libraries/eina/src/tests/eina_test_counter.c | 92 ++++++++- libraries/eina/src/tests/eina_test_error.c | 184 +++++++++++++++++ libraries/eina/src/tests/eina_test_file.c | 54 +++++ libraries/eina/src/tests/eina_test_inlist.c | 171 +++++++++++++++- libraries/eina/src/tests/eina_test_list.c | 40 ++++ libraries/eina/src/tests/eina_test_log.c | 217 +++++++++++++++++++-- libraries/eina/src/tests/eina_test_magic.c | 110 +++++++++++ .../eina/src/tests/eina_test_simple_xml_parser.c | 6 +- libraries/eina/src/tests/eina_test_ustr.c | 130 +++++++++++- libraries/eina/src/tests/eina_test_value.c | 109 +++++++++-- 15 files changed, 1104 insertions(+), 66 deletions(-) (limited to 'libraries/eina/src/tests') diff --git a/libraries/eina/src/tests/Makefile.am b/libraries/eina/src/tests/Makefile.am index 7e05ba9..cf500f5 100644 --- a/libraries/eina/src/tests/Makefile.am +++ b/libraries/eina/src/tests/Makefile.am @@ -66,7 +66,8 @@ eina_test_strbuf.c \ eina_test_str.c \ eina_test_quadtree.c \ eina_test_simple_xml_parser.c \ -eina_test_value.c +eina_test_value.c \ +eina_test_model.c eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm diff --git a/libraries/eina/src/tests/Makefile.in b/libraries/eina/src/tests/Makefile.in index c56211a..81e58ba 100644 --- a/libraries/eina/src/tests/Makefile.in +++ b/libraries/eina/src/tests/Makefile.in @@ -43,20 +43,24 @@ host_triplet = @host@ subdir = src/tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/efl_attribute.m4 \ - $(top_srcdir)/m4/efl_benchmark.m4 \ - $(top_srcdir)/m4/efl_compiler_flag.m4 \ - $(top_srcdir)/m4/efl_coverage.m4 $(top_srcdir)/m4/efl_cpu.m4 \ - $(top_srcdir)/m4/efl_doxygen.m4 \ - $(top_srcdir)/m4/efl_examples.m4 \ - $(top_srcdir)/m4/efl_fnmatch.m4 \ - $(top_srcdir)/m4/efl_path_max.m4 $(top_srcdir)/m4/efl_tests.m4 \ - $(top_srcdir)/m4/efl_threads.m4 \ - $(top_srcdir)/m4/efl_voltron.m4 $(top_srcdir)/m4/eina_bench.m4 \ - $(top_srcdir)/m4/eina_check.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/eina/eina_bench.m4 \ + $(top_srcdir)/m4/eina/eina_check.m4 \ + $(top_srcdir)/m4/common/efl_attribute.m4 \ + $(top_srcdir)/m4/common/efl_benchmark.m4 \ + $(top_srcdir)/m4/common/efl_compiler_flag.m4 \ + $(top_srcdir)/m4/common/efl_coverage.m4 \ + $(top_srcdir)/m4/common/efl_cpu.m4 \ + $(top_srcdir)/m4/common/efl_doxygen.m4 \ + $(top_srcdir)/m4/common/efl_examples.m4 \ + $(top_srcdir)/m4/common/efl_fnmatch.m4 \ + $(top_srcdir)/m4/common/efl_path_max.m4 \ + $(top_srcdir)/m4/common/efl_tests.m4 \ + $(top_srcdir)/m4/common/efl_threads.m4 \ + $(top_srcdir)/m4/common/efl_voltron.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -159,7 +163,8 @@ am__eina_suite_SOURCES_DIST = eina_suite.c eina_test_fp.c \ eina_test_rectangle.c eina_test_list.c \ eina_test_matrixsparse.c eina_test_tiler.c eina_test_strbuf.c \ eina_test_str.c eina_test_quadtree.c \ - eina_test_simple_xml_parser.c eina_test_value.c + eina_test_simple_xml_parser.c eina_test_value.c \ + eina_test_model.c @EFL_ENABLE_TESTS_TRUE@am_eina_suite_OBJECTS = eina_suite.$(OBJEXT) \ @EFL_ENABLE_TESTS_TRUE@ eina_test_fp.$(OBJEXT) \ @EFL_ENABLE_TESTS_TRUE@ eina_test_stringshare.$(OBJEXT) \ @@ -195,7 +200,8 @@ am__eina_suite_SOURCES_DIST = eina_suite.c eina_test_fp.c \ @EFL_ENABLE_TESTS_TRUE@ eina_test_str.$(OBJEXT) \ @EFL_ENABLE_TESTS_TRUE@ eina_test_quadtree.$(OBJEXT) \ @EFL_ENABLE_TESTS_TRUE@ eina_test_simple_xml_parser.$(OBJEXT) \ -@EFL_ENABLE_TESTS_TRUE@ eina_test_value.$(OBJEXT) +@EFL_ENABLE_TESTS_TRUE@ eina_test_value.$(OBJEXT) \ +@EFL_ENABLE_TESTS_TRUE@ eina_test_model.$(OBJEXT) eina_suite_OBJECTS = $(am_eina_suite_OBJECTS) @EFL_ENABLE_TESTS_TRUE@eina_suite_DEPENDENCIES = \ @EFL_ENABLE_TESTS_TRUE@ $(top_builddir)/src/lib/libeina.la @@ -296,13 +302,13 @@ EINA_CONFIGURE_DEFAULT_MEMPOOL = @EINA_CONFIGURE_DEFAULT_MEMPOOL@ EINA_CONFIGURE_ENABLE_LOG = @EINA_CONFIGURE_ENABLE_LOG@ EINA_CONFIGURE_HAVE_DEBUG_THREADS = @EINA_CONFIGURE_HAVE_DEBUG_THREADS@ EINA_CONFIGURE_HAVE_DIRENT_H = @EINA_CONFIGURE_HAVE_DIRENT_H@ +EINA_CONFIGURE_HAVE_EXOTIC = @EINA_CONFIGURE_HAVE_EXOTIC@ EINA_CONFIGURE_HAVE_INTTYPES_H = @EINA_CONFIGURE_HAVE_INTTYPES_H@ EINA_CONFIGURE_HAVE_ON_OFF_THREADS = @EINA_CONFIGURE_HAVE_ON_OFF_THREADS@ EINA_CONFIGURE_HAVE_STDINT_H = @EINA_CONFIGURE_HAVE_STDINT_H@ EINA_CONFIGURE_HAVE_THREADS = @EINA_CONFIGURE_HAVE_THREADS@ EINA_CONFIGURE_MAGIC_DEBUG = @EINA_CONFIGURE_MAGIC_DEBUG@ EINA_CONFIGURE_SAFETY_CHECKS = @EINA_CONFIGURE_SAFETY_CHECKS@ -EINA_CPPFLAGS = @EINA_CPPFLAGS@ EINA_LIBS = @EINA_LIBS@ EINA_SIZEOF_WCHAR_T = @EINA_SIZEOF_WCHAR_T@ EMEMOA_CFLAGS = @EMEMOA_CFLAGS@ @@ -312,6 +318,8 @@ ESCAPE_LIBS = @ESCAPE_LIBS@ EVIL_CFLAGS = @EVIL_CFLAGS@ EVIL_LIBS = @EVIL_LIBS@ EXEEXT = @EXEEXT@ +EXOTIC_CFLAGS = @EXOTIC_CFLAGS@ +EXOTIC_LIBS = @EXOTIC_LIBS@ FGREP = @FGREP@ GLIB_CFLAGS = @GLIB_CFLAGS@ GLIB_LIBS = @GLIB_LIBS@ @@ -347,6 +355,8 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -465,7 +475,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/src/include \ @EFL_ENABLE_TESTS_TRUE@eina_test_str.c \ @EFL_ENABLE_TESTS_TRUE@eina_test_quadtree.c \ @EFL_ENABLE_TESTS_TRUE@eina_test_simple_xml_parser.c \ -@EFL_ENABLE_TESTS_TRUE@eina_test_value.c +@EFL_ENABLE_TESTS_TRUE@eina_test_value.c \ +@EFL_ENABLE_TESTS_TRUE@eina_test_model.c @EFL_ENABLE_TESTS_TRUE@eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm @EFL_ENABLE_TESTS_TRUE@cxx_compile_test_SOURCES = cxx_compile_test.cxx @@ -704,6 +715,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_matrixsparse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_mempool.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_model.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_module.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_quadtree.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_rbtree.Po@am__quote@ diff --git a/libraries/eina/src/tests/eina_suite.c b/libraries/eina/src/tests/eina_suite.c index 648a717..b34d016 100644 --- a/libraries/eina/src/tests/eina_suite.c +++ b/libraries/eina/src/tests/eina_suite.c @@ -68,6 +68,7 @@ static const Eina_Test_Case etc[] = { { "Sched", eina_test_sched }, { "Simple Xml Parser", eina_test_simple_xml_parser}, { "Value", eina_test_value }, + { "Model", eina_test_model }, { NULL, NULL } }; @@ -137,6 +138,8 @@ static void _mempool_init(void) static void _mempool_shutdown(void) { eina_module_list_free(_modules); + if (_modules) + eina_array_free(_modules); /* TODO delete the list */ eina_shutdown(); } diff --git a/libraries/eina/src/tests/eina_suite.h b/libraries/eina/src/tests/eina_suite.h index 6eaaec7..d399298 100644 --- a/libraries/eina/src/tests/eina_suite.h +++ b/libraries/eina/src/tests/eina_suite.h @@ -56,5 +56,6 @@ void eina_test_fp(TCase *tc); void eina_test_sched(TCase *tc); void eina_test_simple_xml_parser(TCase *tc); void eina_test_value(TCase *tc); +void eina_test_model(TCase *tc); #endif /* EINA_SUITE_H_ */ diff --git a/libraries/eina/src/tests/eina_test_clist.c b/libraries/eina/src/tests/eina_test_clist.c index 901c0e8..115afc2 100644 --- a/libraries/eina/src/tests/eina_test_clist.c +++ b/libraries/eina/src/tests/eina_test_clist.c @@ -6,7 +6,7 @@ #include #include -#include +#include "Eina.h" #include "eina_suite.h" Eina_Clist string_list = EINA_CLIST_INIT(string_list); diff --git a/libraries/eina/src/tests/eina_test_counter.c b/libraries/eina/src/tests/eina_test_counter.c index 2a3f30d..4d956fd 100644 --- a/libraries/eina/src/tests/eina_test_counter.c +++ b/libraries/eina/src/tests/eina_test_counter.c @@ -27,6 +27,43 @@ #include "Eina.h" #include "eina_safety_checks.h" +#ifdef EINA_SAFETY_CHECKS +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} +#endif + START_TEST(eina_counter_simple) { Eina_Counter *cnt; @@ -61,6 +98,7 @@ START_TEST(eina_counter_simple) dump = eina_counter_dump(cnt); fail_if(!dump); + /* TODO: parse dump and check if it's right */ fprintf(stderr, "%s", dump); free(dump); @@ -86,13 +124,65 @@ START_TEST(eina_counter_break) #ifdef EINA_SAFETY_CHECKS { + struct log_ctx ctx; char *dump; +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + +#ifdef SHOW_LOG fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_counter_new", + "safety check failed: name == NULL"); + cnt = eina_counter_new(NULL); + fail_if(cnt); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_counter_free", + "safety check failed: counter == NULL"); + eina_counter_free(NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_counter_start", + "safety check failed: counter == NULL"); + eina_counter_start(NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_counter_stop", + "safety check failed: counter == NULL"); + eina_counter_stop(NULL, 0); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_counter_dump", + "safety check failed: counter == NULL"); dump = eina_counter_dump(NULL); fail_if(dump); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); - free(dump); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); } #endif diff --git a/libraries/eina/src/tests/eina_test_error.c b/libraries/eina/src/tests/eina_test_error.c index 506f406..57f6950 100644 --- a/libraries/eina/src/tests/eina_test_error.c +++ b/libraries/eina/src/tests/eina_test_error.c @@ -33,6 +33,41 @@ #define TEST_TEXT "The big test\n" +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} + START_TEST(eina_error_errno) { int test; @@ -52,8 +87,157 @@ START_TEST(eina_error_errno) } END_TEST +START_TEST(eina_error_test_find) +{ + int test, r; + const char *str; + + eina_init(); + + test = eina_error_msg_register(TEST_TEXT); + ck_assert_int_ne(test, 0); + + str = eina_error_msg_get(test); + fail_unless(str != NULL); + ck_assert_str_eq(str, TEST_TEXT); + + eina_error_set(test); + fail_if(eina_error_get() != test); + + r = eina_error_find(TEST_TEXT); + ck_assert_int_eq(r, test); + + eina_shutdown(); +} +END_TEST + +START_TEST(eina_error_test_modify) +{ + int test, r; + const char *str, smsg[] = "Do not copy this string"; + + eina_init(); + + test = eina_error_msg_register("Some Test Error"); + ck_assert_int_ne(test, 0); + + str = eina_error_msg_get(test); + fail_unless(str != NULL); + ck_assert_str_eq(str, "Some Test Error"); + + eina_error_set(test); + fail_if(eina_error_get() != test); + + fail_unless(eina_error_msg_modify(test, "ABCDE")); + + r = eina_error_find("ABCDE"); + ck_assert_int_eq(r, test); + + test = eina_error_msg_static_register(smsg); + ck_assert_int_ne(test, 0); + + str = eina_error_msg_get(test); + fail_unless(str != NULL); + fail_unless(str == smsg); + + fail_unless(eina_error_msg_modify(test, "Change that!")); + r = eina_error_find("Change that!"); + ck_assert_int_eq(r, test); + + eina_shutdown(); +} +END_TEST + +START_TEST(eina_error_test_lots) +{ + char buf[64]; + int codes[512]; + unsigned int i; + + eina_init(); + + for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) + { + snprintf(buf, sizeof(buf), "myerr-%d", i); + codes[i] = eina_error_msg_register(buf); + ck_assert_int_ne(codes[i], 0); + } + + for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) + { + int found; + + snprintf(buf, sizeof(buf), "myerr-%d", i); + + found = eina_error_find(buf); + ck_assert_int_eq(codes[i], found); + } + + eina_shutdown(); +} +END_TEST + +#ifdef EINA_SAFETY_CHECKS +START_TEST(eina_error_test_failures) +{ + struct log_ctx ctx; + + eina_init(); + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + TEST_MAGIC_SAFETY("eina_error_msg_register", + "safety check failed: msg == NULL"); + ck_assert_int_eq(eina_error_msg_register(NULL), 0); + fail_unless(ctx.did); + + TEST_MAGIC_SAFETY("eina_error_msg_static_register", + "safety check failed: msg == NULL"); + ck_assert_int_eq(eina_error_msg_static_register(NULL), 0); + fail_unless(ctx.did); + + ck_assert_int_eq(eina_error_msg_modify(0, "X"), EINA_FALSE); + ck_assert_int_eq(eina_error_msg_modify(4096, "X"), EINA_FALSE); + + TEST_MAGIC_SAFETY("eina_error_msg_modify", + "safety check failed: msg == NULL"); + ck_assert_int_eq(eina_error_msg_modify(EINA_ERROR_OUT_OF_MEMORY, NULL), + EINA_FALSE); + fail_unless(ctx.did); + + ck_assert_str_eq(eina_error_msg_get(EINA_ERROR_OUT_OF_MEMORY), + "Out of memory"); + + TEST_MAGIC_SAFETY("eina_error_find", + "safety check failed: msg == NULL"); + ck_assert_int_eq(eina_error_find(NULL), 0); + fail_unless(ctx.did); + + ck_assert_int_eq(eina_error_find("Non-existent Error..."), 0); + + fail_if(eina_error_msg_get(0)); + fail_if(eina_error_msg_get(4096)); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + + eina_shutdown(); +} +END_TEST +#endif + void eina_test_error(TCase *tc) { tcase_add_test(tc, eina_error_errno); + tcase_add_test(tc, eina_error_test_find); + tcase_add_test(tc, eina_error_test_modify); + tcase_add_test(tc, eina_error_test_lots); +#ifdef EINA_SAFETY_CHECKS + tcase_add_test(tc, eina_error_test_failures); +#endif } diff --git a/libraries/eina/src/tests/eina_test_file.c b/libraries/eina/src/tests/eina_test_file.c index 55e9976..a3ba998 100644 --- a/libraries/eina/src/tests/eina_test_file.c +++ b/libraries/eina/src/tests/eina_test_file.c @@ -28,6 +28,44 @@ #include "Eina.h" #include "eina_safety_checks.h" +#ifdef EINA_SAFETY_CHECKS +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} +#endif + + START_TEST(eina_file_split_simple) { Eina_Array *ea; @@ -35,10 +73,26 @@ START_TEST(eina_file_split_simple) eina_init(); #ifdef EINA_SAFETY_CHECKS +#ifdef SHOW_LOG fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + struct log_ctx ctx; + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + + TEST_MAGIC_SAFETY("eina_file_split", "safety check failed: path == NULL"); ea = eina_file_split(NULL); fail_if(ea); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); +#undef TEST_MAGIC_SAFETY #endif #ifdef _WIN32 diff --git a/libraries/eina/src/tests/eina_test_inlist.c b/libraries/eina/src/tests/eina_test_inlist.c index c27f393..a8631e7 100644 --- a/libraries/eina/src/tests/eina_test_inlist.c +++ b/libraries/eina/src/tests/eina_test_inlist.c @@ -34,6 +34,43 @@ struct _Eina_Test_Inlist EINA_INLIST; }; +#ifdef EINA_SAFETY_CHECKS +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} +#endif + static Eina_Test_Inlist * _eina_test_inlist_build(int i) { @@ -52,6 +89,10 @@ START_TEST(eina_inlist_simple) Eina_Test_Inlist *tmp; Eina_Test_Inlist *prev; int i = 0; +#ifdef EINA_SAFETY_CHECKS + Eina_Inlist *bkp; + struct log_ctx ctx; +#endif fail_if(!eina_init()); @@ -106,16 +147,142 @@ START_TEST(eina_inlist_simple) } #ifdef EINA_SAFETY_CHECKS + bkp = lst; + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + +#ifdef SHOW_LOG fprintf(stderr, "you should have a safety check failure below:\n"); +#endif { - Eina_Inlist *tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp)); + Eina_Inlist *tmp2; + + TEST_MAGIC_SAFETY("eina_inlist_remove", + "safety check failed: list == NULL"); + + tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp)); fail_if(tmp2 != NULL); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); } - fprintf(stderr, "you should have a safety check failure below:\n"); +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_remove", + "safety check failed: item == NULL"); lst = eina_inlist_remove(lst, NULL); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_append", + "safety check failed: new_l == NULL"); + lst = eina_inlist_append(lst, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_append_relative", + "safety check failed: new_l == NULL"); + lst = eina_inlist_append_relative(lst, NULL, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_prepend", + "safety check failed: new_l == NULL"); + lst = eina_inlist_prepend(lst, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_prepend_relative", + "safety check failed: new_l == NULL"); + lst = eina_inlist_prepend_relative(lst, NULL, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_find", + "safety check failed: item == NULL"); + lst = eina_inlist_find(lst, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_demote", + "safety check failed: list == NULL"); + lst = eina_inlist_demote(NULL, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_demote", + "safety check failed: item == NULL"); + lst = eina_inlist_demote((void*)1L, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + lst = NULL; + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_promote", + "safety check failed: list == NULL"); + lst = eina_inlist_promote(NULL, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_promote", + "safety check failed: item == NULL"); + lst = eina_inlist_promote((void*)1L, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + lst = NULL; + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_sorted_insert", + "safety check failed: item == NULL"); + lst = eina_inlist_sorted_insert(NULL, NULL, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_inlist_sorted_insert", + "safety check failed: func == NULL"); + lst = eina_inlist_sorted_insert(NULL, (void*)1L, NULL); + fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); + lst = NULL; + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + lst = bkp; #endif tmp = EINA_INLIST_CONTAINER_GET(lst, Eina_Test_Inlist); diff --git a/libraries/eina/src/tests/eina_test_list.c b/libraries/eina/src/tests/eina_test_list.c index 6e08847..ce70d03 100644 --- a/libraries/eina/src/tests/eina_test_list.c +++ b/libraries/eina/src/tests/eina_test_list.c @@ -338,10 +338,50 @@ START_TEST(eina_test_sorted_insert) } END_TEST +START_TEST(eina_test_list_split) +{ + Eina_List *left = NULL, *right = NULL ; + Eina_List *list = NULL; + Eina_List *l; + void *list_data; + int i; + + eina_init(); + + list = eina_list_append(list, "tigh"); + list = eina_list_append(list, "adar"); + list = eina_list_append(list, "baltar"); + list = eina_list_append(list, "roslin"); + list = eina_list_append(list, "baltar"); + list = eina_list_append(list, "roslin"); + list = eina_list_append(list, "baltar"); + list = eina_list_append(list, "roslin"); + + fail_if(list == NULL); + fail_if(eina_list_count(list) != 8); + + for ( i = 0; i < 200; i++) + { + left = eina_list_split_list(list, eina_list_nth_list(list, i % 2), &right); + + if (i % 2 == 0) + fail_if(eina_list_count(left) == 1 && eina_list_count(right) + eina_list_count(left) == i + 7); + else + fail_if(eina_list_count(left) == 2 && eina_list_count(right) + eina_list_count(left) == i + 7); + + list = eina_list_merge(left, right); + list = eina_list_append(list, "roslin"); + } + + eina_shutdown(); +} +END_TEST + void eina_test_list(TCase *tc) { tcase_add_test(tc, eina_test_simple); tcase_add_test(tc, eina_test_merge); tcase_add_test(tc, eina_test_sorted_insert); + tcase_add_test(tc, eina_test_list_split); } diff --git a/libraries/eina/src/tests/eina_test_log.c b/libraries/eina/src/tests/eina_test_log.c index ba17d5f..e0f0363 100644 --- a/libraries/eina/src/tests/eina_test_log.c +++ b/libraries/eina/src/tests/eina_test_log.c @@ -27,18 +27,119 @@ #include "eina_suite.h" #include "Eina.h" - START_TEST(eina_log_macro) +struct log_ctx { + int level; + int line; + const char *msg; + const char *fnc; + const char *dom; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_log(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) { + struct log_ctx *ctx = data; + ck_assert_int_eq(ctx->level, level); + ck_assert_int_eq(ctx->line, line); + ck_assert_str_eq(ctx->msg, fmt); + ck_assert_str_eq(ctx->fnc, fnc); + ck_assert_str_eq(file, __FILE__); + ctx->did = EINA_TRUE; +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; +#endif +} + +static void +_eina_test_log_domain(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + ck_assert_int_eq(ctx->level, level); + ck_assert_int_eq(ctx->line, line); + ck_assert_str_eq(ctx->msg, fmt); + ck_assert_str_eq(ctx->fnc, fnc); + ck_assert_str_eq(file, __FILE__); + ck_assert_str_eq(ctx->dom, d->name); + ctx->did = EINA_TRUE; +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#endif +} + +static void +_eina_test_log_safety(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(ctx->level, level); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} + +START_TEST(eina_log_macro) +{ + struct log_ctx ctx; + int oldlevel; + fail_if(!eina_init()); + oldlevel = eina_log_level_get(); eina_log_level_set(EINA_LOG_LEVEL_DBG); - eina_log_print_cb_set(eina_log_print_cb_file, stderr); + eina_log_print_cb_set(_eina_test_log, &ctx); + +#define TEST_LOG_CTX(lvl, _msg) \ + ctx.level = lvl; \ + ctx.line = __LINE__ + 1; \ + ctx.msg = _msg; \ + ctx.fnc = __FUNCTION__; \ + ctx.did = EINA_FALSE + + TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "Critical message"); + EINA_LOG_CRIT("Critical message"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error"); + EINA_LOG_ERR("An error"); + fail_unless(ctx.did); - EINA_LOG_CRIT("Critical message\n"); - EINA_LOG_ERR("An error\n"); - EINA_LOG_INFO("An info\n"); - EINA_LOG_WARN("A warning\n"); - EINA_LOG_DBG("A debug\n"); + TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning"); + EINA_LOG_WARN("A warning"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info"); + EINA_LOG_INFO("An info"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug"); + EINA_LOG_DBG("A debug"); + fail_unless(ctx.did); + +#undef TEST_LOG_CTX + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eina_log_level_set(oldlevel); eina_shutdown(); } @@ -46,16 +147,54 @@ END_TEST START_TEST(eina_log_domains_macros) { + struct log_ctx ctx; + int oldlevel; + fail_if(!eina_init()); + /* make global log level blocker */ + oldlevel = eina_log_level_get(); + eina_log_level_set(EINA_LOG_LEVEL_CRITICAL); + eina_log_print_cb_set(_eina_test_log_domain, &ctx); + int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); fail_if(d < 0); - EINA_LOG_DOM_CRIT(d, "A critical message\n"); - EINA_LOG_DOM_ERR(d, "An error\n"); - EINA_LOG_DOM_WARN(d, "A warning\n"); - EINA_LOG_DOM_DBG(d, "A debug\n"); - EINA_LOG_DOM_INFO(d, "An info\n"); + /* make specific domain permissive */ + eina_log_domain_level_set("MyDomain", EINA_LOG_LEVEL_DBG); + +#define TEST_LOG_CTX(lvl, _msg) \ + ctx.level = lvl; \ + ctx.line = __LINE__ + 1; \ + ctx.msg = _msg; \ + ctx.fnc = __FUNCTION__; \ + ctx.dom = "MyDomain"; \ + ctx.did = EINA_FALSE + + TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "A critical message"); + EINA_LOG_DOM_CRIT(d, "A critical message"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error"); + EINA_LOG_DOM_ERR(d, "An error"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning"); + EINA_LOG_DOM_WARN(d, "A warning"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info"); + EINA_LOG_DOM_INFO(d, "An info"); + fail_unless(ctx.did); + + TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug"); + EINA_LOG_DOM_DBG(d, "A debug"); + fail_unless(ctx.did); + +#undef TEST_LOG_CTX + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eina_log_level_set(oldlevel); eina_shutdown(); } @@ -120,6 +259,8 @@ END_TEST START_TEST(eina_log_level_indexes) { + struct log_ctx ctx; + fail_if(!eina_init()); fail_if(!eina_threads_init()); fail_if(!eina_threads_init()); @@ -127,11 +268,41 @@ START_TEST(eina_log_level_indexes) int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); fail_if(d < 0); + eina_log_print_cb_set(_eina_test_log_domain, &ctx); + +#define TEST_LOG_CTX(lvl, _msg) \ + ctx.level = lvl; \ + ctx.line = __LINE__ + 1; \ + ctx.msg = _msg; \ + ctx.fnc = __FUNCTION__; \ + ctx.dom = "Levels"; \ + ctx.did = EINA_FALSE; + // Displayed unless user sets level lower than -1 - EINA_LOG(d, -1, "Negative index message\n"); + eina_log_domain_level_set("Levels", -1); + TEST_LOG_CTX(-1, "Negative index message"); + EINA_LOG(d, -1, "Negative index message"); + fail_unless(ctx.did); + + eina_log_domain_level_set("Levels", -2); + TEST_LOG_CTX(-1, "Negative index message"); + EINA_LOG(d, -1, "Negative index message"); + fail_if(ctx.did); // Displayed only if user sets level 6 or higher - EINA_LOG(d, 6, "Higher level debug\n"); + eina_log_domain_level_set("Levels", 6); + TEST_LOG_CTX(6, "Higher level debug"); + EINA_LOG(d, 6, "Higher level debug"); + fail_unless(ctx.did); + + eina_log_domain_level_set("Levels", 5); + TEST_LOG_CTX(6, "Higher level debug"); + EINA_LOG(d, 6, "Higher level debug"); + fail_if(ctx.did); + +#undef TEST_LOG_CTX + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); eina_threads_shutdown(); eina_threads_shutdown(); @@ -141,6 +312,7 @@ END_TEST START_TEST(eina_log_customize) { + struct log_ctx ctx; int d; /* please don't define EINA_LOG_LEVELS for it */ @@ -182,11 +354,28 @@ START_TEST(eina_log_customize) fail_if(eina_log_domain_registered_level_get(d) != 890); eina_log_domain_unregister(d); + +#ifdef EINA_SAFETY_CHECKS +#ifdef SHOW_LOG fputs("NOTE: You should see a failed safety check or " "a crash if compiled without safety checks support.\n", stderr); +#endif eina_log_abort_on_critical_set(EINA_FALSE); + eina_log_function_disable_set(EINA_FALSE); + + eina_log_print_cb_set(_eina_test_log_safety, &ctx); + ctx.level = EINA_LOG_LEVEL_ERR; + ctx.msg = "safety check failed: _log_domains[domain].deleted is true"; + ctx.fnc = "eina_log_domain_registered_level_get"; + ctx.did = EINA_FALSE; fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); +#else +#warning "Compiled without safety checks" +#endif #undef test_set_get_bool #undef test_set_get diff --git a/libraries/eina/src/tests/eina_test_magic.c b/libraries/eina/src/tests/eina_test_magic.c index d2c3d49..d0a374e 100644 --- a/libraries/eina/src/tests/eina_test_magic.c +++ b/libraries/eina/src/tests/eina_test_magic.c @@ -40,21 +40,95 @@ struct _Eina_Magic_Struct EINA_MAGIC }; +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} + +static void +_eina_test_magic_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + + ck_assert_int_eq(level, EINA_LOG_LEVEL_CRITICAL); + ck_assert_str_eq(ctx->msg, fmt); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} + +#ifdef EINA_SAFETY_CHECKS +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE +#endif + START_TEST(eina_magic_simple) { Eina_Magic_Struct *ems = NULL; + struct log_ctx ctx; eina_init(); + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); #ifdef EINA_SAFETY_CHECKS +#ifdef SHOW_LOG fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_magic_string_set", + "safety check failed: magic_name == NULL"); eina_magic_string_set(EINA_MAGIC_TEST2, NULL); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); + fail_unless(ctx.did); +#ifdef SHOW_LOG fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_magic_string_set", + "safety check failed: magic_name == NULL"); eina_magic_string_set(EINA_MAGIC_TEST2, NULL); + fail_unless(ctx.did); fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); #endif @@ -64,10 +138,22 @@ START_TEST(eina_magic_simple) fail_if(strcmp(eina_magic_string_get( EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); + eina_log_print_cb_set(_eina_test_magic_print_cb, &ctx); + #ifdef EINA_MAGIC_DEBUG fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); +#ifdef SHOW_LOG fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); +#endif + TEST_MAGIC_SAFETY(__FUNCTION__, + "*** Eina Magic Check Failed !!!\n" + " Input handle pointer is NULL !\n" + "*** NAUGHTY PROGRAMMER!!!\n" + "*** SPANK SPANK SPANK!!!\n" + "*** Now go fix your code. Tut tut tut!\n" + "\n"); EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); + fail_unless(ctx.did); ems = malloc(sizeof (Eina_Magic_Struct)); fail_if(!ems); @@ -76,15 +162,39 @@ START_TEST(eina_magic_simple) fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); +#ifdef SHOW_LOG fprintf(stderr, "you should see 'Input handle has already been freed' below\n"); +#endif + TEST_MAGIC_SAFETY(__FUNCTION__, + "*** Eina Magic Check Failed !!!\n" + " Input handle has already been freed!\n" + "*** NAUGHTY PROGRAMMER!!!\n" + "*** SPANK SPANK SPANK!!!\n" + "*** Now go fix your code. Tut tut tut!\n" + "\n"); EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); + fail_unless(ctx.did); EINA_MAGIC_SET(ems, 42424242); +#ifdef SHOW_LOG fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); +#endif + TEST_MAGIC_SAFETY(__FUNCTION__, + "*** Eina Magic Check Failed !!!\n" + " Input handle is wrong type\n" + " Expected: %08x - %s\n" + " Supplied: %08x - %s\n" + "*** NAUGHTY PROGRAMMER!!!\n" + "*** SPANK SPANK SPANK!!!\n" + "*** Now go fix your code. Tut tut tut!\n" + "\n"); EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); + fail_unless(ctx.did); #endif + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); + eina_shutdown(); } END_TEST diff --git a/libraries/eina/src/tests/eina_test_simple_xml_parser.c b/libraries/eina/src/tests/eina_test_simple_xml_parser.c index 94e6a2a..7093019 100644 --- a/libraries/eina/src/tests/eina_test_simple_xml_parser.c +++ b/libraries/eina/src/tests/eina_test_simple_xml_parser.c @@ -44,15 +44,17 @@ START_TEST(eina_simple_xml_parser_node_dump) char *buf; fseek(f, 0, SEEK_SET); - buf = malloc(sz); + buf = malloc(sz + 1); if (buf) { if (fread(buf, 1, sz, f)) { Eina_Simple_XML_Node_Root *root = eina_simple_xml_node_load (buf, sz, EINA_TRUE); + buf[sz] = '\0'; char *out = eina_simple_xml_node_dump(&root->base, " "); - puts(out); + //puts(out); + ck_assert_str_eq(out, buf); free(out); eina_simple_xml_node_root_free(root); free(buf); diff --git a/libraries/eina/src/tests/eina_test_ustr.c b/libraries/eina/src/tests/eina_test_ustr.c index eaeba9d..75126cc 100644 --- a/libraries/eina/src/tests/eina_test_ustr.c +++ b/libraries/eina/src/tests/eina_test_ustr.c @@ -28,6 +28,43 @@ #include "eina_suite.h" #include "Eina.h" +#ifdef EINA_SAFETY_CHECKS +struct log_ctx { + const char *msg; + const char *fnc; + Eina_Bool did; +}; + +/* tests should not output on success, just uncomment this for debugging */ +//#define SHOW_LOG 1 + +static void +_eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__) +{ + struct log_ctx *ctx = data; + va_list cp_args; + const char *str; + + va_copy(cp_args, args); + str = va_arg(cp_args, const char *); + va_end(cp_args); + + ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); + ck_assert_str_eq(fmt, "%s"); + ck_assert_str_eq(ctx->msg, str); + ck_assert_str_eq(ctx->fnc, fnc); + ctx->did = EINA_TRUE; + +#ifdef SHOW_LOG + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); +#else + (void)d; + (void)file; + (void)line; +#endif +} +#endif + static const Eina_Unicode STR1[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; static const Eina_Unicode STR2[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'f', 'f', 0}; static const Eina_Unicode STR3[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; @@ -126,14 +163,42 @@ START_TEST(eina_unicode_strncpy_test) rv = eina_unicode_strncpy(buf, STR1, 0); fail_if(buf[0] != '7'); - /* may segfault */ - buf[0] = '7'; - rv = eina_unicode_strncpy(buf, NULL, 0); - fail_if(buf[0] != '7'); +#ifdef EINA_SAFETY_CHECKS + { + struct log_ctx ctx; + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); - /* Hopefully won't segfault */ - rv = eina_unicode_strncpy(NULL, STR1, 0); - fail_if(rv != NULL); + /* may segfault */ + buf[0] = '7'; +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_unicode_strncpy", + "safety check failed: source == NULL"); + rv = eina_unicode_strncpy(buf, NULL, 0); + fail_if(buf[0] != '7'); + fail_unless(ctx.did); + + /* Hopefully won't segfault */ +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_unicode_strncpy", + "safety check failed: dest == NULL"); + rv = eina_unicode_strncpy(NULL, STR1, 0); + fail_if(rv != NULL); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); +#undef TEST_MAGIC_SAFETY + } +#endif eina_shutdown(); } @@ -151,8 +216,30 @@ START_TEST(eina_ustr_strlen_test) fail_if(eina_unicode_strlen(STR3) != 8); fail_if(eina_unicode_strlen(STR4) != 1); fail_if(eina_unicode_strlen(EMPTYSTR) != 0); - /* Eina unicode doesn't take NULL */ - // fail_if(eina_unicode_strlen(NULL)); + +#ifdef EINA_SAFETY_CHECKS + { + struct log_ctx ctx; + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_unicode_strlen", + "safety check failed: ustr == NULL"); + fail_if(eina_unicode_strlen(NULL)); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); +#undef TEST_MAGIC_SAFETY + } +#endif eina_shutdown(); } @@ -174,7 +261,30 @@ START_TEST(eina_unicode_strnlen_test) fail_if(eina_unicode_strnlen(STR2,3) != 3); fail_if(eina_unicode_strnlen(STR3,3) != 3); fail_if(eina_unicode_strnlen(EMPTYSTR,1) != 0); - fail_if(eina_unicode_strnlen(NULL,0) != 0); + +#ifdef EINA_SAFETY_CHECKS + { + struct log_ctx ctx; + +#define TEST_MAGIC_SAFETY(fn, _msg) \ + ctx.msg = _msg; \ + ctx.fnc = fn; \ + ctx.did = EINA_FALSE + + eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); + +#ifdef SHOW_LOG + fprintf(stderr, "you should have a safety check failure below:\n"); +#endif + TEST_MAGIC_SAFETY("eina_unicode_strnlen", + "safety check failed: ustr == NULL"); + fail_if(eina_unicode_strnlen(NULL,0) != 0); + fail_unless(ctx.did); + + eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); +#undef TEST_MAGIC_SAFETY + } +#endif eina_shutdown(); } diff --git a/libraries/eina/src/tests/eina_test_value.c b/libraries/eina/src/tests/eina_test_value.c index 2d04c2f..94a5ab7 100644 --- a/libraries/eina/src/tests/eina_test_value.c +++ b/libraries/eina/src/tests/eina_test_value.c @@ -1140,8 +1140,10 @@ START_TEST(eina_value_test_array) fail_unless(eina_inarray_append(inarray, &c) >= 0); desc.subtype = EINA_VALUE_TYPE_CHAR; desc.step = 0; - desc.array = inarray; /* will be adopted and freed by value */ + desc.array = inarray; fail_unless(eina_value_set(value, desc)); /* manually configure */ + eina_inarray_free(inarray); + fail_unless(eina_value_array_get(value, 0, &c)); fail_unless(c == 11); fail_unless(eina_value_array_get(value, 1, &c)); @@ -1242,11 +1244,13 @@ START_TEST(eina_value_test_list) desc.subtype = EINA_VALUE_TYPE_STRING; desc.list = NULL; - desc.list = eina_list_append(desc.list, strdup("hello")); - desc.list = eina_list_append(desc.list, strdup("world")); - desc.list = eina_list_append(desc.list, strdup("eina")); + desc.list = eina_list_append(desc.list, "hello"); + desc.list = eina_list_append(desc.list, "world"); + desc.list = eina_list_append(desc.list, "eina"); fail_unless(eina_list_count(desc.list) == 3); fail_unless(eina_value_set(value, desc)); + eina_list_free(desc.list); + fail_unless(eina_value_list_get(value, 0, &s)); fail_unless(s != NULL); fail_unless(strcmp(s, "hello") == 0); @@ -1351,14 +1355,17 @@ START_TEST(eina_value_test_hash) fail_unless(desc.hash != NULL); /* watch out hash pointer is to a size of subtype->value_size! */ ptr = malloc(sizeof(char *)); - *ptr = strdup("there"); + *ptr = "there"; fail_unless(eina_hash_add(desc.hash, "hi", ptr)); ptr = malloc(sizeof(char *)); - *ptr = strdup("y"); + *ptr = "y"; fail_unless(eina_hash_add(desc.hash, "x", ptr)); - fail_unless(eina_value_set(value, desc)); + free(eina_hash_find(desc.hash, "hi")); + free(eina_hash_find(desc.hash, "x")); + eina_hash_free(desc.hash); + fail_unless(eina_value_hash_get(value, "hi", &s)); fail_unless(s != NULL); fail_unless(strcmp(s, "there") == 0); @@ -1606,6 +1613,20 @@ START_TEST(eina_value_test_struct) fail_unless(eina_value_struct_get(value, "c", &c)); fail_unless(c == 0xf); + fail_unless(eina_value_struct_member_value_get + (value, myst_members + 0, &other)); + fail_unless(other.type == EINA_VALUE_TYPE_INT); + fail_unless(eina_value_get(&other, &i)); + fail_unless(i == 5678); + eina_value_flush(&other); + + fail_unless(eina_value_struct_member_value_get + (value, myst_members + 1, &other)); + fail_unless(other.type == EINA_VALUE_TYPE_CHAR); + fail_unless(eina_value_get(&other, &c)); + fail_unless(c = 0xf); + eina_value_flush(&other); + str = eina_value_to_string(value); fail_unless(str != NULL); fail_unless(strcmp(str, "{i: 5678, c: 15}") == 0); @@ -1704,6 +1725,7 @@ START_TEST(eina_value_test_struct) fail_unless(strcmp(str, "{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 12, l: 13, m: 14, n: 15, o: 16, p: 17, q: 18, r: 19, s: 20, t: 21, u: 22, v: 23, x: 24}") == 0); free(str); + eina_value_flush(&other); eina_value_free(value); eina_shutdown(); } @@ -1728,7 +1750,7 @@ START_TEST(eina_value_test_array_of_struct) EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH, myst_members, 4, sizeof(struct myst) }; - Eina_Value *value; + Eina_Value *value, array_item; char *str; int i; @@ -1740,20 +1762,17 @@ START_TEST(eina_value_test_array_of_struct) for (i = 0; i < 10; i++) { Eina_Value_Struct desc; - struct myst *st; + struct myst st; char buf[64]; snprintf(buf, sizeof(buf), "item%02d", i); - st = malloc(sizeof(struct myst)); - fail_unless(st != NULL); - st->a = i; - st->b = i * 10; - st->c = i * 100; - st->s = strdup(buf); - fail_unless(st->s != NULL); + st.a = i; + st.b = i * 10; + st.c = i * 100; + st.s = buf; desc.desc = &myst_desc; - desc.memory = st; + desc.memory = &st; fail_unless(eina_value_array_append(value, desc)); } @@ -1773,11 +1792,66 @@ START_TEST(eina_value_test_array_of_struct) "]") == 0); free(str); + eina_value_array_value_get(value, 2, &array_item); + eina_value_struct_get(&array_item, "a", &i); + ck_assert_int_eq(i, 2); + eina_value_struct_get(&array_item, "b", &i); + ck_assert_int_eq(i, 20); + eina_value_struct_get(&array_item, "c", &i); + ck_assert_int_eq(i, 200); + eina_value_struct_get(&array_item, "s", &str); + ck_assert_str_eq(str, "item02"); + eina_value_flush(&array_item); + eina_value_free(value); eina_shutdown(); } END_TEST + +START_TEST(eina_value_test_model) +{ + Eina_Value *value, inv; + Eina_Model *model, *m; + char *str; + + eina_init(); + + value = eina_value_new(EINA_VALUE_TYPE_MODEL); + fail_unless(value != NULL); + + model = eina_model_new(EINA_MODEL_TYPE_GENERIC); + fail_unless(model != NULL); + + fail_unless(eina_value_setup(&inv, EINA_VALUE_TYPE_INT)); + fail_unless(eina_value_set(&inv, 1234)); + fail_unless(eina_model_property_set(model, "i", &inv)); + eina_value_flush(&inv); + + fail_unless(eina_value_set(value, model)); + fail_unless(eina_model_refcount(model) == 2); + + fail_unless(eina_value_get(value, &m)); + fail_unless(m == model); + fail_unless(eina_model_refcount(m) == 2); + + fail_unless(eina_value_pset(value, &model)); + fail_unless(eina_model_refcount(model) == 2); + + str = eina_value_to_string(value); + fail_unless(str != NULL); + fail_unless(strcmp(str, "Eina_Model_Type_Generic({i: 1234}, [])") == 0); + free(str); + + eina_value_free(value); + + fail_unless(eina_model_refcount(model) == 1); + eina_model_unref(model); + + eina_shutdown(); +} +END_TEST + void eina_test_value(TCase *tc) { @@ -1796,4 +1870,5 @@ eina_test_value(TCase *tc) tcase_add_test(tc, eina_value_test_blob); tcase_add_test(tc, eina_value_test_struct); tcase_add_test(tc, eina_value_test_array_of_struct); + tcase_add_test(tc, eina_value_test_model); } -- cgit v1.1