diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/eina/src/tests | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2 SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz |
Update EFL to latest beta.
Diffstat (limited to 'libraries/eina/src/tests')
-rw-r--r-- | libraries/eina/src/tests/Makefile.am | 3 | ||||
-rw-r--r-- | libraries/eina/src/tests/Makefile.in | 48 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_suite.c | 3 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_suite.h | 1 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_clist.c | 2 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_counter.c | 92 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_error.c | 184 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_file.c | 54 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_inlist.c | 171 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_list.c | 40 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_log.c | 217 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_magic.c | 110 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_simple_xml_parser.c | 6 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_ustr.c | 130 | ||||
-rw-r--r-- | libraries/eina/src/tests/eina_test_value.c | 109 |
15 files changed, 1104 insertions, 66 deletions
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 \ | |||
66 | eina_test_str.c \ | 66 | eina_test_str.c \ |
67 | eina_test_quadtree.c \ | 67 | eina_test_quadtree.c \ |
68 | eina_test_simple_xml_parser.c \ | 68 | eina_test_simple_xml_parser.c \ |
69 | eina_test_value.c | 69 | eina_test_value.c \ |
70 | eina_test_model.c | ||
70 | 71 | ||
71 | eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm | 72 | eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm |
72 | 73 | ||
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@ | |||
43 | subdir = src/tests | 43 | subdir = src/tests |
44 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in | 44 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in |
45 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | 45 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
46 | am__aclocal_m4_deps = $(top_srcdir)/m4/efl_attribute.m4 \ | 46 | am__aclocal_m4_deps = $(top_srcdir)/m4/eina/eina_bench.m4 \ |
47 | $(top_srcdir)/m4/efl_benchmark.m4 \ | 47 | $(top_srcdir)/m4/eina/eina_check.m4 \ |
48 | $(top_srcdir)/m4/efl_compiler_flag.m4 \ | 48 | $(top_srcdir)/m4/common/efl_attribute.m4 \ |
49 | $(top_srcdir)/m4/efl_coverage.m4 $(top_srcdir)/m4/efl_cpu.m4 \ | 49 | $(top_srcdir)/m4/common/efl_benchmark.m4 \ |
50 | $(top_srcdir)/m4/efl_doxygen.m4 \ | 50 | $(top_srcdir)/m4/common/efl_compiler_flag.m4 \ |
51 | $(top_srcdir)/m4/efl_examples.m4 \ | 51 | $(top_srcdir)/m4/common/efl_coverage.m4 \ |
52 | $(top_srcdir)/m4/efl_fnmatch.m4 \ | 52 | $(top_srcdir)/m4/common/efl_cpu.m4 \ |
53 | $(top_srcdir)/m4/efl_path_max.m4 $(top_srcdir)/m4/efl_tests.m4 \ | 53 | $(top_srcdir)/m4/common/efl_doxygen.m4 \ |
54 | $(top_srcdir)/m4/efl_threads.m4 \ | 54 | $(top_srcdir)/m4/common/efl_examples.m4 \ |
55 | $(top_srcdir)/m4/efl_voltron.m4 $(top_srcdir)/m4/eina_bench.m4 \ | 55 | $(top_srcdir)/m4/common/efl_fnmatch.m4 \ |
56 | $(top_srcdir)/m4/eina_check.m4 $(top_srcdir)/m4/libtool.m4 \ | 56 | $(top_srcdir)/m4/common/efl_path_max.m4 \ |
57 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ | 57 | $(top_srcdir)/m4/common/efl_tests.m4 \ |
58 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ | 58 | $(top_srcdir)/m4/common/efl_threads.m4 \ |
59 | $(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac | 59 | $(top_srcdir)/m4/common/efl_voltron.m4 \ |
60 | $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ | ||
61 | $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ | ||
62 | $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ | ||
63 | $(top_srcdir)/configure.ac | ||
60 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | 64 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ |
61 | $(ACLOCAL_M4) | 65 | $(ACLOCAL_M4) |
62 | mkinstalldirs = $(install_sh) -d | 66 | mkinstalldirs = $(install_sh) -d |
@@ -159,7 +163,8 @@ am__eina_suite_SOURCES_DIST = eina_suite.c eina_test_fp.c \ | |||
159 | eina_test_rectangle.c eina_test_list.c \ | 163 | eina_test_rectangle.c eina_test_list.c \ |
160 | eina_test_matrixsparse.c eina_test_tiler.c eina_test_strbuf.c \ | 164 | eina_test_matrixsparse.c eina_test_tiler.c eina_test_strbuf.c \ |
161 | eina_test_str.c eina_test_quadtree.c \ | 165 | eina_test_str.c eina_test_quadtree.c \ |
162 | eina_test_simple_xml_parser.c eina_test_value.c | 166 | eina_test_simple_xml_parser.c eina_test_value.c \ |
167 | eina_test_model.c | ||
163 | @EFL_ENABLE_TESTS_TRUE@am_eina_suite_OBJECTS = eina_suite.$(OBJEXT) \ | 168 | @EFL_ENABLE_TESTS_TRUE@am_eina_suite_OBJECTS = eina_suite.$(OBJEXT) \ |
164 | @EFL_ENABLE_TESTS_TRUE@ eina_test_fp.$(OBJEXT) \ | 169 | @EFL_ENABLE_TESTS_TRUE@ eina_test_fp.$(OBJEXT) \ |
165 | @EFL_ENABLE_TESTS_TRUE@ eina_test_stringshare.$(OBJEXT) \ | 170 | @EFL_ENABLE_TESTS_TRUE@ eina_test_stringshare.$(OBJEXT) \ |
@@ -195,7 +200,8 @@ am__eina_suite_SOURCES_DIST = eina_suite.c eina_test_fp.c \ | |||
195 | @EFL_ENABLE_TESTS_TRUE@ eina_test_str.$(OBJEXT) \ | 200 | @EFL_ENABLE_TESTS_TRUE@ eina_test_str.$(OBJEXT) \ |
196 | @EFL_ENABLE_TESTS_TRUE@ eina_test_quadtree.$(OBJEXT) \ | 201 | @EFL_ENABLE_TESTS_TRUE@ eina_test_quadtree.$(OBJEXT) \ |
197 | @EFL_ENABLE_TESTS_TRUE@ eina_test_simple_xml_parser.$(OBJEXT) \ | 202 | @EFL_ENABLE_TESTS_TRUE@ eina_test_simple_xml_parser.$(OBJEXT) \ |
198 | @EFL_ENABLE_TESTS_TRUE@ eina_test_value.$(OBJEXT) | 203 | @EFL_ENABLE_TESTS_TRUE@ eina_test_value.$(OBJEXT) \ |
204 | @EFL_ENABLE_TESTS_TRUE@ eina_test_model.$(OBJEXT) | ||
199 | eina_suite_OBJECTS = $(am_eina_suite_OBJECTS) | 205 | eina_suite_OBJECTS = $(am_eina_suite_OBJECTS) |
200 | @EFL_ENABLE_TESTS_TRUE@eina_suite_DEPENDENCIES = \ | 206 | @EFL_ENABLE_TESTS_TRUE@eina_suite_DEPENDENCIES = \ |
201 | @EFL_ENABLE_TESTS_TRUE@ $(top_builddir)/src/lib/libeina.la | 207 | @EFL_ENABLE_TESTS_TRUE@ $(top_builddir)/src/lib/libeina.la |
@@ -296,13 +302,13 @@ EINA_CONFIGURE_DEFAULT_MEMPOOL = @EINA_CONFIGURE_DEFAULT_MEMPOOL@ | |||
296 | EINA_CONFIGURE_ENABLE_LOG = @EINA_CONFIGURE_ENABLE_LOG@ | 302 | EINA_CONFIGURE_ENABLE_LOG = @EINA_CONFIGURE_ENABLE_LOG@ |
297 | EINA_CONFIGURE_HAVE_DEBUG_THREADS = @EINA_CONFIGURE_HAVE_DEBUG_THREADS@ | 303 | EINA_CONFIGURE_HAVE_DEBUG_THREADS = @EINA_CONFIGURE_HAVE_DEBUG_THREADS@ |
298 | EINA_CONFIGURE_HAVE_DIRENT_H = @EINA_CONFIGURE_HAVE_DIRENT_H@ | 304 | EINA_CONFIGURE_HAVE_DIRENT_H = @EINA_CONFIGURE_HAVE_DIRENT_H@ |
305 | EINA_CONFIGURE_HAVE_EXOTIC = @EINA_CONFIGURE_HAVE_EXOTIC@ | ||
299 | EINA_CONFIGURE_HAVE_INTTYPES_H = @EINA_CONFIGURE_HAVE_INTTYPES_H@ | 306 | EINA_CONFIGURE_HAVE_INTTYPES_H = @EINA_CONFIGURE_HAVE_INTTYPES_H@ |
300 | EINA_CONFIGURE_HAVE_ON_OFF_THREADS = @EINA_CONFIGURE_HAVE_ON_OFF_THREADS@ | 307 | EINA_CONFIGURE_HAVE_ON_OFF_THREADS = @EINA_CONFIGURE_HAVE_ON_OFF_THREADS@ |
301 | EINA_CONFIGURE_HAVE_STDINT_H = @EINA_CONFIGURE_HAVE_STDINT_H@ | 308 | EINA_CONFIGURE_HAVE_STDINT_H = @EINA_CONFIGURE_HAVE_STDINT_H@ |
302 | EINA_CONFIGURE_HAVE_THREADS = @EINA_CONFIGURE_HAVE_THREADS@ | 309 | EINA_CONFIGURE_HAVE_THREADS = @EINA_CONFIGURE_HAVE_THREADS@ |
303 | EINA_CONFIGURE_MAGIC_DEBUG = @EINA_CONFIGURE_MAGIC_DEBUG@ | 310 | EINA_CONFIGURE_MAGIC_DEBUG = @EINA_CONFIGURE_MAGIC_DEBUG@ |
304 | EINA_CONFIGURE_SAFETY_CHECKS = @EINA_CONFIGURE_SAFETY_CHECKS@ | 311 | EINA_CONFIGURE_SAFETY_CHECKS = @EINA_CONFIGURE_SAFETY_CHECKS@ |
305 | EINA_CPPFLAGS = @EINA_CPPFLAGS@ | ||
306 | EINA_LIBS = @EINA_LIBS@ | 312 | EINA_LIBS = @EINA_LIBS@ |
307 | EINA_SIZEOF_WCHAR_T = @EINA_SIZEOF_WCHAR_T@ | 313 | EINA_SIZEOF_WCHAR_T = @EINA_SIZEOF_WCHAR_T@ |
308 | EMEMOA_CFLAGS = @EMEMOA_CFLAGS@ | 314 | EMEMOA_CFLAGS = @EMEMOA_CFLAGS@ |
@@ -312,6 +318,8 @@ ESCAPE_LIBS = @ESCAPE_LIBS@ | |||
312 | EVIL_CFLAGS = @EVIL_CFLAGS@ | 318 | EVIL_CFLAGS = @EVIL_CFLAGS@ |
313 | EVIL_LIBS = @EVIL_LIBS@ | 319 | EVIL_LIBS = @EVIL_LIBS@ |
314 | EXEEXT = @EXEEXT@ | 320 | EXEEXT = @EXEEXT@ |
321 | EXOTIC_CFLAGS = @EXOTIC_CFLAGS@ | ||
322 | EXOTIC_LIBS = @EXOTIC_LIBS@ | ||
315 | FGREP = @FGREP@ | 323 | FGREP = @FGREP@ |
316 | GLIB_CFLAGS = @GLIB_CFLAGS@ | 324 | GLIB_CFLAGS = @GLIB_CFLAGS@ |
317 | GLIB_LIBS = @GLIB_LIBS@ | 325 | GLIB_LIBS = @GLIB_LIBS@ |
@@ -347,6 +355,8 @@ PACKAGE_URL = @PACKAGE_URL@ | |||
347 | PACKAGE_VERSION = @PACKAGE_VERSION@ | 355 | PACKAGE_VERSION = @PACKAGE_VERSION@ |
348 | PATH_SEPARATOR = @PATH_SEPARATOR@ | 356 | PATH_SEPARATOR = @PATH_SEPARATOR@ |
349 | PKG_CONFIG = @PKG_CONFIG@ | 357 | PKG_CONFIG = @PKG_CONFIG@ |
358 | PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ | ||
359 | PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ | ||
350 | RANLIB = @RANLIB@ | 360 | RANLIB = @RANLIB@ |
351 | SED = @SED@ | 361 | SED = @SED@ |
352 | SET_MAKE = @SET_MAKE@ | 362 | SET_MAKE = @SET_MAKE@ |
@@ -465,7 +475,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/src/include \ | |||
465 | @EFL_ENABLE_TESTS_TRUE@eina_test_str.c \ | 475 | @EFL_ENABLE_TESTS_TRUE@eina_test_str.c \ |
466 | @EFL_ENABLE_TESTS_TRUE@eina_test_quadtree.c \ | 476 | @EFL_ENABLE_TESTS_TRUE@eina_test_quadtree.c \ |
467 | @EFL_ENABLE_TESTS_TRUE@eina_test_simple_xml_parser.c \ | 477 | @EFL_ENABLE_TESTS_TRUE@eina_test_simple_xml_parser.c \ |
468 | @EFL_ENABLE_TESTS_TRUE@eina_test_value.c | 478 | @EFL_ENABLE_TESTS_TRUE@eina_test_value.c \ |
479 | @EFL_ENABLE_TESTS_TRUE@eina_test_model.c | ||
469 | 480 | ||
470 | @EFL_ENABLE_TESTS_TRUE@eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm | 481 | @EFL_ENABLE_TESTS_TRUE@eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm |
471 | @EFL_ENABLE_TESTS_TRUE@cxx_compile_test_SOURCES = cxx_compile_test.cxx | 482 | @EFL_ENABLE_TESTS_TRUE@cxx_compile_test_SOURCES = cxx_compile_test.cxx |
@@ -704,6 +715,7 @@ distclean-compile: | |||
704 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_main.Po@am__quote@ | 715 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_main.Po@am__quote@ |
705 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_matrixsparse.Po@am__quote@ | 716 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_matrixsparse.Po@am__quote@ |
706 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_mempool.Po@am__quote@ | 717 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_mempool.Po@am__quote@ |
718 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_model.Po@am__quote@ | ||
707 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_module.Po@am__quote@ | 719 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_module.Po@am__quote@ |
708 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_quadtree.Po@am__quote@ | 720 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_quadtree.Po@am__quote@ |
709 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eina_test_rbtree.Po@am__quote@ | 721 | @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[] = { | |||
68 | { "Sched", eina_test_sched }, | 68 | { "Sched", eina_test_sched }, |
69 | { "Simple Xml Parser", eina_test_simple_xml_parser}, | 69 | { "Simple Xml Parser", eina_test_simple_xml_parser}, |
70 | { "Value", eina_test_value }, | 70 | { "Value", eina_test_value }, |
71 | { "Model", eina_test_model }, | ||
71 | { NULL, NULL } | 72 | { NULL, NULL } |
72 | }; | 73 | }; |
73 | 74 | ||
@@ -137,6 +138,8 @@ static void _mempool_init(void) | |||
137 | static void _mempool_shutdown(void) | 138 | static void _mempool_shutdown(void) |
138 | { | 139 | { |
139 | eina_module_list_free(_modules); | 140 | eina_module_list_free(_modules); |
141 | if (_modules) | ||
142 | eina_array_free(_modules); | ||
140 | /* TODO delete the list */ | 143 | /* TODO delete the list */ |
141 | eina_shutdown(); | 144 | eina_shutdown(); |
142 | } | 145 | } |
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); | |||
56 | void eina_test_sched(TCase *tc); | 56 | void eina_test_sched(TCase *tc); |
57 | void eina_test_simple_xml_parser(TCase *tc); | 57 | void eina_test_simple_xml_parser(TCase *tc); |
58 | void eina_test_value(TCase *tc); | 58 | void eina_test_value(TCase *tc); |
59 | void eina_test_model(TCase *tc); | ||
59 | 60 | ||
60 | #endif /* EINA_SUITE_H_ */ | 61 | #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 @@ | |||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <assert.h> | 7 | #include <assert.h> |
8 | 8 | ||
9 | #include <Eina.h> | 9 | #include "Eina.h" |
10 | #include "eina_suite.h" | 10 | #include "eina_suite.h" |
11 | 11 | ||
12 | Eina_Clist string_list = EINA_CLIST_INIT(string_list); | 12 | 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 @@ | |||
27 | #include "Eina.h" | 27 | #include "Eina.h" |
28 | #include "eina_safety_checks.h" | 28 | #include "eina_safety_checks.h" |
29 | 29 | ||
30 | #ifdef EINA_SAFETY_CHECKS | ||
31 | struct log_ctx { | ||
32 | const char *msg; | ||
33 | const char *fnc; | ||
34 | Eina_Bool did; | ||
35 | }; | ||
36 | |||
37 | /* tests should not output on success, just uncomment this for debugging */ | ||
38 | //#define SHOW_LOG 1 | ||
39 | |||
40 | static void | ||
41 | _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__) | ||
42 | { | ||
43 | struct log_ctx *ctx = data; | ||
44 | va_list cp_args; | ||
45 | const char *str; | ||
46 | |||
47 | va_copy(cp_args, args); | ||
48 | str = va_arg(cp_args, const char *); | ||
49 | va_end(cp_args); | ||
50 | |||
51 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
52 | ck_assert_str_eq(fmt, "%s"); | ||
53 | ck_assert_str_eq(ctx->msg, str); | ||
54 | ck_assert_str_eq(ctx->fnc, fnc); | ||
55 | ctx->did = EINA_TRUE; | ||
56 | |||
57 | #ifdef SHOW_LOG | ||
58 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
59 | #else | ||
60 | (void)d; | ||
61 | (void)file; | ||
62 | (void)line; | ||
63 | #endif | ||
64 | } | ||
65 | #endif | ||
66 | |||
30 | START_TEST(eina_counter_simple) | 67 | START_TEST(eina_counter_simple) |
31 | { | 68 | { |
32 | Eina_Counter *cnt; | 69 | Eina_Counter *cnt; |
@@ -61,6 +98,7 @@ START_TEST(eina_counter_simple) | |||
61 | dump = eina_counter_dump(cnt); | 98 | dump = eina_counter_dump(cnt); |
62 | fail_if(!dump); | 99 | fail_if(!dump); |
63 | 100 | ||
101 | /* TODO: parse dump and check if it's right */ | ||
64 | fprintf(stderr, "%s", dump); | 102 | fprintf(stderr, "%s", dump); |
65 | 103 | ||
66 | free(dump); | 104 | free(dump); |
@@ -86,13 +124,65 @@ START_TEST(eina_counter_break) | |||
86 | 124 | ||
87 | #ifdef EINA_SAFETY_CHECKS | 125 | #ifdef EINA_SAFETY_CHECKS |
88 | { | 126 | { |
127 | struct log_ctx ctx; | ||
89 | char *dump; | 128 | char *dump; |
90 | 129 | ||
130 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
131 | ctx.msg = _msg; \ | ||
132 | ctx.fnc = fn; \ | ||
133 | ctx.did = EINA_FALSE | ||
134 | |||
135 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
136 | |||
137 | #ifdef SHOW_LOG | ||
91 | fprintf(stderr, "you should have a safety check failure below:\n"); | 138 | fprintf(stderr, "you should have a safety check failure below:\n"); |
139 | #endif | ||
140 | TEST_MAGIC_SAFETY("eina_counter_new", | ||
141 | "safety check failed: name == NULL"); | ||
142 | cnt = eina_counter_new(NULL); | ||
143 | fail_if(cnt); | ||
144 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
145 | fail_unless(ctx.did); | ||
146 | |||
147 | #ifdef SHOW_LOG | ||
148 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
149 | #endif | ||
150 | TEST_MAGIC_SAFETY("eina_counter_free", | ||
151 | "safety check failed: counter == NULL"); | ||
152 | eina_counter_free(NULL); | ||
153 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
154 | fail_unless(ctx.did); | ||
155 | |||
156 | #ifdef SHOW_LOG | ||
157 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
158 | #endif | ||
159 | TEST_MAGIC_SAFETY("eina_counter_start", | ||
160 | "safety check failed: counter == NULL"); | ||
161 | eina_counter_start(NULL); | ||
162 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
163 | fail_unless(ctx.did); | ||
164 | |||
165 | #ifdef SHOW_LOG | ||
166 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
167 | #endif | ||
168 | TEST_MAGIC_SAFETY("eina_counter_stop", | ||
169 | "safety check failed: counter == NULL"); | ||
170 | eina_counter_stop(NULL, 0); | ||
171 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
172 | fail_unless(ctx.did); | ||
173 | |||
174 | |||
175 | #ifdef SHOW_LOG | ||
176 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
177 | #endif | ||
178 | TEST_MAGIC_SAFETY("eina_counter_dump", | ||
179 | "safety check failed: counter == NULL"); | ||
92 | dump = eina_counter_dump(NULL); | 180 | dump = eina_counter_dump(NULL); |
93 | fail_if(dump); | 181 | fail_if(dump); |
94 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 182 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
95 | free(dump); | 183 | fail_unless(ctx.did); |
184 | |||
185 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
96 | } | 186 | } |
97 | #endif | 187 | #endif |
98 | 188 | ||
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 @@ | |||
33 | 33 | ||
34 | #define TEST_TEXT "The big test\n" | 34 | #define TEST_TEXT "The big test\n" |
35 | 35 | ||
36 | struct log_ctx { | ||
37 | const char *msg; | ||
38 | const char *fnc; | ||
39 | Eina_Bool did; | ||
40 | }; | ||
41 | |||
42 | /* tests should not output on success, just uncomment this for debugging */ | ||
43 | //#define SHOW_LOG 1 | ||
44 | |||
45 | static void | ||
46 | _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__) | ||
47 | { | ||
48 | struct log_ctx *ctx = data; | ||
49 | va_list cp_args; | ||
50 | const char *str; | ||
51 | |||
52 | va_copy(cp_args, args); | ||
53 | str = va_arg(cp_args, const char *); | ||
54 | va_end(cp_args); | ||
55 | |||
56 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
57 | ck_assert_str_eq(fmt, "%s"); | ||
58 | ck_assert_str_eq(ctx->msg, str); | ||
59 | ck_assert_str_eq(ctx->fnc, fnc); | ||
60 | ctx->did = EINA_TRUE; | ||
61 | |||
62 | #ifdef SHOW_LOG | ||
63 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
64 | #else | ||
65 | (void)d; | ||
66 | (void)file; | ||
67 | (void)line; | ||
68 | #endif | ||
69 | } | ||
70 | |||
36 | START_TEST(eina_error_errno) | 71 | START_TEST(eina_error_errno) |
37 | { | 72 | { |
38 | int test; | 73 | int test; |
@@ -52,8 +87,157 @@ START_TEST(eina_error_errno) | |||
52 | } | 87 | } |
53 | END_TEST | 88 | END_TEST |
54 | 89 | ||
90 | START_TEST(eina_error_test_find) | ||
91 | { | ||
92 | int test, r; | ||
93 | const char *str; | ||
94 | |||
95 | eina_init(); | ||
96 | |||
97 | test = eina_error_msg_register(TEST_TEXT); | ||
98 | ck_assert_int_ne(test, 0); | ||
99 | |||
100 | str = eina_error_msg_get(test); | ||
101 | fail_unless(str != NULL); | ||
102 | ck_assert_str_eq(str, TEST_TEXT); | ||
103 | |||
104 | eina_error_set(test); | ||
105 | fail_if(eina_error_get() != test); | ||
106 | |||
107 | r = eina_error_find(TEST_TEXT); | ||
108 | ck_assert_int_eq(r, test); | ||
109 | |||
110 | eina_shutdown(); | ||
111 | } | ||
112 | END_TEST | ||
113 | |||
114 | START_TEST(eina_error_test_modify) | ||
115 | { | ||
116 | int test, r; | ||
117 | const char *str, smsg[] = "Do not copy this string"; | ||
118 | |||
119 | eina_init(); | ||
120 | |||
121 | test = eina_error_msg_register("Some Test Error"); | ||
122 | ck_assert_int_ne(test, 0); | ||
123 | |||
124 | str = eina_error_msg_get(test); | ||
125 | fail_unless(str != NULL); | ||
126 | ck_assert_str_eq(str, "Some Test Error"); | ||
127 | |||
128 | eina_error_set(test); | ||
129 | fail_if(eina_error_get() != test); | ||
130 | |||
131 | fail_unless(eina_error_msg_modify(test, "ABCDE")); | ||
132 | |||
133 | r = eina_error_find("ABCDE"); | ||
134 | ck_assert_int_eq(r, test); | ||
135 | |||
136 | test = eina_error_msg_static_register(smsg); | ||
137 | ck_assert_int_ne(test, 0); | ||
138 | |||
139 | str = eina_error_msg_get(test); | ||
140 | fail_unless(str != NULL); | ||
141 | fail_unless(str == smsg); | ||
142 | |||
143 | fail_unless(eina_error_msg_modify(test, "Change that!")); | ||
144 | r = eina_error_find("Change that!"); | ||
145 | ck_assert_int_eq(r, test); | ||
146 | |||
147 | eina_shutdown(); | ||
148 | } | ||
149 | END_TEST | ||
150 | |||
151 | START_TEST(eina_error_test_lots) | ||
152 | { | ||
153 | char buf[64]; | ||
154 | int codes[512]; | ||
155 | unsigned int i; | ||
156 | |||
157 | eina_init(); | ||
158 | |||
159 | for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) | ||
160 | { | ||
161 | snprintf(buf, sizeof(buf), "myerr-%d", i); | ||
162 | codes[i] = eina_error_msg_register(buf); | ||
163 | ck_assert_int_ne(codes[i], 0); | ||
164 | } | ||
165 | |||
166 | for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) | ||
167 | { | ||
168 | int found; | ||
169 | |||
170 | snprintf(buf, sizeof(buf), "myerr-%d", i); | ||
171 | |||
172 | found = eina_error_find(buf); | ||
173 | ck_assert_int_eq(codes[i], found); | ||
174 | } | ||
175 | |||
176 | eina_shutdown(); | ||
177 | } | ||
178 | END_TEST | ||
179 | |||
180 | #ifdef EINA_SAFETY_CHECKS | ||
181 | START_TEST(eina_error_test_failures) | ||
182 | { | ||
183 | struct log_ctx ctx; | ||
184 | |||
185 | eina_init(); | ||
186 | |||
187 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
188 | |||
189 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
190 | ctx.msg = _msg; \ | ||
191 | ctx.fnc = fn; \ | ||
192 | ctx.did = EINA_FALSE | ||
193 | |||
194 | TEST_MAGIC_SAFETY("eina_error_msg_register", | ||
195 | "safety check failed: msg == NULL"); | ||
196 | ck_assert_int_eq(eina_error_msg_register(NULL), 0); | ||
197 | fail_unless(ctx.did); | ||
198 | |||
199 | TEST_MAGIC_SAFETY("eina_error_msg_static_register", | ||
200 | "safety check failed: msg == NULL"); | ||
201 | ck_assert_int_eq(eina_error_msg_static_register(NULL), 0); | ||
202 | fail_unless(ctx.did); | ||
203 | |||
204 | ck_assert_int_eq(eina_error_msg_modify(0, "X"), EINA_FALSE); | ||
205 | ck_assert_int_eq(eina_error_msg_modify(4096, "X"), EINA_FALSE); | ||
206 | |||
207 | TEST_MAGIC_SAFETY("eina_error_msg_modify", | ||
208 | "safety check failed: msg == NULL"); | ||
209 | ck_assert_int_eq(eina_error_msg_modify(EINA_ERROR_OUT_OF_MEMORY, NULL), | ||
210 | EINA_FALSE); | ||
211 | fail_unless(ctx.did); | ||
212 | |||
213 | ck_assert_str_eq(eina_error_msg_get(EINA_ERROR_OUT_OF_MEMORY), | ||
214 | "Out of memory"); | ||
215 | |||
216 | TEST_MAGIC_SAFETY("eina_error_find", | ||
217 | "safety check failed: msg == NULL"); | ||
218 | ck_assert_int_eq(eina_error_find(NULL), 0); | ||
219 | fail_unless(ctx.did); | ||
220 | |||
221 | ck_assert_int_eq(eina_error_find("Non-existent Error..."), 0); | ||
222 | |||
223 | fail_if(eina_error_msg_get(0)); | ||
224 | fail_if(eina_error_msg_get(4096)); | ||
225 | |||
226 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
227 | |||
228 | eina_shutdown(); | ||
229 | } | ||
230 | END_TEST | ||
231 | #endif | ||
232 | |||
55 | void | 233 | void |
56 | eina_test_error(TCase *tc) | 234 | eina_test_error(TCase *tc) |
57 | { | 235 | { |
58 | tcase_add_test(tc, eina_error_errno); | 236 | tcase_add_test(tc, eina_error_errno); |
237 | tcase_add_test(tc, eina_error_test_find); | ||
238 | tcase_add_test(tc, eina_error_test_modify); | ||
239 | tcase_add_test(tc, eina_error_test_lots); | ||
240 | #ifdef EINA_SAFETY_CHECKS | ||
241 | tcase_add_test(tc, eina_error_test_failures); | ||
242 | #endif | ||
59 | } | 243 | } |
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 @@ | |||
28 | #include "Eina.h" | 28 | #include "Eina.h" |
29 | #include "eina_safety_checks.h" | 29 | #include "eina_safety_checks.h" |
30 | 30 | ||
31 | #ifdef EINA_SAFETY_CHECKS | ||
32 | struct log_ctx { | ||
33 | const char *msg; | ||
34 | const char *fnc; | ||
35 | Eina_Bool did; | ||
36 | }; | ||
37 | |||
38 | /* tests should not output on success, just uncomment this for debugging */ | ||
39 | //#define SHOW_LOG 1 | ||
40 | |||
41 | static void | ||
42 | _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__) | ||
43 | { | ||
44 | struct log_ctx *ctx = data; | ||
45 | va_list cp_args; | ||
46 | const char *str; | ||
47 | |||
48 | va_copy(cp_args, args); | ||
49 | str = va_arg(cp_args, const char *); | ||
50 | va_end(cp_args); | ||
51 | |||
52 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
53 | ck_assert_str_eq(fmt, "%s"); | ||
54 | ck_assert_str_eq(ctx->msg, str); | ||
55 | ck_assert_str_eq(ctx->fnc, fnc); | ||
56 | ctx->did = EINA_TRUE; | ||
57 | |||
58 | #ifdef SHOW_LOG | ||
59 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
60 | #else | ||
61 | (void)d; | ||
62 | (void)file; | ||
63 | (void)line; | ||
64 | #endif | ||
65 | } | ||
66 | #endif | ||
67 | |||
68 | |||
31 | START_TEST(eina_file_split_simple) | 69 | START_TEST(eina_file_split_simple) |
32 | { | 70 | { |
33 | Eina_Array *ea; | 71 | Eina_Array *ea; |
@@ -35,10 +73,26 @@ START_TEST(eina_file_split_simple) | |||
35 | eina_init(); | 73 | eina_init(); |
36 | 74 | ||
37 | #ifdef EINA_SAFETY_CHECKS | 75 | #ifdef EINA_SAFETY_CHECKS |
76 | #ifdef SHOW_LOG | ||
38 | fprintf(stderr, "you should have a safety check failure below:\n"); | 77 | fprintf(stderr, "you should have a safety check failure below:\n"); |
78 | #endif | ||
79 | struct log_ctx ctx; | ||
80 | |||
81 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
82 | ctx.msg = _msg; \ | ||
83 | ctx.fnc = fn; \ | ||
84 | ctx.did = EINA_FALSE | ||
85 | |||
86 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
87 | |||
88 | TEST_MAGIC_SAFETY("eina_file_split", "safety check failed: path == NULL"); | ||
39 | ea = eina_file_split(NULL); | 89 | ea = eina_file_split(NULL); |
40 | fail_if(ea); | 90 | fail_if(ea); |
41 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 91 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
92 | fail_unless(ctx.did); | ||
93 | |||
94 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
95 | #undef TEST_MAGIC_SAFETY | ||
42 | #endif | 96 | #endif |
43 | 97 | ||
44 | #ifdef _WIN32 | 98 | #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 | |||
34 | EINA_INLIST; | 34 | EINA_INLIST; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | #ifdef EINA_SAFETY_CHECKS | ||
38 | struct log_ctx { | ||
39 | const char *msg; | ||
40 | const char *fnc; | ||
41 | Eina_Bool did; | ||
42 | }; | ||
43 | |||
44 | /* tests should not output on success, just uncomment this for debugging */ | ||
45 | //#define SHOW_LOG 1 | ||
46 | |||
47 | static void | ||
48 | _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__) | ||
49 | { | ||
50 | struct log_ctx *ctx = data; | ||
51 | va_list cp_args; | ||
52 | const char *str; | ||
53 | |||
54 | va_copy(cp_args, args); | ||
55 | str = va_arg(cp_args, const char *); | ||
56 | va_end(cp_args); | ||
57 | |||
58 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
59 | ck_assert_str_eq(fmt, "%s"); | ||
60 | ck_assert_str_eq(ctx->msg, str); | ||
61 | ck_assert_str_eq(ctx->fnc, fnc); | ||
62 | ctx->did = EINA_TRUE; | ||
63 | |||
64 | #ifdef SHOW_LOG | ||
65 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
66 | #else | ||
67 | (void)d; | ||
68 | (void)file; | ||
69 | (void)line; | ||
70 | #endif | ||
71 | } | ||
72 | #endif | ||
73 | |||
37 | static Eina_Test_Inlist * | 74 | static Eina_Test_Inlist * |
38 | _eina_test_inlist_build(int i) | 75 | _eina_test_inlist_build(int i) |
39 | { | 76 | { |
@@ -52,6 +89,10 @@ START_TEST(eina_inlist_simple) | |||
52 | Eina_Test_Inlist *tmp; | 89 | Eina_Test_Inlist *tmp; |
53 | Eina_Test_Inlist *prev; | 90 | Eina_Test_Inlist *prev; |
54 | int i = 0; | 91 | int i = 0; |
92 | #ifdef EINA_SAFETY_CHECKS | ||
93 | Eina_Inlist *bkp; | ||
94 | struct log_ctx ctx; | ||
95 | #endif | ||
55 | 96 | ||
56 | fail_if(!eina_init()); | 97 | fail_if(!eina_init()); |
57 | 98 | ||
@@ -106,16 +147,142 @@ START_TEST(eina_inlist_simple) | |||
106 | } | 147 | } |
107 | 148 | ||
108 | #ifdef EINA_SAFETY_CHECKS | 149 | #ifdef EINA_SAFETY_CHECKS |
150 | bkp = lst; | ||
151 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
152 | |||
153 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
154 | ctx.msg = _msg; \ | ||
155 | ctx.fnc = fn; \ | ||
156 | ctx.did = EINA_FALSE | ||
157 | |||
158 | #ifdef SHOW_LOG | ||
109 | fprintf(stderr, "you should have a safety check failure below:\n"); | 159 | fprintf(stderr, "you should have a safety check failure below:\n"); |
160 | #endif | ||
110 | { | 161 | { |
111 | Eina_Inlist *tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp)); | 162 | Eina_Inlist *tmp2; |
163 | |||
164 | TEST_MAGIC_SAFETY("eina_inlist_remove", | ||
165 | "safety check failed: list == NULL"); | ||
166 | |||
167 | tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp)); | ||
112 | fail_if(tmp2 != NULL); | 168 | fail_if(tmp2 != NULL); |
113 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 169 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
170 | fail_unless(ctx.did); | ||
114 | } | 171 | } |
115 | 172 | ||
116 | fprintf(stderr, "you should have a safety check failure below:\n"); | 173 | #ifdef SHOW_LOG |
174 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
175 | #endif | ||
176 | TEST_MAGIC_SAFETY("eina_inlist_remove", | ||
177 | "safety check failed: item == NULL"); | ||
117 | lst = eina_inlist_remove(lst, NULL); | 178 | lst = eina_inlist_remove(lst, NULL); |
118 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 179 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
180 | fail_unless(ctx.did); | ||
181 | |||
182 | #ifdef SHOW_LOG | ||
183 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
184 | #endif | ||
185 | TEST_MAGIC_SAFETY("eina_inlist_append", | ||
186 | "safety check failed: new_l == NULL"); | ||
187 | lst = eina_inlist_append(lst, NULL); | ||
188 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
189 | fail_unless(ctx.did); | ||
190 | |||
191 | #ifdef SHOW_LOG | ||
192 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
193 | #endif | ||
194 | TEST_MAGIC_SAFETY("eina_inlist_append_relative", | ||
195 | "safety check failed: new_l == NULL"); | ||
196 | lst = eina_inlist_append_relative(lst, NULL, NULL); | ||
197 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
198 | fail_unless(ctx.did); | ||
199 | |||
200 | #ifdef SHOW_LOG | ||
201 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
202 | #endif | ||
203 | TEST_MAGIC_SAFETY("eina_inlist_prepend", | ||
204 | "safety check failed: new_l == NULL"); | ||
205 | lst = eina_inlist_prepend(lst, NULL); | ||
206 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
207 | fail_unless(ctx.did); | ||
208 | |||
209 | #ifdef SHOW_LOG | ||
210 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
211 | #endif | ||
212 | TEST_MAGIC_SAFETY("eina_inlist_prepend_relative", | ||
213 | "safety check failed: new_l == NULL"); | ||
214 | lst = eina_inlist_prepend_relative(lst, NULL, NULL); | ||
215 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
216 | fail_unless(ctx.did); | ||
217 | |||
218 | #ifdef SHOW_LOG | ||
219 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
220 | #endif | ||
221 | TEST_MAGIC_SAFETY("eina_inlist_find", | ||
222 | "safety check failed: item == NULL"); | ||
223 | lst = eina_inlist_find(lst, NULL); | ||
224 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
225 | fail_unless(ctx.did); | ||
226 | |||
227 | #ifdef SHOW_LOG | ||
228 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
229 | #endif | ||
230 | TEST_MAGIC_SAFETY("eina_inlist_demote", | ||
231 | "safety check failed: list == NULL"); | ||
232 | lst = eina_inlist_demote(NULL, NULL); | ||
233 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
234 | fail_unless(ctx.did); | ||
235 | |||
236 | #ifdef SHOW_LOG | ||
237 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
238 | #endif | ||
239 | TEST_MAGIC_SAFETY("eina_inlist_demote", | ||
240 | "safety check failed: item == NULL"); | ||
241 | lst = eina_inlist_demote((void*)1L, NULL); | ||
242 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
243 | fail_unless(ctx.did); | ||
244 | lst = NULL; | ||
245 | |||
246 | #ifdef SHOW_LOG | ||
247 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
248 | #endif | ||
249 | TEST_MAGIC_SAFETY("eina_inlist_promote", | ||
250 | "safety check failed: list == NULL"); | ||
251 | lst = eina_inlist_promote(NULL, NULL); | ||
252 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
253 | fail_unless(ctx.did); | ||
254 | |||
255 | #ifdef SHOW_LOG | ||
256 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
257 | #endif | ||
258 | TEST_MAGIC_SAFETY("eina_inlist_promote", | ||
259 | "safety check failed: item == NULL"); | ||
260 | lst = eina_inlist_promote((void*)1L, NULL); | ||
261 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
262 | fail_unless(ctx.did); | ||
263 | lst = NULL; | ||
264 | |||
265 | #ifdef SHOW_LOG | ||
266 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
267 | #endif | ||
268 | TEST_MAGIC_SAFETY("eina_inlist_sorted_insert", | ||
269 | "safety check failed: item == NULL"); | ||
270 | lst = eina_inlist_sorted_insert(NULL, NULL, NULL); | ||
271 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
272 | fail_unless(ctx.did); | ||
273 | |||
274 | #ifdef SHOW_LOG | ||
275 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
276 | #endif | ||
277 | TEST_MAGIC_SAFETY("eina_inlist_sorted_insert", | ||
278 | "safety check failed: func == NULL"); | ||
279 | lst = eina_inlist_sorted_insert(NULL, (void*)1L, NULL); | ||
280 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
281 | fail_unless(ctx.did); | ||
282 | lst = NULL; | ||
283 | |||
284 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
285 | lst = bkp; | ||
119 | #endif | 286 | #endif |
120 | 287 | ||
121 | tmp = EINA_INLIST_CONTAINER_GET(lst, Eina_Test_Inlist); | 288 | 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) | |||
338 | } | 338 | } |
339 | END_TEST | 339 | END_TEST |
340 | 340 | ||
341 | START_TEST(eina_test_list_split) | ||
342 | { | ||
343 | Eina_List *left = NULL, *right = NULL ; | ||
344 | Eina_List *list = NULL; | ||
345 | Eina_List *l; | ||
346 | void *list_data; | ||
347 | int i; | ||
348 | |||
349 | eina_init(); | ||
350 | |||
351 | list = eina_list_append(list, "tigh"); | ||
352 | list = eina_list_append(list, "adar"); | ||
353 | list = eina_list_append(list, "baltar"); | ||
354 | list = eina_list_append(list, "roslin"); | ||
355 | list = eina_list_append(list, "baltar"); | ||
356 | list = eina_list_append(list, "roslin"); | ||
357 | list = eina_list_append(list, "baltar"); | ||
358 | list = eina_list_append(list, "roslin"); | ||
359 | |||
360 | fail_if(list == NULL); | ||
361 | fail_if(eina_list_count(list) != 8); | ||
362 | |||
363 | for ( i = 0; i < 200; i++) | ||
364 | { | ||
365 | left = eina_list_split_list(list, eina_list_nth_list(list, i % 2), &right); | ||
366 | |||
367 | if (i % 2 == 0) | ||
368 | fail_if(eina_list_count(left) == 1 && eina_list_count(right) + eina_list_count(left) == i + 7); | ||
369 | else | ||
370 | fail_if(eina_list_count(left) == 2 && eina_list_count(right) + eina_list_count(left) == i + 7); | ||
371 | |||
372 | list = eina_list_merge(left, right); | ||
373 | list = eina_list_append(list, "roslin"); | ||
374 | } | ||
375 | |||
376 | eina_shutdown(); | ||
377 | } | ||
378 | END_TEST | ||
379 | |||
341 | void | 380 | void |
342 | eina_test_list(TCase *tc) | 381 | eina_test_list(TCase *tc) |
343 | { | 382 | { |
344 | tcase_add_test(tc, eina_test_simple); | 383 | tcase_add_test(tc, eina_test_simple); |
345 | tcase_add_test(tc, eina_test_merge); | 384 | tcase_add_test(tc, eina_test_merge); |
346 | tcase_add_test(tc, eina_test_sorted_insert); | 385 | tcase_add_test(tc, eina_test_sorted_insert); |
386 | tcase_add_test(tc, eina_test_list_split); | ||
347 | } | 387 | } |
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 @@ | |||
27 | #include "eina_suite.h" | 27 | #include "eina_suite.h" |
28 | #include "Eina.h" | 28 | #include "Eina.h" |
29 | 29 | ||
30 | START_TEST(eina_log_macro) | 30 | struct log_ctx { |
31 | int level; | ||
32 | int line; | ||
33 | const char *msg; | ||
34 | const char *fnc; | ||
35 | const char *dom; | ||
36 | Eina_Bool did; | ||
37 | }; | ||
38 | |||
39 | /* tests should not output on success, just uncomment this for debugging */ | ||
40 | //#define SHOW_LOG 1 | ||
41 | |||
42 | static void | ||
43 | _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__) | ||
31 | { | 44 | { |
45 | struct log_ctx *ctx = data; | ||
46 | ck_assert_int_eq(ctx->level, level); | ||
47 | ck_assert_int_eq(ctx->line, line); | ||
48 | ck_assert_str_eq(ctx->msg, fmt); | ||
49 | ck_assert_str_eq(ctx->fnc, fnc); | ||
50 | ck_assert_str_eq(file, __FILE__); | ||
51 | ctx->did = EINA_TRUE; | ||
52 | #ifdef SHOW_LOG | ||
53 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
54 | #else | ||
55 | (void)d; | ||
56 | #endif | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | _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__) | ||
61 | { | ||
62 | struct log_ctx *ctx = data; | ||
63 | ck_assert_int_eq(ctx->level, level); | ||
64 | ck_assert_int_eq(ctx->line, line); | ||
65 | ck_assert_str_eq(ctx->msg, fmt); | ||
66 | ck_assert_str_eq(ctx->fnc, fnc); | ||
67 | ck_assert_str_eq(file, __FILE__); | ||
68 | ck_assert_str_eq(ctx->dom, d->name); | ||
69 | ctx->did = EINA_TRUE; | ||
70 | #ifdef SHOW_LOG | ||
71 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
72 | #endif | ||
73 | } | ||
74 | |||
75 | static void | ||
76 | _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__) | ||
77 | { | ||
78 | struct log_ctx *ctx = data; | ||
79 | va_list cp_args; | ||
80 | const char *str; | ||
81 | |||
82 | va_copy(cp_args, args); | ||
83 | str = va_arg(cp_args, const char *); | ||
84 | va_end(cp_args); | ||
85 | |||
86 | ck_assert_int_eq(ctx->level, level); | ||
87 | ck_assert_str_eq(fmt, "%s"); | ||
88 | ck_assert_str_eq(ctx->msg, str); | ||
89 | ck_assert_str_eq(ctx->fnc, fnc); | ||
90 | ctx->did = EINA_TRUE; | ||
91 | |||
92 | #ifdef SHOW_LOG | ||
93 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
94 | #else | ||
95 | (void)d; | ||
96 | (void)file; | ||
97 | (void)line; | ||
98 | #endif | ||
99 | } | ||
100 | |||
101 | START_TEST(eina_log_macro) | ||
102 | { | ||
103 | struct log_ctx ctx; | ||
104 | int oldlevel; | ||
105 | |||
32 | fail_if(!eina_init()); | 106 | fail_if(!eina_init()); |
33 | 107 | ||
108 | oldlevel = eina_log_level_get(); | ||
34 | eina_log_level_set(EINA_LOG_LEVEL_DBG); | 109 | eina_log_level_set(EINA_LOG_LEVEL_DBG); |
35 | eina_log_print_cb_set(eina_log_print_cb_file, stderr); | 110 | eina_log_print_cb_set(_eina_test_log, &ctx); |
111 | |||
112 | #define TEST_LOG_CTX(lvl, _msg) \ | ||
113 | ctx.level = lvl; \ | ||
114 | ctx.line = __LINE__ + 1; \ | ||
115 | ctx.msg = _msg; \ | ||
116 | ctx.fnc = __FUNCTION__; \ | ||
117 | ctx.did = EINA_FALSE | ||
118 | |||
119 | TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "Critical message"); | ||
120 | EINA_LOG_CRIT("Critical message"); | ||
121 | fail_unless(ctx.did); | ||
122 | |||
123 | TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error"); | ||
124 | EINA_LOG_ERR("An error"); | ||
125 | fail_unless(ctx.did); | ||
36 | 126 | ||
37 | EINA_LOG_CRIT("Critical message\n"); | 127 | TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning"); |
38 | EINA_LOG_ERR("An error\n"); | 128 | EINA_LOG_WARN("A warning"); |
39 | EINA_LOG_INFO("An info\n"); | 129 | fail_unless(ctx.did); |
40 | EINA_LOG_WARN("A warning\n"); | 130 | |
41 | EINA_LOG_DBG("A debug\n"); | 131 | TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info"); |
132 | EINA_LOG_INFO("An info"); | ||
133 | fail_unless(ctx.did); | ||
134 | |||
135 | TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug"); | ||
136 | EINA_LOG_DBG("A debug"); | ||
137 | fail_unless(ctx.did); | ||
138 | |||
139 | #undef TEST_LOG_CTX | ||
140 | |||
141 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
142 | eina_log_level_set(oldlevel); | ||
42 | 143 | ||
43 | eina_shutdown(); | 144 | eina_shutdown(); |
44 | } | 145 | } |
@@ -46,16 +147,54 @@ END_TEST | |||
46 | 147 | ||
47 | START_TEST(eina_log_domains_macros) | 148 | START_TEST(eina_log_domains_macros) |
48 | { | 149 | { |
150 | struct log_ctx ctx; | ||
151 | int oldlevel; | ||
152 | |||
49 | fail_if(!eina_init()); | 153 | fail_if(!eina_init()); |
50 | 154 | ||
155 | /* make global log level blocker */ | ||
156 | oldlevel = eina_log_level_get(); | ||
157 | eina_log_level_set(EINA_LOG_LEVEL_CRITICAL); | ||
158 | eina_log_print_cb_set(_eina_test_log_domain, &ctx); | ||
159 | |||
51 | int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); | 160 | int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); |
52 | fail_if(d < 0); | 161 | fail_if(d < 0); |
53 | 162 | ||
54 | EINA_LOG_DOM_CRIT(d, "A critical message\n"); | 163 | /* make specific domain permissive */ |
55 | EINA_LOG_DOM_ERR(d, "An error\n"); | 164 | eina_log_domain_level_set("MyDomain", EINA_LOG_LEVEL_DBG); |
56 | EINA_LOG_DOM_WARN(d, "A warning\n"); | 165 | |
57 | EINA_LOG_DOM_DBG(d, "A debug\n"); | 166 | #define TEST_LOG_CTX(lvl, _msg) \ |
58 | EINA_LOG_DOM_INFO(d, "An info\n"); | 167 | ctx.level = lvl; \ |
168 | ctx.line = __LINE__ + 1; \ | ||
169 | ctx.msg = _msg; \ | ||
170 | ctx.fnc = __FUNCTION__; \ | ||
171 | ctx.dom = "MyDomain"; \ | ||
172 | ctx.did = EINA_FALSE | ||
173 | |||
174 | TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "A critical message"); | ||
175 | EINA_LOG_DOM_CRIT(d, "A critical message"); | ||
176 | fail_unless(ctx.did); | ||
177 | |||
178 | TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error"); | ||
179 | EINA_LOG_DOM_ERR(d, "An error"); | ||
180 | fail_unless(ctx.did); | ||
181 | |||
182 | TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning"); | ||
183 | EINA_LOG_DOM_WARN(d, "A warning"); | ||
184 | fail_unless(ctx.did); | ||
185 | |||
186 | TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info"); | ||
187 | EINA_LOG_DOM_INFO(d, "An info"); | ||
188 | fail_unless(ctx.did); | ||
189 | |||
190 | TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug"); | ||
191 | EINA_LOG_DOM_DBG(d, "A debug"); | ||
192 | fail_unless(ctx.did); | ||
193 | |||
194 | #undef TEST_LOG_CTX | ||
195 | |||
196 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
197 | eina_log_level_set(oldlevel); | ||
59 | 198 | ||
60 | eina_shutdown(); | 199 | eina_shutdown(); |
61 | } | 200 | } |
@@ -120,6 +259,8 @@ END_TEST | |||
120 | 259 | ||
121 | START_TEST(eina_log_level_indexes) | 260 | START_TEST(eina_log_level_indexes) |
122 | { | 261 | { |
262 | struct log_ctx ctx; | ||
263 | |||
123 | fail_if(!eina_init()); | 264 | fail_if(!eina_init()); |
124 | fail_if(!eina_threads_init()); | 265 | fail_if(!eina_threads_init()); |
125 | fail_if(!eina_threads_init()); | 266 | fail_if(!eina_threads_init()); |
@@ -127,11 +268,41 @@ START_TEST(eina_log_level_indexes) | |||
127 | int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); | 268 | int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); |
128 | fail_if(d < 0); | 269 | fail_if(d < 0); |
129 | 270 | ||
271 | eina_log_print_cb_set(_eina_test_log_domain, &ctx); | ||
272 | |||
273 | #define TEST_LOG_CTX(lvl, _msg) \ | ||
274 | ctx.level = lvl; \ | ||
275 | ctx.line = __LINE__ + 1; \ | ||
276 | ctx.msg = _msg; \ | ||
277 | ctx.fnc = __FUNCTION__; \ | ||
278 | ctx.dom = "Levels"; \ | ||
279 | ctx.did = EINA_FALSE; | ||
280 | |||
130 | // Displayed unless user sets level lower than -1 | 281 | // Displayed unless user sets level lower than -1 |
131 | EINA_LOG(d, -1, "Negative index message\n"); | 282 | eina_log_domain_level_set("Levels", -1); |
283 | TEST_LOG_CTX(-1, "Negative index message"); | ||
284 | EINA_LOG(d, -1, "Negative index message"); | ||
285 | fail_unless(ctx.did); | ||
286 | |||
287 | eina_log_domain_level_set("Levels", -2); | ||
288 | TEST_LOG_CTX(-1, "Negative index message"); | ||
289 | EINA_LOG(d, -1, "Negative index message"); | ||
290 | fail_if(ctx.did); | ||
132 | 291 | ||
133 | // Displayed only if user sets level 6 or higher | 292 | // Displayed only if user sets level 6 or higher |
134 | EINA_LOG(d, 6, "Higher level debug\n"); | 293 | eina_log_domain_level_set("Levels", 6); |
294 | TEST_LOG_CTX(6, "Higher level debug"); | ||
295 | EINA_LOG(d, 6, "Higher level debug"); | ||
296 | fail_unless(ctx.did); | ||
297 | |||
298 | eina_log_domain_level_set("Levels", 5); | ||
299 | TEST_LOG_CTX(6, "Higher level debug"); | ||
300 | EINA_LOG(d, 6, "Higher level debug"); | ||
301 | fail_if(ctx.did); | ||
302 | |||
303 | #undef TEST_LOG_CTX | ||
304 | |||
305 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
135 | 306 | ||
136 | eina_threads_shutdown(); | 307 | eina_threads_shutdown(); |
137 | eina_threads_shutdown(); | 308 | eina_threads_shutdown(); |
@@ -141,6 +312,7 @@ END_TEST | |||
141 | 312 | ||
142 | START_TEST(eina_log_customize) | 313 | START_TEST(eina_log_customize) |
143 | { | 314 | { |
315 | struct log_ctx ctx; | ||
144 | int d; | 316 | int d; |
145 | 317 | ||
146 | /* please don't define EINA_LOG_LEVELS for it */ | 318 | /* please don't define EINA_LOG_LEVELS for it */ |
@@ -182,11 +354,28 @@ START_TEST(eina_log_customize) | |||
182 | fail_if(eina_log_domain_registered_level_get(d) != 890); | 354 | fail_if(eina_log_domain_registered_level_get(d) != 890); |
183 | 355 | ||
184 | eina_log_domain_unregister(d); | 356 | eina_log_domain_unregister(d); |
357 | |||
358 | #ifdef EINA_SAFETY_CHECKS | ||
359 | #ifdef SHOW_LOG | ||
185 | fputs("NOTE: You should see a failed safety check or " | 360 | fputs("NOTE: You should see a failed safety check or " |
186 | "a crash if compiled without safety checks support.\n", | 361 | "a crash if compiled without safety checks support.\n", |
187 | stderr); | 362 | stderr); |
363 | #endif | ||
188 | eina_log_abort_on_critical_set(EINA_FALSE); | 364 | eina_log_abort_on_critical_set(EINA_FALSE); |
365 | eina_log_function_disable_set(EINA_FALSE); | ||
366 | |||
367 | eina_log_print_cb_set(_eina_test_log_safety, &ctx); | ||
368 | ctx.level = EINA_LOG_LEVEL_ERR; | ||
369 | ctx.msg = "safety check failed: _log_domains[domain].deleted is true"; | ||
370 | ctx.fnc = "eina_log_domain_registered_level_get"; | ||
371 | ctx.did = EINA_FALSE; | ||
189 | fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN); | 372 | fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN); |
373 | fail_unless(ctx.did); | ||
374 | |||
375 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
376 | #else | ||
377 | #warning "Compiled without safety checks" | ||
378 | #endif | ||
190 | 379 | ||
191 | #undef test_set_get_bool | 380 | #undef test_set_get_bool |
192 | #undef test_set_get | 381 | #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 | |||
40 | EINA_MAGIC | 40 | EINA_MAGIC |
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct log_ctx { | ||
44 | const char *msg; | ||
45 | const char *fnc; | ||
46 | Eina_Bool did; | ||
47 | }; | ||
48 | |||
49 | /* tests should not output on success, just uncomment this for debugging */ | ||
50 | //#define SHOW_LOG 1 | ||
51 | |||
52 | static void | ||
53 | _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__) | ||
54 | { | ||
55 | struct log_ctx *ctx = data; | ||
56 | va_list cp_args; | ||
57 | const char *str; | ||
58 | |||
59 | va_copy(cp_args, args); | ||
60 | str = va_arg(cp_args, const char *); | ||
61 | va_end(cp_args); | ||
62 | |||
63 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
64 | ck_assert_str_eq(fmt, "%s"); | ||
65 | ck_assert_str_eq(ctx->msg, str); | ||
66 | ck_assert_str_eq(ctx->fnc, fnc); | ||
67 | ctx->did = EINA_TRUE; | ||
68 | |||
69 | #ifdef SHOW_LOG | ||
70 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
71 | #else | ||
72 | (void)d; | ||
73 | (void)file; | ||
74 | (void)line; | ||
75 | #endif | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | _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__) | ||
80 | { | ||
81 | struct log_ctx *ctx = data; | ||
82 | |||
83 | ck_assert_int_eq(level, EINA_LOG_LEVEL_CRITICAL); | ||
84 | ck_assert_str_eq(ctx->msg, fmt); | ||
85 | ck_assert_str_eq(ctx->fnc, fnc); | ||
86 | ctx->did = EINA_TRUE; | ||
87 | |||
88 | #ifdef SHOW_LOG | ||
89 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
90 | #else | ||
91 | (void)d; | ||
92 | (void)file; | ||
93 | (void)line; | ||
94 | #endif | ||
95 | } | ||
96 | |||
97 | #ifdef EINA_SAFETY_CHECKS | ||
98 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
99 | ctx.msg = _msg; \ | ||
100 | ctx.fnc = fn; \ | ||
101 | ctx.did = EINA_FALSE | ||
102 | #endif | ||
103 | |||
43 | START_TEST(eina_magic_simple) | 104 | START_TEST(eina_magic_simple) |
44 | { | 105 | { |
45 | Eina_Magic_Struct *ems = NULL; | 106 | Eina_Magic_Struct *ems = NULL; |
107 | struct log_ctx ctx; | ||
46 | 108 | ||
47 | eina_init(); | 109 | eina_init(); |
48 | 110 | ||
111 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
112 | |||
49 | eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); | 113 | eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); |
50 | 114 | ||
51 | #ifdef EINA_SAFETY_CHECKS | 115 | #ifdef EINA_SAFETY_CHECKS |
116 | #ifdef SHOW_LOG | ||
52 | fprintf(stderr, "you should have a safety check failure below:\n"); | 117 | fprintf(stderr, "you should have a safety check failure below:\n"); |
118 | #endif | ||
119 | TEST_MAGIC_SAFETY("eina_magic_string_set", | ||
120 | "safety check failed: magic_name == NULL"); | ||
53 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | 121 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); |
54 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 122 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
123 | fail_unless(ctx.did); | ||
55 | 124 | ||
125 | #ifdef SHOW_LOG | ||
56 | fprintf(stderr, "you should have a safety check failure below:\n"); | 126 | fprintf(stderr, "you should have a safety check failure below:\n"); |
127 | #endif | ||
128 | TEST_MAGIC_SAFETY("eina_magic_string_set", | ||
129 | "safety check failed: magic_name == NULL"); | ||
57 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | 130 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); |
131 | fail_unless(ctx.did); | ||
58 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 132 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
59 | #endif | 133 | #endif |
60 | 134 | ||
@@ -64,10 +138,22 @@ START_TEST(eina_magic_simple) | |||
64 | fail_if(strcmp(eina_magic_string_get( | 138 | fail_if(strcmp(eina_magic_string_get( |
65 | EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); | 139 | EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); |
66 | 140 | ||
141 | eina_log_print_cb_set(_eina_test_magic_print_cb, &ctx); | ||
142 | |||
67 | #ifdef EINA_MAGIC_DEBUG | 143 | #ifdef EINA_MAGIC_DEBUG |
68 | fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | 144 | fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); |
145 | #ifdef SHOW_LOG | ||
69 | fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); | 146 | fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); |
147 | #endif | ||
148 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
149 | "*** Eina Magic Check Failed !!!\n" | ||
150 | " Input handle pointer is NULL !\n" | ||
151 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
152 | "*** SPANK SPANK SPANK!!!\n" | ||
153 | "*** Now go fix your code. Tut tut tut!\n" | ||
154 | "\n"); | ||
70 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 155 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
156 | fail_unless(ctx.did); | ||
71 | 157 | ||
72 | ems = malloc(sizeof (Eina_Magic_Struct)); | 158 | ems = malloc(sizeof (Eina_Magic_Struct)); |
73 | fail_if(!ems); | 159 | fail_if(!ems); |
@@ -76,15 +162,39 @@ START_TEST(eina_magic_simple) | |||
76 | fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | 162 | fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); |
77 | 163 | ||
78 | EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); | 164 | EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); |
165 | #ifdef SHOW_LOG | ||
79 | fprintf(stderr, | 166 | fprintf(stderr, |
80 | "you should see 'Input handle has already been freed' below\n"); | 167 | "you should see 'Input handle has already been freed' below\n"); |
168 | #endif | ||
169 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
170 | "*** Eina Magic Check Failed !!!\n" | ||
171 | " Input handle has already been freed!\n" | ||
172 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
173 | "*** SPANK SPANK SPANK!!!\n" | ||
174 | "*** Now go fix your code. Tut tut tut!\n" | ||
175 | "\n"); | ||
81 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 176 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
177 | fail_unless(ctx.did); | ||
82 | 178 | ||
83 | EINA_MAGIC_SET(ems, 42424242); | 179 | EINA_MAGIC_SET(ems, 42424242); |
180 | #ifdef SHOW_LOG | ||
84 | fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); | 181 | fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); |
182 | #endif | ||
183 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
184 | "*** Eina Magic Check Failed !!!\n" | ||
185 | " Input handle is wrong type\n" | ||
186 | " Expected: %08x - %s\n" | ||
187 | " Supplied: %08x - %s\n" | ||
188 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
189 | "*** SPANK SPANK SPANK!!!\n" | ||
190 | "*** Now go fix your code. Tut tut tut!\n" | ||
191 | "\n"); | ||
85 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 192 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
193 | fail_unless(ctx.did); | ||
86 | #endif | 194 | #endif |
87 | 195 | ||
196 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
197 | |||
88 | eina_shutdown(); | 198 | eina_shutdown(); |
89 | } | 199 | } |
90 | END_TEST | 200 | 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) | |||
44 | char *buf; | 44 | char *buf; |
45 | 45 | ||
46 | fseek(f, 0, SEEK_SET); | 46 | fseek(f, 0, SEEK_SET); |
47 | buf = malloc(sz); | 47 | buf = malloc(sz + 1); |
48 | if (buf) | 48 | if (buf) |
49 | { | 49 | { |
50 | if (fread(buf, 1, sz, f)) | 50 | if (fread(buf, 1, sz, f)) |
51 | { | 51 | { |
52 | Eina_Simple_XML_Node_Root *root = eina_simple_xml_node_load | 52 | Eina_Simple_XML_Node_Root *root = eina_simple_xml_node_load |
53 | (buf, sz, EINA_TRUE); | 53 | (buf, sz, EINA_TRUE); |
54 | buf[sz] = '\0'; | ||
54 | char *out = eina_simple_xml_node_dump(&root->base, " "); | 55 | char *out = eina_simple_xml_node_dump(&root->base, " "); |
55 | puts(out); | 56 | //puts(out); |
57 | ck_assert_str_eq(out, buf); | ||
56 | free(out); | 58 | free(out); |
57 | eina_simple_xml_node_root_free(root); | 59 | eina_simple_xml_node_root_free(root); |
58 | free(buf); | 60 | 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 @@ | |||
28 | #include "eina_suite.h" | 28 | #include "eina_suite.h" |
29 | #include "Eina.h" | 29 | #include "Eina.h" |
30 | 30 | ||
31 | #ifdef EINA_SAFETY_CHECKS | ||
32 | struct log_ctx { | ||
33 | const char *msg; | ||
34 | const char *fnc; | ||
35 | Eina_Bool did; | ||
36 | }; | ||
37 | |||
38 | /* tests should not output on success, just uncomment this for debugging */ | ||
39 | //#define SHOW_LOG 1 | ||
40 | |||
41 | static void | ||
42 | _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__) | ||
43 | { | ||
44 | struct log_ctx *ctx = data; | ||
45 | va_list cp_args; | ||
46 | const char *str; | ||
47 | |||
48 | va_copy(cp_args, args); | ||
49 | str = va_arg(cp_args, const char *); | ||
50 | va_end(cp_args); | ||
51 | |||
52 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
53 | ck_assert_str_eq(fmt, "%s"); | ||
54 | ck_assert_str_eq(ctx->msg, str); | ||
55 | ck_assert_str_eq(ctx->fnc, fnc); | ||
56 | ctx->did = EINA_TRUE; | ||
57 | |||
58 | #ifdef SHOW_LOG | ||
59 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
60 | #else | ||
61 | (void)d; | ||
62 | (void)file; | ||
63 | (void)line; | ||
64 | #endif | ||
65 | } | ||
66 | #endif | ||
67 | |||
31 | static const Eina_Unicode STR1[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; | 68 | static const Eina_Unicode STR1[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; |
32 | static const Eina_Unicode STR2[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'f', 'f', 0}; | 69 | static const Eina_Unicode STR2[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'f', 'f', 0}; |
33 | static const Eina_Unicode STR3[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; | 70 | static const Eina_Unicode STR3[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0}; |
@@ -126,14 +163,42 @@ START_TEST(eina_unicode_strncpy_test) | |||
126 | rv = eina_unicode_strncpy(buf, STR1, 0); | 163 | rv = eina_unicode_strncpy(buf, STR1, 0); |
127 | fail_if(buf[0] != '7'); | 164 | fail_if(buf[0] != '7'); |
128 | 165 | ||
129 | /* may segfault */ | 166 | #ifdef EINA_SAFETY_CHECKS |
130 | buf[0] = '7'; | 167 | { |
131 | rv = eina_unicode_strncpy(buf, NULL, 0); | 168 | struct log_ctx ctx; |
132 | fail_if(buf[0] != '7'); | 169 | |
170 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
171 | ctx.msg = _msg; \ | ||
172 | ctx.fnc = fn; \ | ||
173 | ctx.did = EINA_FALSE | ||
174 | |||
175 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
133 | 176 | ||
134 | /* Hopefully won't segfault */ | 177 | /* may segfault */ |
135 | rv = eina_unicode_strncpy(NULL, STR1, 0); | 178 | buf[0] = '7'; |
136 | fail_if(rv != NULL); | 179 | #ifdef SHOW_LOG |
180 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
181 | #endif | ||
182 | TEST_MAGIC_SAFETY("eina_unicode_strncpy", | ||
183 | "safety check failed: source == NULL"); | ||
184 | rv = eina_unicode_strncpy(buf, NULL, 0); | ||
185 | fail_if(buf[0] != '7'); | ||
186 | fail_unless(ctx.did); | ||
187 | |||
188 | /* Hopefully won't segfault */ | ||
189 | #ifdef SHOW_LOG | ||
190 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
191 | #endif | ||
192 | TEST_MAGIC_SAFETY("eina_unicode_strncpy", | ||
193 | "safety check failed: dest == NULL"); | ||
194 | rv = eina_unicode_strncpy(NULL, STR1, 0); | ||
195 | fail_if(rv != NULL); | ||
196 | fail_unless(ctx.did); | ||
197 | |||
198 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
199 | #undef TEST_MAGIC_SAFETY | ||
200 | } | ||
201 | #endif | ||
137 | 202 | ||
138 | eina_shutdown(); | 203 | eina_shutdown(); |
139 | } | 204 | } |
@@ -151,8 +216,30 @@ START_TEST(eina_ustr_strlen_test) | |||
151 | fail_if(eina_unicode_strlen(STR3) != 8); | 216 | fail_if(eina_unicode_strlen(STR3) != 8); |
152 | fail_if(eina_unicode_strlen(STR4) != 1); | 217 | fail_if(eina_unicode_strlen(STR4) != 1); |
153 | fail_if(eina_unicode_strlen(EMPTYSTR) != 0); | 218 | fail_if(eina_unicode_strlen(EMPTYSTR) != 0); |
154 | /* Eina unicode doesn't take NULL */ | 219 | |
155 | // fail_if(eina_unicode_strlen(NULL)); | 220 | #ifdef EINA_SAFETY_CHECKS |
221 | { | ||
222 | struct log_ctx ctx; | ||
223 | |||
224 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
225 | ctx.msg = _msg; \ | ||
226 | ctx.fnc = fn; \ | ||
227 | ctx.did = EINA_FALSE | ||
228 | |||
229 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
230 | |||
231 | #ifdef SHOW_LOG | ||
232 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
233 | #endif | ||
234 | TEST_MAGIC_SAFETY("eina_unicode_strlen", | ||
235 | "safety check failed: ustr == NULL"); | ||
236 | fail_if(eina_unicode_strlen(NULL)); | ||
237 | fail_unless(ctx.did); | ||
238 | |||
239 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
240 | #undef TEST_MAGIC_SAFETY | ||
241 | } | ||
242 | #endif | ||
156 | 243 | ||
157 | eina_shutdown(); | 244 | eina_shutdown(); |
158 | } | 245 | } |
@@ -174,7 +261,30 @@ START_TEST(eina_unicode_strnlen_test) | |||
174 | fail_if(eina_unicode_strnlen(STR2,3) != 3); | 261 | fail_if(eina_unicode_strnlen(STR2,3) != 3); |
175 | fail_if(eina_unicode_strnlen(STR3,3) != 3); | 262 | fail_if(eina_unicode_strnlen(STR3,3) != 3); |
176 | fail_if(eina_unicode_strnlen(EMPTYSTR,1) != 0); | 263 | fail_if(eina_unicode_strnlen(EMPTYSTR,1) != 0); |
177 | fail_if(eina_unicode_strnlen(NULL,0) != 0); | 264 | |
265 | #ifdef EINA_SAFETY_CHECKS | ||
266 | { | ||
267 | struct log_ctx ctx; | ||
268 | |||
269 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
270 | ctx.msg = _msg; \ | ||
271 | ctx.fnc = fn; \ | ||
272 | ctx.did = EINA_FALSE | ||
273 | |||
274 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
275 | |||
276 | #ifdef SHOW_LOG | ||
277 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
278 | #endif | ||
279 | TEST_MAGIC_SAFETY("eina_unicode_strnlen", | ||
280 | "safety check failed: ustr == NULL"); | ||
281 | fail_if(eina_unicode_strnlen(NULL,0) != 0); | ||
282 | fail_unless(ctx.did); | ||
283 | |||
284 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
285 | #undef TEST_MAGIC_SAFETY | ||
286 | } | ||
287 | #endif | ||
178 | 288 | ||
179 | eina_shutdown(); | 289 | eina_shutdown(); |
180 | } | 290 | } |
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) | |||
1140 | fail_unless(eina_inarray_append(inarray, &c) >= 0); | 1140 | fail_unless(eina_inarray_append(inarray, &c) >= 0); |
1141 | desc.subtype = EINA_VALUE_TYPE_CHAR; | 1141 | desc.subtype = EINA_VALUE_TYPE_CHAR; |
1142 | desc.step = 0; | 1142 | desc.step = 0; |
1143 | desc.array = inarray; /* will be adopted and freed by value */ | 1143 | desc.array = inarray; |
1144 | fail_unless(eina_value_set(value, desc)); /* manually configure */ | 1144 | fail_unless(eina_value_set(value, desc)); /* manually configure */ |
1145 | eina_inarray_free(inarray); | ||
1146 | |||
1145 | fail_unless(eina_value_array_get(value, 0, &c)); | 1147 | fail_unless(eina_value_array_get(value, 0, &c)); |
1146 | fail_unless(c == 11); | 1148 | fail_unless(c == 11); |
1147 | fail_unless(eina_value_array_get(value, 1, &c)); | 1149 | fail_unless(eina_value_array_get(value, 1, &c)); |
@@ -1242,11 +1244,13 @@ START_TEST(eina_value_test_list) | |||
1242 | 1244 | ||
1243 | desc.subtype = EINA_VALUE_TYPE_STRING; | 1245 | desc.subtype = EINA_VALUE_TYPE_STRING; |
1244 | desc.list = NULL; | 1246 | desc.list = NULL; |
1245 | desc.list = eina_list_append(desc.list, strdup("hello")); | 1247 | desc.list = eina_list_append(desc.list, "hello"); |
1246 | desc.list = eina_list_append(desc.list, strdup("world")); | 1248 | desc.list = eina_list_append(desc.list, "world"); |
1247 | desc.list = eina_list_append(desc.list, strdup("eina")); | 1249 | desc.list = eina_list_append(desc.list, "eina"); |
1248 | fail_unless(eina_list_count(desc.list) == 3); | 1250 | fail_unless(eina_list_count(desc.list) == 3); |
1249 | fail_unless(eina_value_set(value, desc)); | 1251 | fail_unless(eina_value_set(value, desc)); |
1252 | eina_list_free(desc.list); | ||
1253 | |||
1250 | fail_unless(eina_value_list_get(value, 0, &s)); | 1254 | fail_unless(eina_value_list_get(value, 0, &s)); |
1251 | fail_unless(s != NULL); | 1255 | fail_unless(s != NULL); |
1252 | fail_unless(strcmp(s, "hello") == 0); | 1256 | fail_unless(strcmp(s, "hello") == 0); |
@@ -1351,14 +1355,17 @@ START_TEST(eina_value_test_hash) | |||
1351 | fail_unless(desc.hash != NULL); | 1355 | fail_unless(desc.hash != NULL); |
1352 | /* watch out hash pointer is to a size of subtype->value_size! */ | 1356 | /* watch out hash pointer is to a size of subtype->value_size! */ |
1353 | ptr = malloc(sizeof(char *)); | 1357 | ptr = malloc(sizeof(char *)); |
1354 | *ptr = strdup("there"); | 1358 | *ptr = "there"; |
1355 | fail_unless(eina_hash_add(desc.hash, "hi", ptr)); | 1359 | fail_unless(eina_hash_add(desc.hash, "hi", ptr)); |
1356 | ptr = malloc(sizeof(char *)); | 1360 | ptr = malloc(sizeof(char *)); |
1357 | *ptr = strdup("y"); | 1361 | *ptr = "y"; |
1358 | fail_unless(eina_hash_add(desc.hash, "x", ptr)); | 1362 | fail_unless(eina_hash_add(desc.hash, "x", ptr)); |
1359 | |||
1360 | fail_unless(eina_value_set(value, desc)); | 1363 | fail_unless(eina_value_set(value, desc)); |
1361 | 1364 | ||
1365 | free(eina_hash_find(desc.hash, "hi")); | ||
1366 | free(eina_hash_find(desc.hash, "x")); | ||
1367 | eina_hash_free(desc.hash); | ||
1368 | |||
1362 | fail_unless(eina_value_hash_get(value, "hi", &s)); | 1369 | fail_unless(eina_value_hash_get(value, "hi", &s)); |
1363 | fail_unless(s != NULL); | 1370 | fail_unless(s != NULL); |
1364 | fail_unless(strcmp(s, "there") == 0); | 1371 | fail_unless(strcmp(s, "there") == 0); |
@@ -1606,6 +1613,20 @@ START_TEST(eina_value_test_struct) | |||
1606 | fail_unless(eina_value_struct_get(value, "c", &c)); | 1613 | fail_unless(eina_value_struct_get(value, "c", &c)); |
1607 | fail_unless(c == 0xf); | 1614 | fail_unless(c == 0xf); |
1608 | 1615 | ||
1616 | fail_unless(eina_value_struct_member_value_get | ||
1617 | (value, myst_members + 0, &other)); | ||
1618 | fail_unless(other.type == EINA_VALUE_TYPE_INT); | ||
1619 | fail_unless(eina_value_get(&other, &i)); | ||
1620 | fail_unless(i == 5678); | ||
1621 | eina_value_flush(&other); | ||
1622 | |||
1623 | fail_unless(eina_value_struct_member_value_get | ||
1624 | (value, myst_members + 1, &other)); | ||
1625 | fail_unless(other.type == EINA_VALUE_TYPE_CHAR); | ||
1626 | fail_unless(eina_value_get(&other, &c)); | ||
1627 | fail_unless(c = 0xf); | ||
1628 | eina_value_flush(&other); | ||
1629 | |||
1609 | str = eina_value_to_string(value); | 1630 | str = eina_value_to_string(value); |
1610 | fail_unless(str != NULL); | 1631 | fail_unless(str != NULL); |
1611 | fail_unless(strcmp(str, "{i: 5678, c: 15}") == 0); | 1632 | fail_unless(strcmp(str, "{i: 5678, c: 15}") == 0); |
@@ -1704,6 +1725,7 @@ START_TEST(eina_value_test_struct) | |||
1704 | 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); | 1725 | 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); |
1705 | free(str); | 1726 | free(str); |
1706 | 1727 | ||
1728 | eina_value_flush(&other); | ||
1707 | eina_value_free(value); | 1729 | eina_value_free(value); |
1708 | eina_shutdown(); | 1730 | eina_shutdown(); |
1709 | } | 1731 | } |
@@ -1728,7 +1750,7 @@ START_TEST(eina_value_test_array_of_struct) | |||
1728 | EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH, | 1750 | EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH, |
1729 | myst_members, 4, sizeof(struct myst) | 1751 | myst_members, 4, sizeof(struct myst) |
1730 | }; | 1752 | }; |
1731 | Eina_Value *value; | 1753 | Eina_Value *value, array_item; |
1732 | char *str; | 1754 | char *str; |
1733 | int i; | 1755 | int i; |
1734 | 1756 | ||
@@ -1740,20 +1762,17 @@ START_TEST(eina_value_test_array_of_struct) | |||
1740 | for (i = 0; i < 10; i++) | 1762 | for (i = 0; i < 10; i++) |
1741 | { | 1763 | { |
1742 | Eina_Value_Struct desc; | 1764 | Eina_Value_Struct desc; |
1743 | struct myst *st; | 1765 | struct myst st; |
1744 | char buf[64]; | 1766 | char buf[64]; |
1745 | 1767 | ||
1746 | snprintf(buf, sizeof(buf), "item%02d", i); | 1768 | snprintf(buf, sizeof(buf), "item%02d", i); |
1747 | st = malloc(sizeof(struct myst)); | 1769 | st.a = i; |
1748 | fail_unless(st != NULL); | 1770 | st.b = i * 10; |
1749 | st->a = i; | 1771 | st.c = i * 100; |
1750 | st->b = i * 10; | 1772 | st.s = buf; |
1751 | st->c = i * 100; | ||
1752 | st->s = strdup(buf); | ||
1753 | fail_unless(st->s != NULL); | ||
1754 | 1773 | ||
1755 | desc.desc = &myst_desc; | 1774 | desc.desc = &myst_desc; |
1756 | desc.memory = st; | 1775 | desc.memory = &st; |
1757 | fail_unless(eina_value_array_append(value, desc)); | 1776 | fail_unless(eina_value_array_append(value, desc)); |
1758 | } | 1777 | } |
1759 | 1778 | ||
@@ -1773,11 +1792,66 @@ START_TEST(eina_value_test_array_of_struct) | |||
1773 | "]") == 0); | 1792 | "]") == 0); |
1774 | free(str); | 1793 | free(str); |
1775 | 1794 | ||
1795 | eina_value_array_value_get(value, 2, &array_item); | ||
1796 | eina_value_struct_get(&array_item, "a", &i); | ||
1797 | ck_assert_int_eq(i, 2); | ||
1798 | eina_value_struct_get(&array_item, "b", &i); | ||
1799 | ck_assert_int_eq(i, 20); | ||
1800 | eina_value_struct_get(&array_item, "c", &i); | ||
1801 | ck_assert_int_eq(i, 200); | ||
1802 | eina_value_struct_get(&array_item, "s", &str); | ||
1803 | ck_assert_str_eq(str, "item02"); | ||
1804 | eina_value_flush(&array_item); | ||
1805 | |||
1776 | eina_value_free(value); | 1806 | eina_value_free(value); |
1777 | eina_shutdown(); | 1807 | eina_shutdown(); |
1778 | } | 1808 | } |
1779 | END_TEST | 1809 | END_TEST |
1780 | 1810 | ||
1811 | |||
1812 | START_TEST(eina_value_test_model) | ||
1813 | { | ||
1814 | Eina_Value *value, inv; | ||
1815 | Eina_Model *model, *m; | ||
1816 | char *str; | ||
1817 | |||
1818 | eina_init(); | ||
1819 | |||
1820 | value = eina_value_new(EINA_VALUE_TYPE_MODEL); | ||
1821 | fail_unless(value != NULL); | ||
1822 | |||
1823 | model = eina_model_new(EINA_MODEL_TYPE_GENERIC); | ||
1824 | fail_unless(model != NULL); | ||
1825 | |||
1826 | fail_unless(eina_value_setup(&inv, EINA_VALUE_TYPE_INT)); | ||
1827 | fail_unless(eina_value_set(&inv, 1234)); | ||
1828 | fail_unless(eina_model_property_set(model, "i", &inv)); | ||
1829 | eina_value_flush(&inv); | ||
1830 | |||
1831 | fail_unless(eina_value_set(value, model)); | ||
1832 | fail_unless(eina_model_refcount(model) == 2); | ||
1833 | |||
1834 | fail_unless(eina_value_get(value, &m)); | ||
1835 | fail_unless(m == model); | ||
1836 | fail_unless(eina_model_refcount(m) == 2); | ||
1837 | |||
1838 | fail_unless(eina_value_pset(value, &model)); | ||
1839 | fail_unless(eina_model_refcount(model) == 2); | ||
1840 | |||
1841 | str = eina_value_to_string(value); | ||
1842 | fail_unless(str != NULL); | ||
1843 | fail_unless(strcmp(str, "Eina_Model_Type_Generic({i: 1234}, [])") == 0); | ||
1844 | free(str); | ||
1845 | |||
1846 | eina_value_free(value); | ||
1847 | |||
1848 | fail_unless(eina_model_refcount(model) == 1); | ||
1849 | eina_model_unref(model); | ||
1850 | |||
1851 | eina_shutdown(); | ||
1852 | } | ||
1853 | END_TEST | ||
1854 | |||
1781 | void | 1855 | void |
1782 | eina_test_value(TCase *tc) | 1856 | eina_test_value(TCase *tc) |
1783 | { | 1857 | { |
@@ -1796,4 +1870,5 @@ eina_test_value(TCase *tc) | |||
1796 | tcase_add_test(tc, eina_value_test_blob); | 1870 | tcase_add_test(tc, eina_value_test_blob); |
1797 | tcase_add_test(tc, eina_value_test_struct); | 1871 | tcase_add_test(tc, eina_value_test_struct); |
1798 | tcase_add_test(tc, eina_value_test_array_of_struct); | 1872 | tcase_add_test(tc, eina_value_test_array_of_struct); |
1873 | tcase_add_test(tc, eina_value_test_model); | ||
1799 | } | 1874 | } |