diff --git a/src/Makefile_Ecore_Cxx.am b/src/Makefile_Ecore_Cxx.am index c0ec604d7d..ef97d5f424 100644 --- a/src/Makefile_Ecore_Cxx.am +++ b/src/Makefile_Ecore_Cxx.am @@ -34,7 +34,8 @@ TESTS += tests/ecore_cxx/ecore_cxx_suite tests/ecore_cxx/cxx_compile_test tests_ecore_cxx_ecore_cxx_suite_SOURCES = \ tests/ecore_cxx/ecore_cxx_suite.cc \ -tests/ecore_cxx/ecore_cxx_test_safe_call.cc +tests/ecore_cxx/ecore_cxx_test_safe_call.cc \ +tests/ecore_cxx/ecore_cxx_suite.h tests_ecore_cxx_ecore_cxx_suite_CPPFLAGS = \ -I$(top_builddir)/src/lib/efl \ diff --git a/src/Makefile_Eet.am b/src/Makefile_Eet.am index 1701e7b85d..d2efc9a8f1 100644 --- a/src/Makefile_Eet.am +++ b/src/Makefile_Eet.am @@ -62,8 +62,17 @@ check_PROGRAMS += tests/eet/eet_suite TESTS += tests/eet/eet_suite tests_eet_eet_suite_SOURCES = \ +tests/eet/eet_test_cache.c \ +tests/eet/eet_test_cipher.c \ +tests/eet/eet_test_common.c \ +tests/eet/eet_test_connection.c \ +tests/eet/eet_test_data.c \ +tests/eet/eet_test_file.c \ +tests/eet/eet_test_identity.c \ +tests/eet/eet_test_image.c \ +tests/eet/eet_test_init.c \ tests/eet/eet_suite.c \ -tests/eet/eet_data_suite.c \ +tests/eet/eet_test_common.h \ tests/eet/eet_suite.h tests_eet_eet_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ diff --git a/src/Makefile_Eet_Cxx.am b/src/Makefile_Eet_Cxx.am index b09223a2d5..681e7bd5cd 100644 --- a/src/Makefile_Eet_Cxx.am +++ b/src/Makefile_Eet_Cxx.am @@ -19,7 +19,8 @@ TESTS += tests/eet_cxx/eet_cxx_suite tests_eet_cxx_eet_cxx_suite_SOURCES = \ tests/eet_cxx/eet_cxx_suite.cc \ -tests/eet_cxx/eet_cxx_test_descriptors.cc +tests/eet_cxx/eet_cxx_test_descriptors.cc \ +tests/eet_cxx/eet_cxx_suite.h tests_eet_cxx_eet_cxx_suite_CPPFLAGS = \ -I$(top_builddir)/src/lib/efl \ diff --git a/src/Makefile_Eeze.am b/src/Makefile_Eeze.am index 31b0cfb5b5..0852d8737b 100644 --- a/src/Makefile_Eeze.am +++ b/src/Makefile_Eeze.am @@ -162,7 +162,13 @@ if EFL_ENABLE_TESTS check_PROGRAMS += tests/eeze/eeze_suite TESTS += tests/eeze/eeze_suite -tests_eeze_eeze_suite_SOURCES = tests/eeze/eeze_suite.c +tests_eeze_eeze_suite_SOURCES = \ +tests/eeze/eeze_suite.c \ +tests/eeze/eeze_test_init.c \ +tests/eeze/eeze_test_net.c \ +tests/eeze/eeze_test_sensor.c \ +tests/eeze/eeze_test_udev.c \ +tests/eeze/eeze_suite.h tests_eeze_eeze_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ @EEZE_CFLAGS@ \ -DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eeze\" \ diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am index a0c4739865..71d0330b68 100644 --- a/src/Makefile_Eina.am +++ b/src/Makefile_Eina.am @@ -273,6 +273,7 @@ check_PROGRAMS += tests/eina/eina_suite tests/eina/cxx_compile_test TESTS += tests/eina/eina_suite tests_eina_eina_suite_SOURCES = \ +tests/efl_check.h \ tests/eina/eina_suite.c \ tests/eina/eina_suite.h \ tests/eina/eina_test_abi.c \ diff --git a/src/Makefile_Eina_Cxx.am b/src/Makefile_Eina_Cxx.am index 6f1d0ab31d..ea5f937198 100644 --- a/src/Makefile_Eina_Cxx.am +++ b/src/Makefile_Eina_Cxx.am @@ -60,7 +60,8 @@ tests/eina_cxx/eina_cxx_test_accessor.cc \ tests/eina_cxx/eina_cxx_test_thread.cc \ tests/eina_cxx/eina_cxx_test_optional.cc \ tests/eina_cxx/eina_cxx_test_value.cc \ -tests/eina_cxx/simple.c +tests/eina_cxx/simple.c \ +tests/eina_cxx/eina_cxx_suite.h tests/eina_cxx/tests_eina_cxx_eina_cxx_suite-eina_cxx_test_accessor.$(OBJEXT): tests/eina_cxx/simple.eo.hh tests/eina_cxx/simple.eo.h tests/eina_cxx/tests_eina_cxx_eina_cxx_suite-eina_cxx_test_ptrarray.$(OBJEXT): tests/eina_cxx/simple.eo.hh tests/eina_cxx/simple.eo.h diff --git a/src/Makefile_Eldbus_Cxx.am b/src/Makefile_Eldbus_Cxx.am index d265b2c3f9..8f9b2cde64 100644 --- a/src/Makefile_Eldbus_Cxx.am +++ b/src/Makefile_Eldbus_Cxx.am @@ -48,7 +48,8 @@ TESTS += tests/eldbus_cxx/eldbus_cxx_suite tests_eldbus_cxx_eldbus_cxx_suite_SOURCES = \ tests/eldbus_cxx/eldbus_cxx_suite.cc \ tests/eldbus_cxx/eldbus_cxx_test_eldbus_connect.cc \ -tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc +tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc \ +tests/eldbus_cxx/eldbus_cxx_suite.h tests_eldbus_cxx_eldbus_cxx_suite_CPPFLAGS = \ -I$(top_builddir)/src/bindings/eina_cxx \ diff --git a/src/Makefile_Emile.am b/src/Makefile_Emile.am index c02df7a7f6..67d2f6ce52 100644 --- a/src/Makefile_Emile.am +++ b/src/Makefile_Emile.am @@ -81,7 +81,10 @@ check_PROGRAMS += tests/emile/emile_suite TESTS += tests/emile/emile_suite tests_emile_emile_suite_SOURCES = \ -tests/emile/emile_suite.c +tests/emile/emile_suite.c \ +tests/emile/emile_test_base.c \ +tests/emile/emile_test_base64.c \ +tests/emile/emile_suite.h tests_emile_emile_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ -DTESTS_WD=\"`pwd`\" \ diff --git a/src/Makefile_Eolian_Cxx.am b/src/Makefile_Eolian_Cxx.am index b310bbe479..89111c1681 100644 --- a/src/Makefile_Eolian_Cxx.am +++ b/src/Makefile_Eolian_Cxx.am @@ -74,7 +74,8 @@ tests/eolian_cxx/eolian_cxx_test_wrapper.cc \ tests/eolian_cxx/simple.c \ tests/eolian_cxx/generic.c \ tests/eolian_cxx/eolian_cxx_test_inheritance.cc \ -tests/eolian_cxx/eolian_cxx_test_generate.cc +tests/eolian_cxx/eolian_cxx_test_generate.cc \ +tests/eolian_cxx/eolian_cxx_suite.h tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_wrapper.$(OBJEXT): tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.h tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.h diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c index ce75f00328..787a455d74 100644 --- a/src/tests/ecore/ecore_suite.c +++ b/src/tests/ecore/ecore_suite.c @@ -2,22 +2,10 @@ # include #endif -#include -#include - -#include - #include "ecore_suite.h" +#include "../efl_check.h" -typedef struct _Ecore_Test_Case Ecore_Test_Case; - -struct _Ecore_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Ecore_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Ecore", ecore_test_ecore }, #if HAVE_ECORE_X { "Ecore_X", ecore_test_ecore_x }, @@ -41,84 +29,18 @@ static const Ecore_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Ecore_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -ecore_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Ecore"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); - tcase_set_timeout(tc, 0); - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = ecore_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Ecore", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c index ed7f4ee886..98c7192a74 100644 --- a/src/tests/ecore/ecore_test_animator.c +++ b/src/tests/ecore/ecore_test_animator.c @@ -2,10 +2,11 @@ #include #endif +#include + #include #include "ecore_suite.h" -#include static double prev = 0; static Eina_Bool _anim_cb(void *data EINA_UNUSED, double pos) diff --git a/src/tests/ecore/ecore_test_ecore_audio.c b/src/tests/ecore/ecore_test_ecore_audio.c index 4be231c39c..5bceee28ae 100644 --- a/src/tests/ecore/ecore_test_ecore_audio.c +++ b/src/tests/ecore/ecore_test_ecore_audio.c @@ -2,17 +2,15 @@ #include #endif +#include #include +#include #include #include #include "ecore_suite.h" -#include -#include -#include - static Eina_Bool _failed_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { Eina_Bool *pulse_context_failed = data; diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c index 91003621c2..cb3928a580 100644 --- a/src/tests/ecore/ecore_test_ecore_file.c +++ b/src/tests/ecore/ecore_test_ecore_file.c @@ -9,9 +9,9 @@ #include #include -#include -#include #include +#include +#include #include "ecore_suite.h" diff --git a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c index d5bdc27f8f..fe5e32a44b 100644 --- a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c +++ b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c @@ -2,10 +2,11 @@ # include #endif -#include -#include -#include #include +#include + +#include +#include #include "ecore_suite.h" diff --git a/src/tests/ecore/ecore_test_ecore_x.c b/src/tests/ecore/ecore_test_ecore_x.c index 8baa9a560f..bb33374550 100644 --- a/src/tests/ecore/ecore_test_ecore_x.c +++ b/src/tests/ecore/ecore_test_ecore_x.c @@ -2,10 +2,10 @@ # include #endif -#include "ecore_suite.h" - #include +#include "ecore_suite.h" + /* FIXME: Currently disable these tests. They are useless ATM and they just * make buildbot complain. Once we add useful tests here we'll also bother * with getting X on the server. */ diff --git a/src/tests/ecore_con/ecore_con_suite.c b/src/tests/ecore_con/ecore_con_suite.c index 331f66091c..a3ef616064 100644 --- a/src/tests/ecore_con/ecore_con_suite.c +++ b/src/tests/ecore_con/ecore_con_suite.c @@ -2,106 +2,28 @@ # include #endif -#include -#include - -#include "Ecore.h" - #include "ecore_con_suite.h" +#include "../efl_check.h" -typedef struct _Ecore_Con_Test_Case Ecore_Con_Test_Case; - -struct _Ecore_Con_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Ecore_Con_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Ecore_Con", ecore_con_test_ecore_con }, { "Ecore_Con_Url", ecore_con_test_ecore_con_url }, { "Ecore_Con_Eet", ecore_con_test_ecore_con_eet }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Ecore_Con_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -ecore_con_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Ecore_Con"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); - tcase_set_timeout(tc, 0); - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = ecore_con_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Ecore_Con", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con.c b/src/tests/ecore_con/ecore_con_test_ecore_con.c index d7f03e6485..33dda2f3ba 100644 --- a/src/tests/ecore_con/ecore_con_test_ecore_con.c +++ b/src/tests/ecore_con/ecore_con_test_ecore_con.c @@ -2,12 +2,13 @@ # include #endif -#include "ecore_con_suite.h" - #include + #include #include +#include "ecore_con_suite.h" + char sdata[] = "Server_info"; char cdata[] = "Client_info"; diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c b/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c index e6eca4daf8..c8801bbd14 100644 --- a/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c +++ b/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c @@ -2,11 +2,11 @@ # include #endif -#include "ecore_con_suite.h" - #include #include +#include "ecore_con_suite.h" + #define TEST_STREAM "test_stream" #define SRV_MSG "Server Message" #define CLI_MSG "Client Message" diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c index 38fb234f27..0c1a6028a6 100644 --- a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c +++ b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c @@ -2,13 +2,14 @@ # include #endif -#include "ecore_con_suite.h" - #include +#include + +#include #include #include -#include -#include + +#include "ecore_con_suite.h" #define COOKIEJAR "testcookieXXXXXX.jar" #define DEFAULT_LINK "www.google.com" diff --git a/src/tests/ecore_cxx/ecore_cxx_suite.cc b/src/tests/ecore_cxx/ecore_cxx_suite.cc index 4d2e721d43..33ed9b6fe6 100644 --- a/src/tests/ecore_cxx/ecore_cxx_suite.cc +++ b/src/tests/ecore_cxx/ecore_cxx_suite.cc @@ -2,107 +2,26 @@ # include #endif -#include "Ecore.hh" +#include "ecore_cxx_suite.h" +#include "../efl_check.h" -#include -#include - -#include - -void ecore_test_safe_call(TCase* tc); - -typedef struct _Ecore_Test_Case Ecore_Test_Case; -struct _Ecore_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Ecore_Test_Case etc[] = { - { "Safe_Call", ecore_test_safe_call }, +static const Efl_Test_Case etc[] = { + { "Safe_Call", ecore_cxx_test_safe_call }, { NULL, NULL } }; -static void -_list_tests(void) +int +main(int argc, char* argv[]) { - const Ecore_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} + int failed_count; -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -ecore_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Ecore"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - -int main(int argc, char* argv[]) -{ - Suite *s; - SRunner *sr; - int i, failed_count; - - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv(const_cast("EFL_RUN_IN_TREE=1")); - s = ecore_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Ecore C++", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/ecore_cxx/ecore_cxx_suite.h b/src/tests/ecore_cxx/ecore_cxx_suite.h new file mode 100644 index 0000000000..34343317fc --- /dev/null +++ b/src/tests/ecore_cxx/ecore_cxx_suite.h @@ -0,0 +1,11 @@ +#ifndef _ECORE_CXX_SUITE_H +#define _ECORE_CXX_SUITE_H + +#include +#include + +#include + +void ecore_cxx_test_safe_call(TCase* tc); + +#endif /* _ECORE_CXX_SUITE_H */ diff --git a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc index 1425041e55..72020873c5 100644 --- a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc +++ b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc @@ -2,14 +2,13 @@ # include #endif -#include "Ecore.hh" -#include "Eina.hh" - #include - #include -#include +#include +#include + +#include "ecore_cxx_suite.h" void call_async(efl::eina::mutex& mutex, efl::eina::condition_variable& cond, int& done) { @@ -260,7 +259,7 @@ START_TEST(ecore_cxx_safe_call_sync) END_TEST void -ecore_test_safe_call(TCase* tc) +ecore_cxx_test_safe_call(TCase* tc) { tcase_add_test(tc, ecore_cxx_safe_call_async); tcase_add_test(tc, ecore_cxx_safe_call_sync); diff --git a/src/tests/ector/ector_suite.c b/src/tests/ector/ector_suite.c index fbae22c4a0..fa491df6ec 100644 --- a/src/tests/ector/ector_suite.c +++ b/src/tests/ector/ector_suite.c @@ -18,96 +18,28 @@ #ifdef HAVE_CONFIG_H # include -#endif /* ifdef HAVE_CONFIG_H */ - -#include -#include - -#include - -#include "Eina.h" +#endif #include "ector_suite.h" +#include "../efl_check.h" -typedef struct _Ector_Test_Case Ector_Test_Case; -struct _Ector_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Ector_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "init", ector_test_init }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Ector_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - int main(int argc, char *argv[]) { - TCase *tc; - Suite *s; - SRunner *sr; - int failed_count, i; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = suite_create("Ector"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc - 1, (const char **) argv + 1, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); - tcase_set_timeout(tc, 0); - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - sr = srunner_create(s); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Ector", etc); return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/src/tests/ector/ector_test_init.c b/src/tests/ector/ector_test_init.c index 1c36e4012d..5194cbd52c 100644 --- a/src/tests/ector/ector_test_init.c +++ b/src/tests/ector/ector_test_init.c @@ -20,9 +20,9 @@ # include "config.h" #endif -#include "ector_suite.h" +#include -#include "Ector.h" +#include "ector_suite.h" START_TEST(ector_init_simple) { diff --git a/src/tests/edje/edje_suite.c b/src/tests/edje/edje_suite.c index 9284dbf319..416a0ec3f8 100644 --- a/src/tests/edje/edje_suite.c +++ b/src/tests/edje/edje_suite.c @@ -2,106 +2,26 @@ # include #endif -#include -#include - -#include - #include "edje_suite.h" +#include "../efl_check.h" -typedef struct _Edje_Test_Case Edje_Test_Case; - -struct _Edje_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Edje_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Edje", edje_test_edje }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Edje_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -edje_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Edje"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = edje_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Edje", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/edje/edje_test_edje.c b/src/tests/edje/edje_test_edje.c index 407ff9af30..8d5f725e64 100644 --- a/src/tests/edje/edje_test_edje.c +++ b/src/tests/edje/edje_test_edje.c @@ -363,7 +363,7 @@ START_TEST(edje_test_color_class) END_TEST void edje_test_edje(TCase *tc) -{ +{ tcase_add_test(tc, edje_test_edje_init); tcase_add_test(tc,edje_test_load_simple_layout); tcase_add_test(tc, edje_test_edje_load); diff --git a/src/tests/eet/eet_data_suite.c b/src/tests/eet/eet_data_suite.c deleted file mode 100644 index c4d5e5096b..0000000000 --- a/src/tests/eet/eet_data_suite.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - -#include - -#include "eet_suite.h" - -static char * -_eet_str_direct_alloc(const char *str) -{ - return (char *)str; -} /* _eet_str_direct_alloc */ - -static void -_eet_str_direct_free(const char *str) -{ - /* FIXME: Use attribute unused */ - (void)str; -} /* _eet_str_direct_free */ - -static void -_eet_eina_hash_foreach(void *hash, - Eina_Hash_Foreach cb, - void *fdata) -{ - if (hash) - eina_hash_foreach(hash, cb, fdata); -} /* _eet_eina_hash_foreach */ - -/* Internal wrapper for eina_hash */ -static Eina_Hash * -_eet_eina_hash_add(Eina_Hash *hash, - const char *key, - const void *data) -{ - if (!hash) - hash = eina_hash_string_superfast_new(NULL); - - if (!hash) - return NULL; - - eina_hash_add(hash, key, data); - return hash; -} /* _eet_eina_hash_add */ - -static void -_eet_eina_hash_free(Eina_Hash *hash) -{ - if (hash) - eina_hash_free(hash); -} /* _eet_eina_hash_free */ - -void -eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc) -{ - eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION; - eddc->func.mem_alloc = NULL; - eddc->func.mem_free = NULL; - eddc->func.str_alloc = NULL; - eddc->func.str_free = NULL; - eddc->func.list_next = (void *)eina_list_next; - eddc->func.list_append = (void *)eina_list_append; - eddc->func.list_data = (void *)eina_list_data_get; - eddc->func.list_free = (void *)eina_list_free; - eddc->func.hash_foreach = (void *)_eet_eina_hash_foreach; - eddc->func.hash_add = (void *)_eet_eina_hash_add; - eddc->func.hash_free = (void *)_eet_eina_hash_free; - eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc; - eddc->func.str_direct_free = (void *)_eet_str_direct_free; - eddc->func.array_alloc = NULL; - eddc->func.array_free = NULL; -} /* eet_test_setup_eddc */ - diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c index e7737a7f1c..3d8bb2d31c 100644 --- a/src/tests/eet/eet_suite.c +++ b/src/tests/eet/eet_suite.c @@ -1,2899 +1,44 @@ #ifdef HAVE_CONFIG_H # include -#endif /* ifdef HAVE_CONFIG_H */ - -#include -#include -#include -#include -#include -#include -#include -#include +#endif #include -#include - #include "eet_suite.h" +#include "../efl_check.h" -#ifndef O_BINARY -# define O_BINARY 0 -#endif - -static char _key_pem[PATH_MAX] = ""; -static char _cert_pem[PATH_MAX] = ""; -static char _key_enc[PATH_MAX] = ""; -static char _key_enc_pem[PATH_MAX] = ""; -static char _key_enc_none_pem[PATH_MAX] = ""; - -START_TEST(eet_test_init) -{ - int ret; - - ret = eet_init(); - fail_if(ret != 1); - - ret = eet_shutdown(); - fail_if(ret != 0); -} -END_TEST - -typedef struct _Eet_Test_Basic_Type Eet_Test_Basic_Type; -struct _Eet_Test_Basic_Type -{ - char c; - short s; - int i; - long long l; - char *str; - char *istr; - float f1; - float f2; - double d; - unsigned char uc; - unsigned short us; - unsigned int ui; - unsigned long long ul; - Eina_Value *vp; - Eet_Test_Basic_Type *empty; - Eet_Test_Basic_Type *with; -}; - -#define EET_TEST_CHAR 0x42 -#define EET_TEST_SHORT 0x4224 -#define EET_TEST_INT 0x42211224 -#define EET_TEST_LONG_LONG 0x84CB42211224BC48 -#define EET_TEST_STRING "my little test with escape \\\"" -#define EET_TEST_KEY1 "key1" -#define EET_TEST_KEY2 "key2" -#define EET_TEST_FLOAT 123.45689 -#define EET_TEST_FLOAT2 1.0 -#define EET_TEST_FLOAT3 0.25 -#define EET_TEST_FLOAT4 0.0001234 -#define EET_TEST_DOUBLE 123456789.9876543210 -#define EET_TEST_DOUBLE2 1.0 -#define EET_TEST_DOUBLE3 0.25 -#define EET_TEST_FILE_KEY1 "keys/data/1" -#define EET_TEST_FILE_KEY2 "keys/data/2" -#define EET_TEST_FILE_IMAGE "keys/images/" - -typedef struct _Eet_Test_Image Eet_Test_Image; -struct _Eet_Test_Image -{ - unsigned int w; - unsigned int h; - int alpha; - unsigned int color[64]; -}; - -static const Eet_Test_Image test_noalpha = { - 8, 8, 0, - { - 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, - 0x000000AA, 0x00110000, - 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, - 0x00110000, 0x00AA0000, - 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, - 0x00AA0000, 0x0000AA00, - 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, - 0x0000AA00, 0x000000AA, - 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, - 0x000000AA, 0x00110000, - 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, - 0x00110000, 0x00AA0000, - 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, - 0x00AA0000, 0x0000AA00, - 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, - 0x0000AA00, 0x000000AA - } -}; - -static const Eet_Test_Image test_alpha = { - 8, 8, 1, - { - 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, - 0x000000AA, 0x0F110000, - 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, - 0x0F110000, 0x00AA0000, - 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x0F110000, - 0x00AA0000, 0x0000AA00, - 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x0F110000, 0x00AA0000, - 0x0000AA00, 0x000000AA, - 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x0FAA0000, 0x0000AA00, - 0x000000AA, 0x00110000, - 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, - 0x00110000, 0x00AA0000, - 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, - 0x0FAA0000, 0x0000AA00, - 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, - 0x0000AA00, 0x0F0000AA - } -}; - -static void -_eet_test_basic_set(Eet_Test_Basic_Type *res, - int i) -{ - res->c = EET_TEST_CHAR; - res->s = EET_TEST_SHORT; - res->i = EET_TEST_INT + i; - res->l = EET_TEST_LONG_LONG; - res->str = EET_TEST_STRING; - res->istr = EET_TEST_STRING; - res->f1 = -EET_TEST_FLOAT; - res->d = -EET_TEST_DOUBLE; - res->f2 = EET_TEST_FLOAT4; - res->uc = EET_TEST_CHAR; - res->us = EET_TEST_SHORT; - res->ui = EET_TEST_INT; - res->ul = EET_TEST_LONG_LONG; - res->empty = NULL; - res->with = NULL; - res->vp = eina_value_new(EINA_VALUE_TYPE_INT); - eina_value_set(res->vp, EET_TEST_INT + i); - - if (i == 0) - { - Eet_Test_Basic_Type *tmp; - - tmp = malloc(sizeof (Eet_Test_Basic_Type)); - fail_if(!tmp); - - res->with = tmp; - tmp->c = EET_TEST_CHAR; - tmp->s = EET_TEST_SHORT; - tmp->i = EET_TEST_INT + i + 1; - tmp->l = EET_TEST_LONG_LONG; - tmp->str = EET_TEST_STRING; - tmp->istr = EET_TEST_STRING; - tmp->f1 = -EET_TEST_FLOAT; - tmp->d = -EET_TEST_DOUBLE; - tmp->f2 = EET_TEST_FLOAT4; - tmp->uc = EET_TEST_CHAR; - tmp->us = EET_TEST_SHORT; - tmp->ui = EET_TEST_INT; - tmp->ul = EET_TEST_LONG_LONG; - tmp->empty = NULL; - tmp->with = NULL; - tmp->vp = NULL; - } -} /* _eet_test_basic_set */ - -static void -_eet_test_basic_check(Eet_Test_Basic_Type *result, - int i, - Eina_Bool dumper) -{ - int test = -1; - float tmp; - - fail_if(result->c != EET_TEST_CHAR); - fail_if(result->s != EET_TEST_SHORT); - fail_if(result->i != EET_TEST_INT + i); - fail_if(result->l != (long long)EET_TEST_LONG_LONG); - fail_if(strcmp(result->str, EET_TEST_STRING) != 0); - fail_if(strcmp(result->istr, EET_TEST_STRING) != 0); - fail_if(result->uc != EET_TEST_CHAR); - fail_if(result->us != EET_TEST_SHORT); - fail_if(result->ui != EET_TEST_INT); - fail_if(result->ul != EET_TEST_LONG_LONG); - if (!dumper) - { - fail_if(result->vp == NULL); - eina_value_get(result->vp, &test); - fail_if(test != EET_TEST_INT + i); - } - else - { - fail_if(result->vp != NULL); - } - - tmp = (result->f1 + EET_TEST_FLOAT); - if (tmp < 0) - tmp = -tmp; - - fail_if(tmp > 0.005); - - tmp = (result->f2 - EET_TEST_FLOAT4); - if (tmp < 0) - tmp = -tmp; - - fail_if(tmp > 0.005); - - tmp = (result->d + EET_TEST_DOUBLE); - if (tmp < 0) - tmp = -tmp; - - fail_if(tmp > 0.00005); - - fail_if(result->empty != NULL); - if (i == 0) - { - Eet_Test_Basic_Type *tmp2; - - tmp2 = result->with; - fail_if(tmp2 == NULL); - - fail_if(tmp2->c != EET_TEST_CHAR); - fail_if(tmp2->s != EET_TEST_SHORT); - fail_if(tmp2->i != EET_TEST_INT + i + 1); - fail_if(tmp2->l != (long long)EET_TEST_LONG_LONG); - fail_if(strcmp(tmp2->str, EET_TEST_STRING) != 0); - fail_if(strcmp(tmp2->istr, EET_TEST_STRING) != 0); - fail_if(tmp2->uc != EET_TEST_CHAR); - fail_if(tmp2->us != EET_TEST_SHORT); - fail_if(tmp2->ui != EET_TEST_INT); - fail_if(tmp2->ul != EET_TEST_LONG_LONG); - fail_if(tmp2->vp != NULL); - } - else - fail_if(result->with != NULL); -} /* _eet_test_basic_check */ - -static void -_eet_build_basic_descriptor(Eet_Data_Descriptor *edd) -{ - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "c", - c, - EET_T_CHAR); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "s", - s, - EET_T_SHORT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "i", - i, - EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "l", - l, - EET_T_LONG_LONG); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "str", - str, - EET_T_STRING); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "istr", - istr, - EET_T_INLINED_STRING); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "f1", - f1, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "f2", - f2, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "d", - d, - EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "uc", - uc, - EET_T_UCHAR); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "us", - us, - EET_T_USHORT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "ui", - ui, - EET_T_UINT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "ul", - ul, - EET_T_ULONG_LONG); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Basic_Type, - "vp", - vp, - EET_T_VALUE); - - EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "empty", empty, edd); - EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "with", with, edd); -} /* _eet_build_basic_descriptor */ - -START_TEST(eet_test_basic_data_type_encoding_decoding) -{ - Eet_Data_Descriptor *edd; - Eet_Test_Basic_Type *result; - Eet_Data_Descriptor_Class eddc; - Eet_Test_Basic_Type etbt; - void *transfert; - int size; - - eet_init(); - - _eet_test_basic_set(&etbt, 0); - - eet_test_setup_eddc(&eddc); - eddc.name = "Eet_Test_Basic_Type"; - eddc.size = sizeof(Eet_Test_Basic_Type); - - edd = eet_data_descriptor_stream_new(&eddc); - fail_if(!edd); - - _eet_build_basic_descriptor(edd); - - transfert = eet_data_descriptor_encode(edd, &etbt, &size); - fail_if(!transfert || size <= 0); - - result = eet_data_descriptor_decode(edd, transfert, size); - fail_if(!result); - - _eet_test_basic_check(result, 0, EINA_FALSE); - - free(result->str); - free(result); - - eet_data_descriptor_free(edd); - - eet_shutdown(); -} -END_TEST - -typedef struct _Eet_Test_Ex_Type Eet_Test_Ex_Type; -struct _Eet_Test_Ex_Type -{ - char c; - short s; - int i; - unsigned long long l; - char *str; - char *istr; - float f1; - float f2; - float f3; - float f4; - double d1; - double d2; - double d3; - double d4; - Eina_List *list; - Eina_Hash *hash; - Eina_List *ilist; - Eina_List *slist; - Eina_Hash *ihash; - Eina_Hash *shash; - Eet_Test_Basic_Type sarray1[10]; - unsigned int sarray2[5]; - unsigned int varray1_count; - unsigned int *varray1; - unsigned int varray2_count; - Eet_Test_Basic_Type *varray2; - unsigned char uc; - unsigned short us; - unsigned int ui; - unsigned long long ul; - char *charray[10]; -}; - -static int i42 = 42; -static int i7 = 7; - -static void -_eet_build_ex_descriptor(Eet_Data_Descriptor *edd, Eina_Bool stream) -{ - Eet_Data_Descriptor_Class eddc; - Eet_Test_Ex_Type etbt; - Eet_Data_Descriptor *eddb; - - if (stream) - { - eet_eina_stream_data_descriptor_class_set(&eddc, - sizeof (Eet_Data_Descriptor_Class), - "Eet_Test_Basic_Type", - sizeof(Eet_Test_Basic_Type)); - eddb = eet_data_descriptor_stream_new(&eddc); - } - else - { - eet_eina_file_data_descriptor_class_set(&eddc, - sizeof (Eet_Data_Descriptor_Class), - "Eet_Test_Basic_Type", - sizeof(Eet_Test_Basic_Type)); - eddb = eet_data_descriptor_file_new(&eddc); - } - fail_if(!eddb); - - _eet_build_basic_descriptor(eddb); - - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "c", - c, - EET_T_CHAR); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "s", - s, - EET_T_SHORT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "i", i, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "l", - l, - EET_T_LONG_LONG); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "str", - str, - EET_T_STRING); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "istr", - istr, - EET_T_INLINED_STRING); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "f1", - f1, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "f2", - f2, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "f3", - f3, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "f4", - f4, - EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "d1", - d1, - EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "d2", - d2, - EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "d3", - d3, - EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "d4", - d4, - EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "uc", - uc, - EET_T_UCHAR); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "us", - us, - EET_T_USHORT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "ui", - ui, - EET_T_UINT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd, - Eet_Test_Ex_Type, - "ul", - ul, - EET_T_ULONG_LONG); - EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, - Eet_Test_Ex_Type, - "sarray1", - sarray1, - eddb); - EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, - Eet_Test_Ex_Type, - "varray2", - varray2, - eddb); - eet_data_descriptor_element_add(edd, - "varray1", - EET_T_INT, - EET_G_VAR_ARRAY, - (char *)(&(etbt.varray1)) - (char *)(&(etbt)), - (char *)(&(etbt.varray1_count)) - - (char *)(&(etbt)), - /* 0, */ NULL, - NULL); - eet_data_descriptor_element_add(edd, "sarray2", EET_T_INT, EET_G_ARRAY, - (char *)(&(etbt.sarray2)) - (char *)(&(etbt)), - /* 0, */ sizeof(etbt.sarray2) / - sizeof(etbt.sarray2[0]), NULL, NULL); - eet_data_descriptor_element_add(edd, "charray", EET_T_STRING, EET_G_ARRAY, - (char *)(&(etbt.charray)) - (char *)(&(etbt)), - /* 0, */ sizeof(etbt.charray) / - sizeof(etbt.charray[0]), NULL, NULL); - EET_DATA_DESCRIPTOR_ADD_LIST(edd, Eet_Test_Ex_Type, "list", list, edd); - EET_DATA_DESCRIPTOR_ADD_HASH(edd, Eet_Test_Ex_Type, "hash", hash, edd); - eet_data_descriptor_element_add(edd, "ilist", EET_T_INT, EET_G_LIST, - (char *)(&(etbt.ilist)) - (char *)(&(etbt)), - 0, /* 0, */ NULL, NULL); - eet_data_descriptor_element_add(edd, "ihash", EET_T_INT, EET_G_HASH, - (char *)(&(etbt.ihash)) - (char *)(&(etbt)), - 0, /* 0, */ NULL, NULL); - eet_data_descriptor_element_add(edd, "slist", EET_T_STRING, EET_G_LIST, - (char *)(&(etbt.slist)) - (char *)(&(etbt)), - 0, /* 0, */ NULL, NULL); - eet_data_descriptor_element_add(edd, "shash", EET_T_STRING, EET_G_HASH, - (char *)(&(etbt.shash)) - (char *)(&(etbt)), - 0, /* 0, */ NULL, NULL); -} /* _eet_build_ex_descriptor */ - -static Eet_Test_Ex_Type * -_eet_test_ex_set(Eet_Test_Ex_Type *res, - int offset) -{ - unsigned int i; - - if (!res) - res = malloc(sizeof(Eet_Test_Ex_Type)); - - if (!res) - return NULL; - - res->c = EET_TEST_CHAR + offset; - res->s = EET_TEST_SHORT + offset; - res->i = EET_TEST_INT + offset; - res->l = EET_TEST_LONG_LONG + offset; - res->str = EET_TEST_STRING; - res->istr = EET_TEST_STRING; - res->f1 = EET_TEST_FLOAT + offset; - res->f2 = -(EET_TEST_FLOAT2 + offset); - res->f3 = EET_TEST_FLOAT3 + offset; - res->f4 = EET_TEST_FLOAT2 + offset; - res->d1 = EET_TEST_DOUBLE + offset; - res->d2 = -(EET_TEST_DOUBLE2 + offset); - res->d3 = EET_TEST_DOUBLE3 + offset; - res->d4 = EET_TEST_DOUBLE2 + offset; - res->list = NULL; - res->hash = NULL; - res->ilist = NULL; - res->ihash = NULL; - res->slist = NULL; - res->shash = NULL; - for (i = 0; i < sizeof(res->charray) / sizeof(res->charray[0]); ++i) - res->charray[i] = NULL; - - res->varray2 = malloc(sizeof (Eet_Test_Basic_Type) * 10); - res->varray1 = malloc(sizeof (int) * 5); - fail_if(!res->varray1 || !res->varray2); - for (i = 0; i < 10; ++i) - { - _eet_test_basic_set(res->sarray1 + i, i); - _eet_test_basic_set(res->varray2 + i, i); - } - res->varray2_count = 10; - for (i = 0; i < 5; ++i) - { - res->sarray2[i] = i * 42 + 1; - res->varray1[i] = i * 42 + 1; - } - res->varray1_count = 5; - - res->uc = EET_TEST_CHAR + offset; - res->us = EET_TEST_SHORT + offset; - res->ui = EET_TEST_INT + offset; - res->ul = EET_TEST_LONG_LONG + offset; - - return res; -} /* _eet_test_ex_set */ - -static int -_eet_test_ex_check(Eet_Test_Ex_Type *stuff, - int offset, - Eina_Bool dumper) -{ - double tmp; - unsigned int i; - - if (!stuff) - return 1; - - if (stuff->c != EET_TEST_CHAR + offset) - return 1; - - if (stuff->s != EET_TEST_SHORT + offset) - return 1; - - if (stuff->i != EET_TEST_INT + offset) - return 1; - - if (stuff->l != EET_TEST_LONG_LONG + offset) - return 1; - - if (strcmp(stuff->str, EET_TEST_STRING) != 0) - return 1; - - if (strcmp(stuff->istr, EET_TEST_STRING) != 0) - return 1; - - tmp = stuff->f1 - (EET_TEST_FLOAT + offset); - if (tmp < 0) - tmp = -tmp; - - if (tmp > 0.005) - return 1; - - tmp = stuff->d1 - (EET_TEST_DOUBLE + offset); - if (tmp < 0) - tmp = -tmp; - - if (tmp > 0.00005) - return 1; - - if (stuff->f2 != -(EET_TEST_FLOAT2 + offset)) - return 1; - - if (stuff->d2 != -(EET_TEST_DOUBLE2 + offset)) - return 1; - - if (stuff->f3 != EET_TEST_FLOAT3 + offset) - return 1; - - if (stuff->d3 != EET_TEST_DOUBLE3 + offset) - return 1; - - if (stuff->f4 != EET_TEST_FLOAT2 + offset) - return 1; - - if (stuff->d4 != EET_TEST_DOUBLE2 + offset) - return 1; - - if (stuff->uc != EET_TEST_CHAR + offset) - return 1; - - if (stuff->us != EET_TEST_SHORT + offset) - return 1; - - if (stuff->ui != (unsigned int)EET_TEST_INT + offset) - return 1; - - if (stuff->ul != EET_TEST_LONG_LONG + offset) - return 1; - - if (stuff->varray1_count != 5) - return 1; - - if (stuff->varray2_count != 10) - return 1; - - for (i = 0; i < 5; ++i) - if (stuff->sarray2[i] != i * 42 + 1 && stuff->varray1[i] != i * 42 + 1) - return 1; - - for (i = 0; i < 10; ++i) - { - _eet_test_basic_check(stuff->sarray1 + i, i, dumper); - _eet_test_basic_check(stuff->varray2 + i, i, dumper); - } - - return 0; -} /* _eet_test_ex_check */ - -static Eina_Bool _dump_call = EINA_FALSE; - -static Eina_Bool -func(EINA_UNUSED const Eina_Hash *hash, - const void *key, - void *data, - void *fdata) -{ - int *res = fdata; - - if (strcmp(key, EET_TEST_KEY1) != 0 - && strcmp(key, EET_TEST_KEY2) != 0) - *res = 1; - - if (_eet_test_ex_check(data, 2, _dump_call)) - *res = 1; - - return EINA_TRUE; -} /* func */ - -static Eina_Bool -func7(EINA_UNUSED const Eina_Hash *hash, - EINA_UNUSED const void *key, - void *data, - void *fdata) -{ - int *res = fdata; - int *val; - - val = data; - if (!val) - *res = 1; - - if (*val != 7) - *res = 1; - - return EINA_TRUE; -} /* func7 */ - -START_TEST(eet_test_data_type_encoding_decoding) -{ - Eet_Data_Descriptor *edd; - Eet_Test_Ex_Type *result; - void *transfert; - Eet_Data_Descriptor_Class eddc; - Eet_Test_Ex_Type etbt; - int size; - int test; - - eet_init(); - - _eet_test_ex_set(&etbt, 0); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2)); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); - etbt.slist = eina_list_prepend(NULL, "test"); - etbt.shash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); - memset(&etbt.charray, 0, sizeof(etbt.charray)); - etbt.charray[0] = "test"; - etbt.charray[5] = "plouf"; - - eet_test_setup_eddc(&eddc); - eddc.name = "Eet_Test_Ex_Type"; - eddc.size = sizeof(Eet_Test_Ex_Type); - - edd = eet_data_descriptor_file_new(&eddc); - fail_if(!edd); - - _eet_build_ex_descriptor(edd, EINA_FALSE); - - transfert = eet_data_descriptor_encode(edd, &etbt, &size); - fail_if(!transfert || size <= 0); - - result = eet_data_descriptor_decode(edd, transfert, size); - fail_if(!result); - - fail_if(_eet_test_ex_check(result, 0, EINA_FALSE) != 0); - fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0); - fail_if(eina_list_data_get(result->ilist) == NULL); - fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); - fail_if(eina_list_data_get(result->slist) == NULL); - fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); - fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); - fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); - fail_if(strcmp(result->charray[0], "test") != 0); - fail_if(strcmp(result->charray[5], "plouf") != 0); - - test = 0; - if (result->hash) - eina_hash_foreach(result->hash, func, &test); - - fail_if(test != 0); - if (result->ihash) - eina_hash_foreach(result->ihash, func7, &test); - - fail_if(test != 0); - - eet_shutdown(); -} -END_TEST - -static void -append_string(void *data, - const char *str) -{ - char **string = data; - int length; - - if (!data) - return; - - length = *string ? strlen(*string) : 0; - *string = realloc(*string, strlen(str) + length + 1); - - fail_unless(*string); // Fail test case if realloc fails. - - memcpy((*string) + length, str, strlen(str) + 1); -} /* append_string */ - -START_TEST(eet_test_data_type_dump_undump) -{ - Eet_Data_Descriptor *edd; - Eet_Test_Ex_Type *result; - Eet_Data_Descriptor_Class eddc; - Eet_Test_Ex_Type etbt; - char *transfert1; - char *transfert2; - char *string1; - char *string2; - int size1; - int size2; - int test; - - eet_init(); - - _eet_test_ex_set(&etbt, 0); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2)); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); - etbt.slist = eina_list_prepend(NULL, "test"); - etbt.shash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); - memset(&etbt.charray, 0, sizeof(etbt.charray)); - etbt.charray[0] = "test"; - - eet_test_setup_eddc(&eddc); - eddc.name = "Eet_Test_Ex_Type"; - eddc.size = sizeof(Eet_Test_Ex_Type); - - edd = eet_data_descriptor_file_new(&eddc); - fail_if(!edd); - - _eet_build_ex_descriptor(edd, EINA_FALSE); - - transfert1 = eet_data_descriptor_encode(edd, &etbt, &size1); - fail_if(!transfert1 || size1 <= 0); - - string1 = NULL; - eet_data_text_dump(transfert1, size1, append_string, &string1); - fail_if(!string1); - - transfert2 = eet_data_text_undump(string1, string1 ? strlen( - string1) : 0, &size2); - fail_if(!transfert2 && size2 <= 0); - - string2 = NULL; - eet_data_text_dump(transfert2, size2, append_string, &string2); - fail_if(!string2); - - fail_if(strlen(string2) != strlen(string1)); - - result = eet_data_descriptor_decode(edd, transfert2, size2); - fail_if(!result); - - fail_if(_eet_test_ex_check(result, 0, EINA_TRUE) != 0); - fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0); - fail_if(eina_list_data_get(result->ilist) == NULL); - fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); - fail_if(eina_list_data_get(result->slist) == NULL); - fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); - fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); - fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); - fail_if(strcmp(result->charray[0], "test") != 0); - - test = 0; - _dump_call = EINA_TRUE; - if (result->hash) - eina_hash_foreach(result->hash, func, &test); - _dump_call = EINA_FALSE; - - fail_if(test != 0); - if (result->ihash) - eina_hash_foreach(result->ihash, func7, &test); - - fail_if(test != 0); - - eet_shutdown(); -} -END_TEST - -static void -append_strbuf_string(void *data, const char *string) -{ - Eina_Strbuf *strbuf = data; - eina_strbuf_append(strbuf, string); -} - -START_TEST(eet_test_data_type_escape_dump_undump) -{ - void *blob; - int blob_len; - int ret = 0; - const char *outputstr; - Eina_Strbuf *strbuf; - const char inputstr[] = "" - "group \"\\\\My\\\"Group\\\\\" struct {\n" - " value \"\\\\My\\\\BackSlash\\\\\" string: \"\\\\\";\n" - " value \"\\\\My\\\\DoubleQuote\\\\\" string: \"\\\"\";\n" - " value \"\\\\My\\\\NewLine\\\\\" string: \"\\n\";\n" - "}\n"; - - eet_init(); - - blob = eet_data_text_undump(inputstr, strlen(inputstr), &blob_len); - fail_if(!blob); - - strbuf = eina_strbuf_new(); - ret = eet_data_text_dump(blob, blob_len, append_strbuf_string, strbuf); - ck_assert_int_eq(ret, 1); - - outputstr = eina_strbuf_string_get(strbuf); - fail_if(!outputstr); - ck_assert_str_eq(inputstr, outputstr); - - eina_strbuf_free(strbuf); - free(blob); - - eet_shutdown(); -} -END_TEST -START_TEST(eet_file_simple_write) -{ - const char *buffer = "Here is a string of data to save !"; - Eet_File *ef; - char *test; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - int size; - int tmpfd; - - eet_init(); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID); - - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - - fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1)); - fail_if(!eet_alias(ef, "keys/alias", "keys/tests", 0)); - fail_if(!eet_alias(ef, "keys/alias2", "keys/alias", 1)); - - fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE); - - fail_if(eet_list(ef, "*", &size) != NULL); - fail_if(eet_num_entries(ef) != -1); - - eet_close(ef); - - /* Test read of simple file */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - test = eet_read(ef, "keys/tests", &size); - fail_if(!test); - fail_if(size != (int)strlen(buffer) + 1); - - fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); - - test = eet_read(ef, "keys/alias2", &size); - fail_if(!test); - fail_if(size != (int)strlen(buffer) + 1); - - fail_if(eet_read_direct(ef, "key/alias2", &size)); - - fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ); - fail_if(eet_num_entries(ef) != 3); - - eet_close(ef); - - /* Test eet cache system */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - test = eet_read(ef, "keys/tests", &size); - fail_if(!test); - fail_if(size != (int)strlen(buffer) + 1); - - fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_file_data_test) -{ - Eet_Data_Descriptor *edd; - Eet_Test_Ex_Type *result; - Eet_Dictionary *ed; - Eet_File *ef; - char **list; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - Eet_Data_Descriptor_Class eddc; - Eet_Test_Ex_Type etbt; - int size; - int test; - int tmpfd; - - eet_init(); - - _eet_test_ex_set(&etbt, 0); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2)); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); - etbt.slist = eina_list_prepend(NULL, "test"); - etbt.shash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); - memset(&etbt.charray, 0, sizeof(etbt.charray)); - etbt.charray[0] = "test"; - - eet_test_setup_eddc(&eddc); - eddc.name = "Eet_Test_Ex_Type"; - eddc.size = sizeof(Eet_Test_Ex_Type); - - edd = eet_data_descriptor_file_new(&eddc); - fail_if(!edd); - - _eet_build_ex_descriptor(edd, EINA_FALSE); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - /* Insert an error in etbt. */ - etbt.i = 0; - - /* Save the encoded data in a file. */ - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); - - result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); - fail_if(!result); - - fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE); - - /* Test string space. */ - ed = eet_dictionary_get(ef); - - fail_if(!eet_dictionary_string_check(ed, result->str)); - fail_if(eet_dictionary_string_check(ed, result->istr)); - - eet_close(ef); - - /* Attempt to replace etbt by the correct one. */ - etbt.i = EET_TEST_INT; - - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); - - result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); - fail_if(!result); - - /* Test the resulting data. */ - fail_if(_eet_test_ex_check(result, 0, EINA_FALSE) != 0); - - eet_close(ef); - - /* Read back the data. */ - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0)); - - result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); - fail_if(!result); - - /* Test string space. */ - ed = eet_dictionary_get(ef); - fail_if(!ed); - - fail_if(!eet_dictionary_string_check(ed, result->str)); - fail_if(eet_dictionary_string_check(ed, result->istr)); - - /* Test the resulting data. */ - fail_if(_eet_test_ex_check(result, 0, EINA_FALSE) != 0); - fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0); - fail_if(eina_list_data_get(result->ilist) == NULL); - fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); - fail_if(eina_list_data_get(result->slist) == NULL); - fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); - fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); - fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); - fail_if(strcmp(result->charray[0], "test") != 0); - - test = 0; - if (result->hash) - eina_hash_foreach(result->hash, func, &test); - - fail_if(test != 0); - if (result->ihash) - eina_hash_foreach(result->ihash, func7, &test); - - fail_if(test != 0); - - list = eet_list(ef, "keys/*", &size); - fail_if(eet_num_entries(ef) != 2); - fail_if(size != 2); - fail_if(!(strcmp(list[0], - EET_TEST_FILE_KEY1) == 0 && - strcmp(list[1], EET_TEST_FILE_KEY2) == 0) - && !(strcmp(list[0], - EET_TEST_FILE_KEY2) == 0 && - strcmp(list[1], EET_TEST_FILE_KEY1) == 0)); - free(list); - - fail_if(eet_delete(ef, NULL) != 0); - fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0); - fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0); - - list = eet_list(ef, "keys/*", &size); - fail_if(size != 1); - fail_if(eet_num_entries(ef) != 1); - - /* Test some more wrong case */ - fail_if(eet_data_read(ef, edd, "plop") != NULL); - fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL); - - /* Reinsert and reread data */ - fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); - fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL); - fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_file_data_dump_test) -{ - Eet_Data_Descriptor *edd; - Eet_Test_Ex_Type *result; - Eet_Data_Descriptor_Class eddc; - Eet_Test_Ex_Type etbt; - Eet_File *ef; - char *string1; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - int test; - int tmpfd; - - eet_init(); - - _eet_test_ex_set(&etbt, 0); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2)); - eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2)); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); - eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); - etbt.slist = eina_list_prepend(NULL, "test"); - etbt.shash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); - memset(&etbt.charray, 0, sizeof(etbt.charray)); - etbt.charray[0] = "test"; - - eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), - "Eet_Test_Ex_Type", - sizeof(Eet_Test_Ex_Type)); - - edd = eet_data_descriptor_file_new(&eddc); - fail_if(!edd); - - _eet_build_ex_descriptor(edd, EINA_FALSE); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - /* Save the encoded data in a file. */ - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - - fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); - - eet_close(ef); - - /* Use dump/undump in the middle */ - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - string1 = NULL; - fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1); - fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0); - fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1)); - - eet_close(ef); - - /* Test the correctness of the reinsertion. */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); - fail_if(!result); - - eet_close(ef); - - /* Test the resulting data. */ - fail_if(_eet_test_ex_check(result, 0, EINA_TRUE) != 0); - fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0); - fail_if(eina_list_data_get(result->ilist) == NULL); - fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); - fail_if(eina_list_data_get(result->slist) == NULL); - fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); - fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); - fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); - fail_if(strcmp(result->charray[0], "test") != 0); - - test = 0; - _dump_call = EINA_TRUE; - if (result->hash) - eina_hash_foreach(result->hash, func, &test); - _dump_call = EINA_FALSE; - - fail_if(test != 0); - if (result->ihash) - eina_hash_foreach(result->ihash, func7, &test); - - fail_if(test != 0); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_image) -{ - Eet_File *ef; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - unsigned int *data; - int compress; - int quality; - int result; - Eet_Image_Encoding lossy; - int alpha; - unsigned int w; - unsigned int h; - int tmpfd; - - eet_init(); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - /* Save the encoded data in a file. */ - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "0", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 0, - 100, - 0); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "1", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 5, - 100, - 0); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "2", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 9, - 100, - 0); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "3", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 0, - 100, - 1); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "4", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 0, - 60, - 1); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "5", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 0, - 10, - 1); - fail_if(result == 0); - - result = eet_data_image_write(ef, - EET_TEST_FILE_IMAGE "6", - test_noalpha.color, - test_noalpha.w, - test_noalpha.h, - test_noalpha.alpha, - 0, - 0, - 1); - fail_if(result == 0); - - result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "7", test_alpha.color, - test_alpha.w, test_alpha.h, test_alpha.alpha, - 9, 100, 0); - fail_if(result == 0); - - result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "8", test_alpha.color, - test_alpha.w, test_alpha.h, test_alpha.alpha, - 0, 80, 1); - fail_if(result == 0); - - result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "9", test_alpha.color, - test_alpha.w, test_alpha.h, test_alpha.alpha, - 0, 100, 1); - fail_if(result == 0); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "2", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 9); - fail_if(lossy != 0); - fail_if(data[0] != test_noalpha.color[0]); - free(data); - - result = eet_data_image_header_read(ef, - EET_TEST_FILE_IMAGE "2", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result == 0); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 9); - fail_if(lossy != 0); - - eet_close(ef); - - /* Test read of image */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - result = eet_data_image_header_read(ef, - EET_TEST_FILE_IMAGE "0", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result == 0); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 0); - fail_if(lossy != 0); - - data = malloc(w * h * 4); - fail_if(data == NULL); - result = eet_data_image_read_to_surface(ef, - EET_TEST_FILE_IMAGE "0", - 4, - 4, - data, - 2, - 2, - w * 4, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result != 1); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 0); - fail_if(quality != 100); - fail_if(lossy != 0); - fail_if(data[0] != test_noalpha.color[4 + 4 * w]); - free(data); - - data = malloc(w * h * 4); - fail_if(data == NULL); - result = eet_data_image_read_to_surface(ef, - EET_TEST_FILE_IMAGE "0", - 0, - 0, - data, - w, - h, - w * 4, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result != 1); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 0); - fail_if(quality != 100); - fail_if(lossy != 0); - fail_if(data[0] != test_noalpha.color[0]); - free(data); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "1", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 5); - fail_if(quality != 100); - fail_if(lossy != 0); - fail_if(data[0] != test_noalpha.color[0]); - free(data); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "2", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(compress != 9); - fail_if(lossy != 0); - fail_if(data[0] != test_noalpha.color[0]); - free(data); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "3", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(lossy != 1); - free(data); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "5", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(lossy != 1); - free(data); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "6", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_noalpha.w); - fail_if(h != test_noalpha.h); - fail_if(alpha != test_noalpha.alpha); - fail_if(lossy != 1); - free(data); - - result = eet_data_image_header_read(ef, - EET_TEST_FILE_IMAGE "7", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result == 0); - fail_if(w != test_alpha.w); - fail_if(h != test_alpha.h); - fail_if(alpha != test_alpha.alpha); - fail_if(compress != 9); - fail_if(lossy != 0); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "7", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_alpha.w); - fail_if(h != test_alpha.h); - fail_if(alpha != test_alpha.alpha); - fail_if(compress != 9); - fail_if(lossy != 0); - fail_if(data[0] != test_alpha.color[0]); - free(data); - - result = eet_data_image_header_read(ef, - EET_TEST_FILE_IMAGE "9", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(result == 0); - fail_if(w != test_alpha.w); - fail_if(h != test_alpha.h); - fail_if(alpha != test_alpha.alpha); - fail_if(lossy != 1); - - data = eet_data_image_read(ef, - EET_TEST_FILE_IMAGE "9", - &w, - &h, - &alpha, - &compress, - &quality, - &lossy); - fail_if(data == NULL); - fail_if(w != test_alpha.w); - fail_if(h != test_alpha.h); - fail_if(alpha != test_alpha.alpha); - fail_if(lossy != 1); - free(data); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST - -#define IM0 0x00112233 -#define IM1 0x44556677 -#define IM2 0x8899aabb -#define IM3 0xccddeeff - -START_TEST(eet_small_image) -{ - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - unsigned int image[4]; - unsigned int *data; - Eet_File *ef; - unsigned int w; - unsigned int h; - int alpha; - int compression; - int quality; - Eet_Image_Encoding lossy; - int result; - int tmpfd; - - image[0] = IM0; - image[1] = IM1; - image[2] = IM2; - image[3] = IM3; - - eet_init(); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - - result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0); - fail_if(result == 0); - - eet_close(ef); - - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - data = (unsigned int *)eet_data_image_read(ef, - "/images/test", - &w, - &h, - &alpha, - &compression, - &quality, - &lossy); - fail_if(data == NULL); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - fail_if(data[0] != IM0); - fail_if(data[1] != IM1); - fail_if(data[2] != IM2); - fail_if(data[3] != IM3); - - free(data); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_identity_simple) -{ - const char *buffer = "Here is a string of data to save !"; - const void *tmp; - Eet_File *ef; - Eet_Key *k; - FILE *noread; - char *test; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - int size; - int fd; - - eet_init(); - - fail_if(-1 == (fd = mkstemp(file))); - fail_if(!!close(fd)); - fail_if(!(noread = fopen("/dev/null", "wb"))); - - /* Sign an eet file. */ - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - - fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); - - k = eet_identity_open(_cert_pem, _key_pem, NULL); - fail_if(!k); - - fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE); - eet_identity_print(k, noread); - - eet_close(ef); - - /* Open a signed file. */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - /* check that the certificates match */ - fail_if(!eet_identity_verify(ef, _cert_pem)); - - test = eet_read(ef, "keys/tests", &size); - fail_if(!test); - fail_if(size != (int)strlen(buffer) + 1); - - fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); - - tmp = eet_identity_x509(ef, &size); - fail_if(tmp == NULL); - - eet_identity_certificate_print(tmp, size, noread); - - eet_close(ef); - - /* As we are changing file contain in less than 1s, this could get unnoticed - by eet cache system. */ - eet_clearcache(); - - /* Corrupting the file. */ - fd = open(file, O_WRONLY | O_BINARY); - fail_if(fd < 0); - - fail_if(lseek(fd, 200, SEEK_SET) != 200); - fail_if(write(fd, "42", 2) != 2); - fail_if(lseek(fd, 50, SEEK_SET) != 50); - fail_if(write(fd, "42", 2) != 2); - fail_if(lseek(fd, 88, SEEK_SET) != 88); - fail_if(write(fd, "42", 2) != 2); - - close(fd); - - /* Attempt to open a modified file. */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_identity_open_simple) -{ - Eet_Key *k = NULL; - - eet_init(); - - k = eet_identity_open(_cert_pem, _key_pem, NULL); - fail_if(!k); - - if (k) - eet_identity_close(k); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST -START_TEST(eet_identity_open_pkcs8) -{ - Eet_Key *k = NULL; - - eet_init(); - - k = eet_identity_open(_cert_pem, _key_enc_none_pem, NULL); - fail_if(!k); - - if (k) - eet_identity_close(k); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST - -static int -pass_get(char *pass, - int size, - EINA_UNUSED int rwflags, - EINA_UNUSED void *u) -{ - memset(pass, 0, size); - - if ((int)strlen("password") > size) - return 0; - - snprintf(pass, size, "%s", "password"); - return strlen(pass); -} /* pass_get */ - -static int -badpass_get(char *pass, - int size, - EINA_UNUSED int rwflags, - EINA_UNUSED void *u) -{ - memset(pass, 0, size); - - if ((int)strlen("bad password") > size) - return 0; - - snprintf(pass, size, "%s", "bad password"); - return strlen(pass); -} /* badpass_get */ - -START_TEST(eet_identity_open_pkcs8_enc) -{ - Eet_Key *k = NULL; - - eet_init(); - - k = eet_identity_open(_cert_pem, _key_enc_pem, NULL); - fail_if(k); - - if (k) - eet_identity_close(k); - - k = eet_identity_open(_cert_pem, _key_enc_pem, &badpass_get); - fail_if(k); - - if (k) - eet_identity_close(k); - - k = eet_identity_open(_cert_pem, _key_enc_pem, &pass_get); - fail_if(!k); - - if (k) - eet_identity_close(k); - - eet_shutdown(); -} -END_TEST -START_TEST(eet_cipher_decipher_simple) -{ - const char *buffer = "Here is a string of data to save !"; - const char *key = "This is a crypto key"; - const char *key_bad = "This is another crypto key"; - Eet_File *ef; - char *test; - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - int size; - int tmpfd; - - eet_init(); - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - /* Crypt an eet file. */ - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - - fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, - key)); - - eet_close(ef); - - /* Decrypt an eet file. */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - test = eet_read_cipher(ef, "keys/tests", &size, key); - fail_if(!test); - fail_if(size != (int)strlen(buffer) + 1); - - fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); - - eet_close(ef); - - /* Decrypt an eet file. */ - ef = eet_open(file, EET_FILE_MODE_READ); - fail_if(!ef); - - test = eet_read_cipher(ef, "keys/tests", &size, key_bad); - - if (size == (int)strlen(buffer) + 1) - fail_if(memcmp(test, buffer, strlen(buffer) + 1) == 0); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST - -static Eina_Bool open_worker_stop; -static Eina_Condition open_worker_cond; -static Eina_Lock open_worker_mutex; - -static void * -open_close_worker(void *path, Eina_Thread tid EINA_UNUSED) -{ - static Eina_Bool first = EINA_TRUE; - - while (!open_worker_stop) - { - Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ); - if (ef == NULL) - return "eet_open() failed"; - else - { - Eet_Error err_code = eet_close(ef); - if (err_code != EET_ERROR_NONE) - return "eet_close() failed"; - } - - if (first) - { - eina_lock_take(&open_worker_mutex); - eina_condition_broadcast(&open_worker_cond); - eina_lock_release(&open_worker_mutex); - first = EINA_FALSE; - } - } - - return NULL; -} - -START_TEST(eet_cache_concurrency) -{ - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - const char *buffer = "test data"; - Eet_File *ef; - void *thread_ret; - unsigned int n; - Eina_Thread thread; - Eina_Bool r; - int tmpfd; - - eet_init(); - eina_threads_init(); - - eina_lock_new(&open_worker_mutex); - eina_condition_new(&open_worker_cond, &open_worker_mutex); - - /* create a file to test with */ - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - ef = eet_open(file, EET_FILE_MODE_WRITE); - fail_if(!ef); - fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); - - eina_lock_take(&open_worker_mutex); - /* start a thread that repeatedly opens and closes a file */ - open_worker_stop = 0; - r = eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, open_close_worker, file); - fail_unless(r); - - eina_condition_wait(&open_worker_cond); - eina_lock_release(&open_worker_mutex); - - /* clear the cache repeatedly in this thread */ - for (n = 0; n < 20000; ++n) - { - eet_clearcache(); - } - - /* join the other thread, and fail if it returned an error message */ - open_worker_stop = 1; - thread_ret = eina_thread_join(thread); - fail_unless(thread_ret == NULL, (char const *)thread_ret); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eina_threads_shutdown(); - eet_shutdown(); -} -END_TEST - -typedef struct _Eet_Connection_Data Eet_Connection_Data; -struct _Eet_Connection_Data -{ - Eet_Connection *conn; - Eet_Data_Descriptor *edd; - Eina_Bool test; -}; - -static Eina_Bool -_eet_connection_read(const void *eet_data, - size_t size, - void *user_data) -{ - Eet_Connection_Data *dt = user_data; - Eet_Test_Ex_Type *result; - Eet_Node *node; - int test; - - result = eet_data_descriptor_decode(dt->edd, eet_data, size); - node = eet_data_node_decode_cipher(eet_data, NULL, size); - - /* Test the resulting data. */ - fail_if(!node); - fail_if(_eet_test_ex_check(result, 0, _dump_call) != 0); - fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1, _dump_call) != 0); - fail_if(eina_list_data_get(result->ilist) == NULL); - fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); - fail_if(eina_list_data_get(result->slist) == NULL); - fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); - fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); - fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); - fail_if(strcmp(result->charray[0], "test") != 0); - - test = 0; - if (result->hash) - eina_hash_foreach(result->hash, func, &test); - - fail_if(test != 0); - if (result->ihash) - eina_hash_foreach(result->ihash, func7, &test); - - fail_if(test != 0); - - if (!dt->test) - { - dt->test = EINA_TRUE; - _dump_call = EINA_TRUE; - fail_if(!eet_connection_node_send(dt->conn, node, NULL)); - _dump_call = EINA_FALSE; - } - - return EINA_TRUE; -} /* _eet_connection_read */ - -static Eina_Bool -_eet_connection_write(const void *data, - size_t size, - void *user_data) -{ - Eet_Connection_Data *dt = user_data; - int still; - - if (!dt->test) - { - int step = size / 3; - - eet_connection_received(dt->conn, data, step); - eet_connection_received(dt->conn, (char *)data + step, step); - size -= 2 * step; - still = eet_connection_received(dt->conn, (char *)data + 2 * step, size); - } - else - still = eet_connection_received(dt->conn, data, size); - - fail_if(still); - - return EINA_TRUE; -} /* _eet_connection_write */ - -START_TEST(eet_connection_check) -{ - Eet_Data_Descriptor *edd; - Eet_Data_Descriptor_Class eddc; - Eet_Connection_Data ecd; - Eet_Test_Ex_Type etbt; - Eina_Bool on_going; - - eet_init(); - - _eet_test_ex_set(&etbt, 0); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.list = eina_list_prepend(etbt.list, _eet_test_ex_set(NULL, 1)); - etbt.hash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.hash, EET_TEST_KEY1, _eet_test_ex_set(NULL, 2)); - eina_hash_add(etbt.hash, EET_TEST_KEY2, _eet_test_ex_set(NULL, 2)); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ilist = eina_list_prepend(etbt.ilist, &i42); - etbt.ihash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); - eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); - etbt.slist = eina_list_prepend(NULL, "test"); - etbt.shash = eina_hash_string_superfast_new(NULL); - eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); - memset(&etbt.charray, 0, sizeof(etbt.charray)); - etbt.charray[0] = "test"; - - eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), - "Eet_Test_Ex_Type", - sizeof(Eet_Test_Ex_Type)); - - edd = eet_data_descriptor_stream_new(&eddc); - fail_if(!edd); - - _eet_build_ex_descriptor(edd, EINA_TRUE); - - /* Init context. */ - ecd.test = EINA_FALSE; - ecd.edd = edd; - - /* Create a connection. */ - ecd.conn = eet_connection_new(_eet_connection_read, _eet_connection_write, &ecd); - fail_if(!ecd.conn); - - /* Test the connection. */ - fail_if(!eet_connection_send(ecd.conn, edd, &etbt, NULL)); - - fail_if(!ecd.test); - - fail_if(!eet_connection_close(ecd.conn, &on_going)); - - fail_if(on_going); - - eet_shutdown(); -} -END_TEST - -struct _Eet_5FP -{ - Eina_F32p32 fp32; - Eina_F16p16 fp16; - Eina_F8p24 fp8; - Eina_F32p32 f1; - Eina_F32p32 f0; -}; -typedef struct _Eet_5FP Eet_5FP; - -struct _Eet_5DBL -{ - double fp32; - double fp16; - float fp8; - double f1; - double f0; -}; -typedef struct _Eet_5DBL Eet_5DBL; - -START_TEST(eet_fp) -{ - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *edd_5FP; - Eet_Data_Descriptor *edd_5DBL; - Eet_5FP origin; - Eet_5DBL *convert; - Eet_5FP *build; - void *blob; - int size; - - eet_init(); - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP); - edd_5FP = eet_data_descriptor_stream_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32); - - eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL)); - edd_5DBL = eet_data_descriptor_stream_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE); - - origin.fp32 = eina_f32p32_double_from(1.125); - origin.fp16 = eina_f16p16_int_from(2000); - origin.fp8 = eina_f8p24_int_from(125); - origin.f1 = eina_f32p32_int_from(1); - origin.f0 = 0; - - blob = eet_data_descriptor_encode(edd_5FP, &origin, &size); - fail_if(!blob || size <= 0); - - build = eet_data_descriptor_decode(edd_5FP, blob, size); - fail_if(!build); - - convert = eet_data_descriptor_decode(edd_5DBL, blob, size); - fail_if(!convert); - - fail_if(build->fp32 != eina_f32p32_double_from(1.125)); - fail_if(build->fp16 != eina_f16p16_int_from(2000)); - fail_if(build->fp8 != eina_f8p24_int_from(125)); - fail_if(build->f1 != eina_f32p32_int_from(1)); - fail_if(build->f0 != 0); - - fail_if(convert->fp32 != 1.125); - fail_if(convert->fp16 != 2000); - fail_if(convert->fp8 != 125); - fail_if(convert->f1 != 1); - fail_if(convert->f0 != 0); - - eet_shutdown(); -} -END_TEST -START_TEST(eet_file_fp) -{ - char *file = strdup("/tmp/eet_suite_testXXXXXX"); - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *edd_5FP; - Eet_Data_Descriptor *edd_5DBL; - Eet_File *ef; - Eet_5FP origin; - Eet_5DBL *convert; - Eet_5FP *build; - int tmpfd; - - eet_init(); - - EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP); - edd_5FP = eet_data_descriptor_file_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32); - - eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL)); - edd_5DBL = eet_data_descriptor_file_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE); - - origin.fp32 = eina_f32p32_double_from(1.125); - origin.fp16 = eina_f16p16_int_from(2000); - origin.fp8 = eina_f8p24_int_from(125); - origin.f1 = eina_f32p32_int_from(1); - origin.f0 = 0; - - fail_if(-1 == (tmpfd = mkstemp(file))); - fail_if(!!close(tmpfd)); - - ef = eet_open(file, EET_FILE_MODE_READ_WRITE); - fail_if(!ef); - - fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1)); - - build = eet_data_read(ef, edd_5FP, EET_TEST_FILE_KEY1); - fail_if(!build); - - convert = eet_data_read(ef, edd_5DBL, EET_TEST_FILE_KEY1); - fail_if(!convert); - - fail_if(build->fp32 != eina_f32p32_double_from(1.125)); - fail_if(build->fp16 != eina_f16p16_int_from(2000)); - fail_if(build->fp8 != eina_f8p24_int_from(125)); - fail_if(build->f1 != eina_f32p32_int_from(1)); - fail_if(build->f0 != 0); - - fail_if(convert->fp32 != 1.125); - fail_if(convert->fp16 != 2000); - fail_if(convert->fp8 != 125); - fail_if(convert->f1 != 1); - fail_if(convert->f0 != 0); - - eet_close(ef); - - fail_if(unlink(file) != 0); - - eet_shutdown(); -} /* START_TEST */ - -END_TEST - -typedef struct _Eet_Union_Test Eet_Union_Test; -typedef struct _Eet_Variant_Test Eet_Variant_Test; -typedef struct _Eet_Variant_Type Eet_Variant_Type; -typedef struct _Eet_Inherit_Test1 Eet_Inherit_Test1; -typedef struct _Eet_Inherit_Test2 Eet_Inherit_Test2; -typedef struct _Eet_Inherit_Test3 Eet_Inherit_Test3; -typedef struct _Eet_St1 Eet_St1; -typedef struct _Eet_St2 Eet_St2; -typedef struct _Eet_St3 Eet_St3; -typedef struct _Eet_List Eet_List; - -typedef enum _Eet_Union -{ - EET_UNKNOWN, - EET_ST1, - EET_ST2, - EET_ST3 -} Eet_Union; - -struct -{ - Eet_Union u; - const char *name; -} eet_mapping[] = { - { EET_ST1, "ST1" }, - { EET_ST2, "ST2" }, - { EET_ST3, "ST3" }, - { EET_UNKNOWN, NULL } -}; - -struct _Eet_St1 -{ - double val1; - int stuff; - char *s1; -}; - -struct _Eet_St2 -{ - Eina_Bool b1; - unsigned long long v1; -}; - -struct _Eet_St3 -{ - int boby; -}; - -struct _Eet_Union_Test -{ - Eet_Union type; - - union { - Eet_St1 st1; - Eet_St2 st2; - Eet_St3 st3; - } u; -}; - -struct _Eet_Variant_Type -{ - const char *type; - Eina_Bool unknow : 1; -}; - -struct _Eet_Variant_Test -{ - Eet_Variant_Type t; - - void *data; - Eina_List *data_list; -}; - -struct _Eet_Inherit_Test1 -{ - Eet_Union type; - Eet_St1 st1; -}; -struct _Eet_Inherit_Test2 -{ - Eet_Union type; - Eet_St2 st2; -}; -struct _Eet_Inherit_Test3 -{ - Eet_Union type; - Eet_St3 st3; -}; - -struct _Eet_List -{ - Eina_List *list; -}; - -static const char * -_eet_union_type_get(const void *data, - Eina_Bool *unknow) -{ - const Eet_Union *u = data; - int i; - - if (unknow) - *unknow = EINA_FALSE; - - for (i = 0; eet_mapping[i].name != NULL; ++i) - if (*u == eet_mapping[i].u) - return eet_mapping[i].name; - - if (unknow) - *unknow = EINA_TRUE; - - return NULL; -} /* _eet_union_type_get */ - -static Eina_Bool -_eet_union_type_set(const char *type, - void *data, - Eina_Bool unknow) -{ - Eet_Union *u = data; - int i; - - if (unknow) - return EINA_FALSE; - - for (i = 0; eet_mapping[i].name != NULL; ++i) - if (strcmp(eet_mapping[i].name, type) == 0) - { - *u = eet_mapping[i].u; - return EINA_TRUE; - } - - return EINA_FALSE; -} /* _eet_union_type_set */ - -static const char * -_eet_variant_type_get(const void *data, - Eina_Bool *unknow) -{ - const Eet_Variant_Type *type = data; - int i; - - if (unknow) - *unknow = type->unknow; - - for (i = 0; eet_mapping[i].name != NULL; ++i) - if (strcmp(type->type, eet_mapping[i].name) == 0) - return eet_mapping[i].name; - - if (unknow) - *unknow = EINA_FALSE; - - return type->type; -} /* _eet_variant_type_get */ - -static Eina_Bool -_eet_variant_type_set(const char *type, - void *data, - Eina_Bool unknow) -{ - Eet_Variant_Type *vt = data; - - vt->type = type; - vt->unknow = unknow; - return EINA_TRUE; -} /* _eet_variant_type_set */ - -static Eet_Data_Descriptor * -_eet_st1_dd(void) -{ - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *res; - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St1); - res = eet_data_descriptor_stream_new(&eddc); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "val1", val1, EET_T_DOUBLE); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "stuff", stuff, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "s1", s1, EET_T_STRING); - - return res; -} /* _eet_st1_dd */ - -static void -_eet_st1_set(Eet_St1 *st1, - int i) -{ - st1->val1 = EET_TEST_DOUBLE; - st1->stuff = EET_TEST_INT + i; - st1->s1 = EET_TEST_STRING; -} /* _eet_st1_set */ - -static void -_eet_st1_cmp(Eet_St1 *st1, - int i) -{ - double tmp; - - fail_if(!st1); - - tmp = st1->val1 - EET_TEST_DOUBLE; - if (tmp < 0) - tmp = -tmp; - - fail_if(tmp > 0.005); - fail_if(st1->stuff != EET_TEST_INT + i); - fail_if(strcmp(st1->s1, EET_TEST_STRING)); -} /* _eet_st1_cmp */ - -static Eet_Data_Descriptor * -_eet_st2_dd(void) -{ - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *res; - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St2); - res = eet_data_descriptor_stream_new(&eddc); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "b1", b1, EET_T_UCHAR); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "v1", v1, EET_T_ULONG_LONG); - - return res; -} /* _eet_st2_dd */ - -static void -_eet_st2_set(Eet_St2 *st2, - int i) -{ - st2->b1 = EINA_TRUE; - st2->v1 = EET_TEST_LONG_LONG + i; -} /* _eet_st2_set */ - -static void -_eet_st2_cmp(Eet_St2 *st2, - int i) -{ - fail_if(!st2->b1); - fail_if(st2->v1 != EET_TEST_LONG_LONG + i); -} /* _eet_st2_cmp */ - -static Eet_Data_Descriptor * -_eet_st3_dd(void) -{ - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *res; - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St3); - res = eet_data_descriptor_stream_new(&eddc); - EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St3, "boby", boby, EET_T_INT); - - return res; -} /* _eet_st3_dd */ - -static void -_eet_st3_set(Eet_St3 *st3, - int i) -{ - st3->boby = EET_TEST_INT + i; -} /* _eet_st3_set */ - -static void -_eet_st3_cmp(Eet_St3 *st3, - int i) -{ - fail_if(st3->boby != EET_TEST_INT + i); -} /* _eet_st3_cmp */ - -START_TEST(eet_test_union) -{ - Eet_Union_Test *eut; - Eet_List *l; - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *edd; - Eet_Data_Descriptor *unified; - Eet_Data_Descriptor *m; - void *blob; - int size; - int i; - - eina_init(); - eet_init(); - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test); - edd = eet_data_descriptor_stream_new(&eddc); - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test); - m = eet_data_descriptor_stream_new(&eddc); - - eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; - eddc.func.type_get = _eet_union_type_get; - eddc.func.type_set = _eet_union_type_set; - unified = eet_data_descriptor_stream_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd()); - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd()); - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd()); - - EET_DATA_DESCRIPTOR_ADD_UNION(edd, Eet_Union_Test, "u", u, type, unified); - - EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd); - - l = calloc(1, sizeof (Eet_List)); - -#define EUT_NEW(Type_Index) \ - eut = calloc(1, sizeof (Eet_Union_Test)); \ - eut->type = EET_ST ## Type_Index; \ - _eet_st ## Type_Index ## _set(&(eut->u.st ## Type_Index), i); - - for (i = 0; i < 3; ++i) - { - EUT_NEW(1); - l->list = eina_list_append(l->list, eut); - - EUT_NEW(2); - l->list = eina_list_append(l->list, eut); - - EUT_NEW(3); - l->list = eina_list_append(l->list, eut); - } - - blob = eet_data_descriptor_encode(m, l, &size); - fail_if(!blob || size <= 0); - - l = eet_data_descriptor_decode(m, blob, size); - fail_if(!l); - - fail_if(eina_list_count(l->list) != 9); - -#define EUT_CMP(Type_Index) \ - eut = eina_list_nth(l->list, i * 3 + Type_Index - 1); \ - fail_if(eut->type != EET_ST ## Type_Index); \ - _eet_st ## Type_Index ## _cmp(&(eut->u.st ## Type_Index), i); - - for (i = 0; i < 3; ++i) - { - EUT_CMP(1); - EUT_CMP(2); - EUT_CMP(3); - } - - eet_shutdown(); - eina_shutdown(); -} -END_TEST -START_TEST(eet_test_variant) -{ - Eet_Variant_Test *evt; - Eet_List *l; - Eet_St1 *st1; - Eet_St2 *st2; - Eet_St3 *st3; - Eet_Data_Descriptor_Class eddc; - Eet_Data_Descriptor *edd; - Eet_Data_Descriptor *unified; - Eet_Data_Descriptor *m; - void *blob; - int size; - int i; - - eina_init(); - eet_init(); - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test); - edd = eet_data_descriptor_stream_new(&eddc); - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test); - m = eet_data_descriptor_stream_new(&eddc); - - eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; - eddc.func.type_get = _eet_variant_type_get; - eddc.func.type_set = _eet_variant_type_set; - unified = eet_data_descriptor_stream_new(&eddc); - - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd()); - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd()); - EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd()); - - EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, - Eet_Variant_Test, - "data", - data, - t, - unified); - - unified = eet_data_descriptor_stream_new(&eddc); - eet_data_descriptor_element_add(unified, "ST1", - EET_T_UNKNOW, EET_G_LIST, - 0, 0, NULL, _eet_st1_dd()); - eet_data_descriptor_element_add(unified, "ST2", - EET_T_UNKNOW, EET_G_LIST, - 0, 0, NULL, _eet_st2_dd()); - - EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, Eet_Variant_Test, - "data_list", data_list, t, unified); - - EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd); - - l = calloc(1, sizeof (Eet_List)); - -#define EVT_NEW(Type_Index) \ - evt = calloc(1, sizeof (Eet_Variant_Test)); \ - evt->t.type = eet_mapping[Type_Index - 1].name; \ - st ## Type_Index = calloc(1, sizeof (Eet_St ## Type_Index)); \ - _eet_st ## Type_Index ## _set(st ## Type_Index, i); \ - evt->data = st ## Type_Index; - - for (i = 0; i < 3; ++i) - { - EVT_NEW(1); - l->list = eina_list_append(l->list, evt); - - st1 = calloc(1, sizeof (Eet_St1)); - _eet_st1_set(st1, i); - evt->data_list = eina_list_append(evt->data_list, st1); - - EVT_NEW(2); - l->list = eina_list_append(l->list, evt); - - EVT_NEW(3); - l->list = eina_list_append(l->list, evt); - } - - blob = eet_data_descriptor_encode(m, l, &size); - fail_if(!blob || size <= 0); - - l = eet_data_descriptor_decode(m, blob, size); - fail_if(!l); - - fail_if(eina_list_count(l->list) != 9); - -#define EVT_CMP(Type_Index) \ - evt = eina_list_nth(l->list, i * 3 + Type_Index - 1); \ - fail_if(strcmp(evt->t.type, eet_mapping[Type_Index - 1].name) != 0); \ - _eet_st ## Type_Index ## _cmp(evt->data, i); - - for (i = 0; i < 3; ++i) - { - EVT_CMP(1); - - fail_if(!evt->data_list); - fail_if(eina_list_count(evt->data_list) != 1); - - st1 = eina_list_data_get(evt->data_list); - _eet_st1_cmp(st1, i); - - EVT_CMP(2); - EVT_CMP(3); - } - - eet_shutdown(); - eina_shutdown(); -} /* START_TEST */ - -END_TEST - -Suite * -eet_suite(void) -{ - Suite *s; - TCase *tc; - - s = suite_create("Eet"); - - tc = tcase_create("Eet_Init"); - tcase_add_test(tc, eet_test_init); - suite_add_tcase(s, tc); - - tc = tcase_create("Eet Data Encoding/Decoding"); - tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding); - tcase_add_test(tc, eet_test_data_type_encoding_decoding); - tcase_add_test(tc, eet_test_data_type_dump_undump); - tcase_add_test(tc, eet_test_data_type_escape_dump_undump); - tcase_add_test(tc, eet_fp); - tcase_add_test(tc, eet_test_union); - tcase_add_test(tc, eet_test_variant); - suite_add_tcase(s, tc); - - tc = tcase_create("Eet File"); - tcase_add_test(tc, eet_file_simple_write); - tcase_add_test(tc, eet_file_data_test); - tcase_add_test(tc, eet_file_data_dump_test); - tcase_add_test(tc, eet_file_fp); - suite_add_tcase(s, tc); - - tc = tcase_create("Eet Image"); - tcase_add_test(tc, eet_image); - tcase_add_test(tc, eet_small_image); - suite_add_tcase(s, tc); +char argv0[PATH_MAX]; +static const Efl_Test_Case etc[] = { + { "Eet Init", eet_test_init }, + { "Eet Data Encoding/Decoding", eet_test_data }, + { "Eet File", eet_test_file }, + { "Eet Image", eet_test_image }, #ifdef HAVE_SIGNATURE - tc = tcase_create("Eet Identity"); - tcase_add_test(tc, eet_identity_simple); - tcase_add_test(tc, eet_identity_open_simple); - tcase_add_test(tc, eet_identity_open_pkcs8); - tcase_add_test(tc, eet_identity_open_pkcs8_enc); - suite_add_tcase(s, tc); -#endif /* ifdef HAVE_SIGNATURE */ - + { "Eet Identity", eet_test_identity }, +#endif #ifdef HAVE_CIPHER - tc = tcase_create("Eet Cipher"); - tcase_add_test(tc, eet_cipher_decipher_simple); - suite_add_tcase(s, tc); -#endif /* ifdef HAVE_CIPHER */ - - tc = tcase_create("Eet Cache"); - tcase_add_test(tc, eet_cache_concurrency); - suite_add_tcase(s, tc); - - tc = tcase_create("Eet Connection"); - tcase_add_test(tc, eet_connection_check); - suite_add_tcase(s, tc); - - return s; -} /* eet_suite */ - -static const char *_cert_dir_find(const char *argv0) -{ - static char base[PATH_MAX] = ""; - char path[PATH_MAX]; - struct stat st; - - eina_strlcpy(base, TESTS_SRC_DIR, sizeof(base)); - eina_str_join(path, sizeof(path), '/', base, "key.pem"); - if (stat(path, &st) == 0) - return base; - - if (base[0] != '/') - { - snprintf(base, sizeof(base), "%s/%s", TESTS_WD, TESTS_SRC_DIR); - eina_str_join(path, sizeof(path), '/', base, "key.pem"); - if (stat(path, &st) == 0) - return base; - } - - eina_strlcpy(base, argv0, sizeof(base)); - do - { - char *p = strrchr(base, '/'); - if (!p) - { - base[0] = '\0'; - break; - } - *p = '\0'; - eina_str_join(path, sizeof(path), '/', base, "key.pem"); - } - while (stat(path, &st) != 0); - - return base; -} + { "Eet Cipher", eet_test_cipher }, +#endif + { "Eet Cache", eet_test_cache }, + { "Eet Connection", eet_test_connection }, + { NULL, NULL } +}; int -main(int argc EINA_UNUSED, char *argv[]) +main(int argc, char *argv[]) { - Suite *s; - SRunner *sr; int failed_count; - const char *base = _cert_dir_find(argv[0]); + + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - eina_str_join(_key_pem, sizeof(_key_pem), '/', base, "key.pem"); - eina_str_join(_cert_pem, sizeof(_cert_pem), '/', base,"cert.pem"); - eina_str_join(_key_enc, sizeof(_key_enc), '/', base, "key.enc"); - eina_str_join(_key_enc_pem, sizeof(_key_enc_pem), '/', base, "key_enc.pem"); - eina_str_join(_key_enc_none_pem, sizeof(_key_enc_none_pem), '/', - base, "key_enc_none.pem"); + memcpy(argv0, argv[0], strlen(argv[0]) + 1); - s = eet_suite(); - sr = srunner_create(s); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eet", etc); return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; -} /* main */ +} diff --git a/src/tests/eet/eet_suite.h b/src/tests/eet/eet_suite.h index c5c91aaee1..b7c3e59ae6 100644 --- a/src/tests/eet/eet_suite.h +++ b/src/tests/eet/eet_suite.h @@ -1,9 +1,15 @@ #ifndef _EET_SUITE_H # define _EET_SUITE_H -#include "Eet.h" +#include -void -eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc); +void eet_test_init(TCase *tc); +void eet_test_data(TCase *tc); +void eet_test_file(TCase *tc); +void eet_test_image(TCase *tc); +void eet_test_identity(TCase *tc); +void eet_test_cipher(TCase *tc); +void eet_test_cache(TCase *tc); +void eet_test_connection(TCase *tc); #endif /* _EET_SUITE_H */ diff --git a/src/tests/eet/eet_test_cache.c b/src/tests/eet/eet_test_cache.c new file mode 100644 index 0000000000..6713c410a0 --- /dev/null +++ b/src/tests/eet/eet_test_cache.c @@ -0,0 +1,105 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +static Eina_Bool open_worker_stop; +static Eina_Condition open_worker_cond; +static Eina_Lock open_worker_mutex; + +static void * +_open_close_worker(void *path, Eina_Thread tid EINA_UNUSED) +{ + static Eina_Bool first = EINA_TRUE; + + while (!open_worker_stop) + { + Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ); + if (ef == NULL) + return "eet_open() failed"; + else + { + Eet_Error err_code = eet_close(ef); + if (err_code != EET_ERROR_NONE) + return "eet_close() failed"; + } + + if (first) + { + eina_lock_take(&open_worker_mutex); + eina_condition_broadcast(&open_worker_cond); + eina_lock_release(&open_worker_mutex); + first = EINA_FALSE; + } + } + + return NULL; +} + +START_TEST(eet_test_cache_concurrency) +{ + char *file; + const char *buffer = "test data"; + Eet_File *ef; + void *thread_ret; + unsigned int n; + Eina_Thread thread; + Eina_Bool r; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + eina_threads_init(); + + eina_lock_new(&open_worker_mutex); + eina_condition_new(&open_worker_cond, &open_worker_mutex); + + /* create a file to test with */ + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); + + eina_lock_take(&open_worker_mutex); + /* start a thread that repeatedly opens and closes a file */ + open_worker_stop = 0; + r = eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, _open_close_worker, file); + fail_unless(r); + + eina_condition_wait(&open_worker_cond); + eina_lock_release(&open_worker_mutex); + + /* clear the cache repeatedly in this thread */ + for (n = 0; n < 20000; ++n) + { + eet_clearcache(); + } + + /* join the other thread, and fail if it returned an error message */ + open_worker_stop = 1; + thread_ret = eina_thread_join(thread); + fail_unless(thread_ret == NULL, (char const *)thread_ret); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eina_threads_shutdown(); + eet_shutdown(); +} +END_TEST + +void eet_test_cache(TCase *tc) +{ + tcase_add_test(tc, eet_test_cache_concurrency); +} diff --git a/src/tests/eet/eet_test_cipher.c b/src/tests/eet/eet_test_cipher.c new file mode 100644 index 0000000000..2cee686a5c --- /dev/null +++ b/src/tests/eet/eet_test_cipher.c @@ -0,0 +1,72 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +START_TEST(eet_test_cipher_decipher_simple) +{ + const char *buffer = "Here is a string of data to save !"; + const char *key = "This is a crypto key"; + const char *key_bad = "This is another crypto key"; + Eet_File *ef; + char *test; + char *file = strdup("/tmp/eet_suite_testXXXXXX"); + int size; + int tmpfd; + + eet_init(); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + /* Crypt an eet file. */ + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + + fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, + key)); + + eet_close(ef); + + /* Decrypt an eet file. */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + test = eet_read_cipher(ef, "keys/tests", &size, key); + fail_if(!test); + fail_if(size != (int)strlen(buffer) + 1); + + fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); + + eet_close(ef); + + /* Decrypt an eet file. */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + test = eet_read_cipher(ef, "keys/tests", &size, key_bad); + + if (size == (int)strlen(buffer) + 1) + fail_if(memcmp(test, buffer, strlen(buffer) + 1) == 0); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +void eet_test_cipher(TCase *tc) +{ + tcase_add_test(tc, eet_test_cipher_decipher_simple); +} diff --git a/src/tests/eet/eet_test_common.c b/src/tests/eet/eet_test_common.c new file mode 100644 index 0000000000..dba9ab19da --- /dev/null +++ b/src/tests/eet/eet_test_common.c @@ -0,0 +1,649 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include + +#include + +#include "eet_test_common.h" + +int i42 = 42; +int i7 = 7; +Eina_Bool _dump_call = EINA_FALSE; + +void +append_string(void *data, + const char *str) +{ + char **string = data; + int length; + + if (!data) + return; + + length = *string ? strlen(*string) : 0; + *string = realloc(*string, strlen(str) + length + 1); + + fail_unless(*string); // Fail test case if realloc fails. + + memcpy((*string) + length, str, strlen(str) + 1); +} + +void +append_strbuf_string(void *data, const char *string) +{ + Eina_Strbuf *strbuf = data; + eina_strbuf_append(strbuf, string); +} + +Eina_Bool +func(EINA_UNUSED const Eina_Hash *hash, + const void *key, + void *data, + void *fdata) +{ + int *res = fdata; + + if (strcmp(key, EET_TEST_KEY1) != 0 + && strcmp(key, EET_TEST_KEY2) != 0) + *res = 1; + + if (eet_test_ex_check(data, 2, _dump_call)) + *res = 1; + + return EINA_TRUE; +} /* func */ + +Eina_Bool +func7(EINA_UNUSED const Eina_Hash *hash, + EINA_UNUSED const void *key, + void *data, + void *fdata) +{ + int *res = fdata; + int *val; + + val = data; + if (!val) + *res = 1; + + if (*val != 7) + *res = 1; + + return EINA_TRUE; +} /* func7 */ + +static char * +_eet_str_direct_alloc(const char *str) +{ + return (char *)str; +} /* _eet_str_direct_alloc */ + +static void +_eet_str_direct_free(const char *str) +{ + /* FIXME: Use attribute unused */ + (void)str; +} /* _eet_str_direct_free */ + +static void +_eet_eina_hash_foreach(void *hash, + Eina_Hash_Foreach cb, + void *fdata) +{ + if (hash) + eina_hash_foreach(hash, cb, fdata); +} /* _eet_eina_hash_foreach */ + +/* Internal wrapper for eina_hash */ +static Eina_Hash * +_eet_eina_hash_add(Eina_Hash *hash, + const char *key, + const void *data) +{ + if (!hash) + hash = eina_hash_string_superfast_new(NULL); + + if (!hash) + return NULL; + + eina_hash_add(hash, key, data); + return hash; +} /* _eet_eina_hash_add */ + +static void +_eet_eina_hash_free(Eina_Hash *hash) +{ + if (hash) + eina_hash_free(hash); +} /* _eet_eina_hash_free */ + +void +eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc) +{ + eddc->version = EET_DATA_DESCRIPTOR_CLASS_VERSION; + eddc->func.mem_alloc = NULL; + eddc->func.mem_free = NULL; + eddc->func.str_alloc = NULL; + eddc->func.str_free = NULL; + eddc->func.list_next = (void *)eina_list_next; + eddc->func.list_append = (void *)eina_list_append; + eddc->func.list_data = (void *)eina_list_data_get; + eddc->func.list_free = (void *)eina_list_free; + eddc->func.hash_foreach = (void *)_eet_eina_hash_foreach; + eddc->func.hash_add = (void *)_eet_eina_hash_add; + eddc->func.hash_free = (void *)_eet_eina_hash_free; + eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc; + eddc->func.str_direct_free = (void *)_eet_str_direct_free; + eddc->func.array_alloc = NULL; + eddc->func.array_free = NULL; +} + +void +eet_build_basic_descriptor(Eet_Data_Descriptor *edd) +{ + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "c", + c, + EET_T_CHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "s", + s, + EET_T_SHORT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "i", + i, + EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "l", + l, + EET_T_LONG_LONG); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "str", + str, + EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "istr", + istr, + EET_T_INLINED_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "f1", + f1, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "f2", + f2, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "d", + d, + EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "uc", + uc, + EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "us", + us, + EET_T_USHORT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "ui", + ui, + EET_T_UINT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "ul", + ul, + EET_T_ULONG_LONG); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Basic_Type, + "vp", + vp, + EET_T_VALUE); + + EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "empty", empty, edd); + EET_DATA_DESCRIPTOR_ADD_SUB(edd, Eet_Test_Basic_Type, "with", with, edd); +} + +void +eet_test_basic_check(Eet_Test_Basic_Type *result, + int i, + Eina_Bool dumper) +{ + int test = -1; + float tmp; + + fail_if(result->c != EET_TEST_CHAR); + fail_if(result->s != EET_TEST_SHORT); + fail_if(result->i != EET_TEST_INT + i); + fail_if(result->l != (long long)EET_TEST_LONG_LONG); + fail_if(strcmp(result->str, EET_TEST_STRING) != 0); + fail_if(strcmp(result->istr, EET_TEST_STRING) != 0); + fail_if(result->uc != EET_TEST_CHAR); + fail_if(result->us != EET_TEST_SHORT); + fail_if(result->ui != EET_TEST_INT); + fail_if(result->ul != EET_TEST_LONG_LONG); + if (!dumper) + { + fail_if(result->vp == NULL); + eina_value_get(result->vp, &test); + fail_if(test != EET_TEST_INT + i); + } + else + { + fail_if(result->vp != NULL); + } + + tmp = (result->f1 + EET_TEST_FLOAT); + if (tmp < 0) + tmp = -tmp; + + fail_if(tmp > 0.005); + + tmp = (result->f2 - EET_TEST_FLOAT4); + if (tmp < 0) + tmp = -tmp; + + fail_if(tmp > 0.005); + + tmp = (result->d + EET_TEST_DOUBLE); + if (tmp < 0) + tmp = -tmp; + + fail_if(tmp > 0.00005); + + fail_if(result->empty != NULL); + if (i == 0) + { + Eet_Test_Basic_Type *tmp2; + + tmp2 = result->with; + fail_if(tmp2 == NULL); + + fail_if(tmp2->c != EET_TEST_CHAR); + fail_if(tmp2->s != EET_TEST_SHORT); + fail_if(tmp2->i != EET_TEST_INT + i + 1); + fail_if(tmp2->l != (long long)EET_TEST_LONG_LONG); + fail_if(strcmp(tmp2->str, EET_TEST_STRING) != 0); + fail_if(strcmp(tmp2->istr, EET_TEST_STRING) != 0); + fail_if(tmp2->uc != EET_TEST_CHAR); + fail_if(tmp2->us != EET_TEST_SHORT); + fail_if(tmp2->ui != EET_TEST_INT); + fail_if(tmp2->ul != EET_TEST_LONG_LONG); + fail_if(tmp2->vp != NULL); + } + else + fail_if(result->with != NULL); +} + +void +eet_build_ex_descriptor(Eet_Data_Descriptor *edd, Eina_Bool stream) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Test_Ex_Type etbt; + Eet_Data_Descriptor *eddb; + + if (stream) + { + eet_eina_stream_data_descriptor_class_set(&eddc, + sizeof (Eet_Data_Descriptor_Class), + "Eet_Test_Basic_Type", + sizeof(Eet_Test_Basic_Type)); + eddb = eet_data_descriptor_stream_new(&eddc); + } + else + { + eet_eina_file_data_descriptor_class_set(&eddc, + sizeof (Eet_Data_Descriptor_Class), + "Eet_Test_Basic_Type", + sizeof(Eet_Test_Basic_Type)); + eddb = eet_data_descriptor_file_new(&eddc); + } + fail_if(!eddb); + + eet_build_basic_descriptor(eddb); + + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "c", + c, + EET_T_CHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "s", + s, + EET_T_SHORT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eet_Test_Ex_Type, "i", i, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "l", + l, + EET_T_LONG_LONG); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "str", + str, + EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "istr", + istr, + EET_T_INLINED_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "f1", + f1, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "f2", + f2, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "f3", + f3, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "f4", + f4, + EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "d1", + d1, + EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "d2", + d2, + EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "d3", + d3, + EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "d4", + d4, + EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "uc", + uc, + EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "us", + us, + EET_T_USHORT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "ui", + ui, + EET_T_UINT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd, + Eet_Test_Ex_Type, + "ul", + ul, + EET_T_ULONG_LONG); + EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, + Eet_Test_Ex_Type, + "sarray1", + sarray1, + eddb); + EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, + Eet_Test_Ex_Type, + "varray2", + varray2, + eddb); + eet_data_descriptor_element_add(edd, + "varray1", + EET_T_INT, + EET_G_VAR_ARRAY, + (char *)(&(etbt.varray1)) - (char *)(&(etbt)), + (char *)(&(etbt.varray1_count)) - + (char *)(&(etbt)), + /* 0, */ NULL, + NULL); + eet_data_descriptor_element_add(edd, "sarray2", EET_T_INT, EET_G_ARRAY, + (char *)(&(etbt.sarray2)) - (char *)(&(etbt)), + /* 0, */ sizeof(etbt.sarray2) / + sizeof(etbt.sarray2[0]), NULL, NULL); + eet_data_descriptor_element_add(edd, "charray", EET_T_STRING, EET_G_ARRAY, + (char *)(&(etbt.charray)) - (char *)(&(etbt)), + /* 0, */ sizeof(etbt.charray) / + sizeof(etbt.charray[0]), NULL, NULL); + EET_DATA_DESCRIPTOR_ADD_LIST(edd, Eet_Test_Ex_Type, "list", list, edd); + EET_DATA_DESCRIPTOR_ADD_HASH(edd, Eet_Test_Ex_Type, "hash", hash, edd); + eet_data_descriptor_element_add(edd, "ilist", EET_T_INT, EET_G_LIST, + (char *)(&(etbt.ilist)) - (char *)(&(etbt)), + 0, /* 0, */ NULL, NULL); + eet_data_descriptor_element_add(edd, "ihash", EET_T_INT, EET_G_HASH, + (char *)(&(etbt.ihash)) - (char *)(&(etbt)), + 0, /* 0, */ NULL, NULL); + eet_data_descriptor_element_add(edd, "slist", EET_T_STRING, EET_G_LIST, + (char *)(&(etbt.slist)) - (char *)(&(etbt)), + 0, /* 0, */ NULL, NULL); + eet_data_descriptor_element_add(edd, "shash", EET_T_STRING, EET_G_HASH, + (char *)(&(etbt.shash)) - (char *)(&(etbt)), + 0, /* 0, */ NULL, NULL); +} + +Eet_Test_Ex_Type * +eet_test_ex_set(Eet_Test_Ex_Type *res, + int offset) +{ + unsigned int i; + + if (!res) + res = malloc(sizeof(Eet_Test_Ex_Type)); + + if (!res) + return NULL; + + res->c = EET_TEST_CHAR + offset; + res->s = EET_TEST_SHORT + offset; + res->i = EET_TEST_INT + offset; + res->l = EET_TEST_LONG_LONG + offset; + res->str = EET_TEST_STRING; + res->istr = EET_TEST_STRING; + res->f1 = EET_TEST_FLOAT + offset; + res->f2 = -(EET_TEST_FLOAT2 + offset); + res->f3 = EET_TEST_FLOAT3 + offset; + res->f4 = EET_TEST_FLOAT2 + offset; + res->d1 = EET_TEST_DOUBLE + offset; + res->d2 = -(EET_TEST_DOUBLE2 + offset); + res->d3 = EET_TEST_DOUBLE3 + offset; + res->d4 = EET_TEST_DOUBLE2 + offset; + res->list = NULL; + res->hash = NULL; + res->ilist = NULL; + res->ihash = NULL; + res->slist = NULL; + res->shash = NULL; + for (i = 0; i < sizeof(res->charray) / sizeof(res->charray[0]); ++i) + res->charray[i] = NULL; + + res->varray2 = malloc(sizeof (Eet_Test_Basic_Type) * 10); + res->varray1 = malloc(sizeof (int) * 5); + fail_if(!res->varray1 || !res->varray2); + for (i = 0; i < 10; ++i) + { + eet_test_basic_set(res->sarray1 + i, i); + eet_test_basic_set(res->varray2 + i, i); + } + res->varray2_count = 10; + for (i = 0; i < 5; ++i) + { + res->sarray2[i] = i * 42 + 1; + res->varray1[i] = i * 42 + 1; + } + res->varray1_count = 5; + + res->uc = EET_TEST_CHAR + offset; + res->us = EET_TEST_SHORT + offset; + res->ui = EET_TEST_INT + offset; + res->ul = EET_TEST_LONG_LONG + offset; + + return res; +} + +int +eet_test_ex_check(Eet_Test_Ex_Type *stuff, + int offset, + Eina_Bool dumper) +{ + double tmp; + unsigned int i; + + if (!stuff) + return 1; + + if (stuff->c != EET_TEST_CHAR + offset) + return 1; + + if (stuff->s != EET_TEST_SHORT + offset) + return 1; + + if (stuff->i != EET_TEST_INT + offset) + return 1; + + if (stuff->l != EET_TEST_LONG_LONG + offset) + return 1; + + if (strcmp(stuff->str, EET_TEST_STRING) != 0) + return 1; + + if (strcmp(stuff->istr, EET_TEST_STRING) != 0) + return 1; + + tmp = stuff->f1 - (EET_TEST_FLOAT + offset); + if (tmp < 0) + tmp = -tmp; + + if (tmp > 0.005) + return 1; + + tmp = stuff->d1 - (EET_TEST_DOUBLE + offset); + if (tmp < 0) + tmp = -tmp; + + if (tmp > 0.00005) + return 1; + + if (stuff->f2 != -(EET_TEST_FLOAT2 + offset)) + return 1; + + if (stuff->d2 != -(EET_TEST_DOUBLE2 + offset)) + return 1; + + if (stuff->f3 != EET_TEST_FLOAT3 + offset) + return 1; + + if (stuff->d3 != EET_TEST_DOUBLE3 + offset) + return 1; + + if (stuff->f4 != EET_TEST_FLOAT2 + offset) + return 1; + + if (stuff->d4 != EET_TEST_DOUBLE2 + offset) + return 1; + + if (stuff->uc != EET_TEST_CHAR + offset) + return 1; + + if (stuff->us != EET_TEST_SHORT + offset) + return 1; + + if (stuff->ui != (unsigned int)EET_TEST_INT + offset) + return 1; + + if (stuff->ul != EET_TEST_LONG_LONG + offset) + return 1; + + if (stuff->varray1_count != 5) + return 1; + + if (stuff->varray2_count != 10) + return 1; + + for (i = 0; i < 5; ++i) + if (stuff->sarray2[i] != i * 42 + 1 && stuff->varray1[i] != i * 42 + 1) + return 1; + + for (i = 0; i < 10; ++i) + { + eet_test_basic_check(stuff->sarray1 + i, i, dumper); + eet_test_basic_check(stuff->varray2 + i, i, dumper); + } + + return 0; +} + +void +eet_test_basic_set(Eet_Test_Basic_Type *res, + int i) +{ + res->c = EET_TEST_CHAR; + res->s = EET_TEST_SHORT; + res->i = EET_TEST_INT + i; + res->l = EET_TEST_LONG_LONG; + res->str = EET_TEST_STRING; + res->istr = EET_TEST_STRING; + res->f1 = -EET_TEST_FLOAT; + res->d = -EET_TEST_DOUBLE; + res->f2 = EET_TEST_FLOAT4; + res->uc = EET_TEST_CHAR; + res->us = EET_TEST_SHORT; + res->ui = EET_TEST_INT; + res->ul = EET_TEST_LONG_LONG; + res->empty = NULL; + res->with = NULL; + res->vp = eina_value_new(EINA_VALUE_TYPE_INT); + eina_value_set(res->vp, EET_TEST_INT + i); + + if (i == 0) + { + Eet_Test_Basic_Type *tmp; + + tmp = malloc(sizeof (Eet_Test_Basic_Type)); + fail_if(!tmp); + + res->with = tmp; + tmp->c = EET_TEST_CHAR; + tmp->s = EET_TEST_SHORT; + tmp->i = EET_TEST_INT + i + 1; + tmp->l = EET_TEST_LONG_LONG; + tmp->str = EET_TEST_STRING; + tmp->istr = EET_TEST_STRING; + tmp->f1 = -EET_TEST_FLOAT; + tmp->d = -EET_TEST_DOUBLE; + tmp->f2 = EET_TEST_FLOAT4; + tmp->uc = EET_TEST_CHAR; + tmp->us = EET_TEST_SHORT; + tmp->ui = EET_TEST_INT; + tmp->ul = EET_TEST_LONG_LONG; + tmp->empty = NULL; + tmp->with = NULL; + tmp->vp = NULL; + } +} diff --git a/src/tests/eet/eet_test_common.h b/src/tests/eet/eet_test_common.h new file mode 100644 index 0000000000..e95b7e5b01 --- /dev/null +++ b/src/tests/eet/eet_test_common.h @@ -0,0 +1,139 @@ +#ifndef EET_TEST_COMMON_H +#define EET_TEST_COMMON_H + +#define EET_TEST_CHAR 0x42 +#define EET_TEST_SHORT 0x4224 +#define EET_TEST_INT 0x42211224 +#define EET_TEST_LONG_LONG 0x84CB42211224BC48 +#define EET_TEST_STRING "my little test with escape \\\"" +#define EET_TEST_KEY1 "key1" +#define EET_TEST_KEY2 "key2" +#define EET_TEST_FLOAT 123.45689 +#define EET_TEST_FLOAT2 1.0 +#define EET_TEST_FLOAT3 0.25 +#define EET_TEST_FLOAT4 0.0001234 +#define EET_TEST_DOUBLE 123456789.9876543210 +#define EET_TEST_DOUBLE2 1.0 +#define EET_TEST_DOUBLE3 0.25 +#define EET_TEST_FILE_KEY1 "keys/data/1" +#define EET_TEST_FILE_KEY2 "keys/data/2" +#define EET_TEST_FILE_IMAGE "keys/images/" + +typedef struct _Eet_Test_Basic_Type Eet_Test_Basic_Type; +struct _Eet_Test_Basic_Type +{ + char c; + short s; + int i; + long long l; + char *str; + char *istr; + float f1; + float f2; + double d; + unsigned char uc; + unsigned short us; + unsigned int ui; + unsigned long long ul; + Eina_Value *vp; + Eet_Test_Basic_Type *empty; + Eet_Test_Basic_Type *with; +}; + +typedef struct _Eet_Test_Ex_Type Eet_Test_Ex_Type; +struct _Eet_Test_Ex_Type +{ + char c; + short s; + int i; + unsigned long long l; + char *str; + char *istr; + float f1; + float f2; + float f3; + float f4; + double d1; + double d2; + double d3; + double d4; + Eina_List *list; + Eina_Hash *hash; + Eina_List *ilist; + Eina_List *slist; + Eina_Hash *ihash; + Eina_Hash *shash; + Eet_Test_Basic_Type sarray1[10]; + unsigned int sarray2[5]; + unsigned int varray1_count; + unsigned int *varray1; + unsigned int varray2_count; + Eet_Test_Basic_Type *varray2; + unsigned char uc; + unsigned short us; + unsigned int ui; + unsigned long long ul; + char *charray[10]; +}; + +typedef struct _Eet_5FP Eet_5FP; +struct _Eet_5FP +{ + Eina_F32p32 fp32; + Eina_F16p16 fp16; + Eina_F8p24 fp8; + Eina_F32p32 f1; + Eina_F32p32 f0; +}; + +typedef struct _Eet_5DBL Eet_5DBL; +struct _Eet_5DBL +{ + double fp32; + double fp16; + float fp8; + double f1; + double f0; +}; + +extern char argv0[PATH_MAX]; +extern int i42; +extern int i7; +extern Eina_Bool _dump_call; + +void append_string(void *data, + const char *str); + +void append_strbuf_string(void *data, const char *string); + +Eina_Bool func(EINA_UNUSED const Eina_Hash *hash, + const void *key, + void *data, + void *fdata); + +Eina_Bool func7(EINA_UNUSED const Eina_Hash *hash, + EINA_UNUSED const void *key, + void *data, + void *fdata); + +void eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc); + +void eet_build_basic_descriptor(Eet_Data_Descriptor *edd); + +void eet_test_basic_check(Eet_Test_Basic_Type *result, + int i, + Eina_Bool dumper); + +void eet_build_ex_descriptor(Eet_Data_Descriptor *edd, Eina_Bool stream); + +Eet_Test_Ex_Type *eet_test_ex_set(Eet_Test_Ex_Type *res, + int offset); + +int eet_test_ex_check(Eet_Test_Ex_Type *stuff, + int offset, + Eina_Bool dumper); + +void eet_test_basic_set(Eet_Test_Basic_Type *res, + int i); + +#endif diff --git a/src/tests/eet/eet_test_connection.c b/src/tests/eet/eet_test_connection.c new file mode 100644 index 0000000000..28c3d5d559 --- /dev/null +++ b/src/tests/eet/eet_test_connection.c @@ -0,0 +1,150 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +typedef struct _Eet_Connection_Data Eet_Connection_Data; +struct _Eet_Connection_Data +{ + Eet_Connection *conn; + Eet_Data_Descriptor *edd; + Eina_Bool test; +}; + +static Eina_Bool +_eet_connection_read(const void *eet_data, + size_t size, + void *user_data) +{ + Eet_Connection_Data *dt = user_data; + Eet_Test_Ex_Type *result; + Eet_Node *node; + int test; + + result = eet_data_descriptor_decode(dt->edd, eet_data, size); + node = eet_data_node_decode_cipher(eet_data, NULL, size); + + /* Test the resulting data. */ + fail_if(!node); + fail_if(eet_test_ex_check(result, 0, _dump_call) != 0); + fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, _dump_call) != 0); + fail_if(eina_list_data_get(result->ilist) == NULL); + fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); + fail_if(eina_list_data_get(result->slist) == NULL); + fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); + fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); + fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); + fail_if(strcmp(result->charray[0], "test") != 0); + + test = 0; + if (result->hash) + eina_hash_foreach(result->hash, func, &test); + + fail_if(test != 0); + if (result->ihash) + eina_hash_foreach(result->ihash, func7, &test); + + fail_if(test != 0); + + if (!dt->test) + { + dt->test = EINA_TRUE; + _dump_call = EINA_TRUE; + fail_if(!eet_connection_node_send(dt->conn, node, NULL)); + _dump_call = EINA_FALSE; + } + + return EINA_TRUE; +} + +static Eina_Bool +_eet_connection_write(const void *data, + size_t size, + void *user_data) +{ + Eet_Connection_Data *dt = user_data; + int still; + + if (!dt->test) + { + int step = size / 3; + + eet_connection_received(dt->conn, data, step); + eet_connection_received(dt->conn, (char *)data + step, step); + size -= 2 * step; + still = eet_connection_received(dt->conn, (char *)data + 2 * step, size); + } + else + still = eet_connection_received(dt->conn, data, size); + + fail_if(still); + + return EINA_TRUE; +} + +START_TEST(eet_test_connection_check) +{ + Eet_Data_Descriptor *edd; + Eet_Data_Descriptor_Class eddc; + Eet_Connection_Data ecd; + Eet_Test_Ex_Type etbt; + Eina_Bool on_going; + + eet_init(); + + eet_test_ex_set(&etbt, 0); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); + eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2)); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); + eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); + etbt.slist = eina_list_prepend(NULL, "test"); + etbt.shash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); + memset(&etbt.charray, 0, sizeof(etbt.charray)); + etbt.charray[0] = "test"; + + eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), + "Eet_Test_Ex_Type", + sizeof(Eet_Test_Ex_Type)); + + edd = eet_data_descriptor_stream_new(&eddc); + fail_if(!edd); + + eet_build_ex_descriptor(edd, EINA_TRUE); + + /* Init context. */ + ecd.test = EINA_FALSE; + ecd.edd = edd; + + /* Create a connection. */ + ecd.conn = eet_connection_new(_eet_connection_read, _eet_connection_write, &ecd); + fail_if(!ecd.conn); + + /* Test the connection. */ + fail_if(!eet_connection_send(ecd.conn, edd, &etbt, NULL)); + + fail_if(!ecd.test); + + fail_if(!eet_connection_close(ecd.conn, &on_going)); + + fail_if(on_going); + + eet_shutdown(); +} +END_TEST + +void eet_test_connection(TCase *tc) +{ + tcase_add_test(tc, eet_test_connection_check); +} diff --git a/src/tests/eet/eet_test_data.c b/src/tests/eet/eet_test_data.c new file mode 100644 index 0000000000..60ec02761c --- /dev/null +++ b/src/tests/eet/eet_test_data.c @@ -0,0 +1,764 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +typedef struct _Eet_Union_Test Eet_Union_Test; +typedef struct _Eet_Variant_Test Eet_Variant_Test; +typedef struct _Eet_Variant_Type Eet_Variant_Type; +typedef struct _Eet_Inherit_Test1 Eet_Inherit_Test1; +typedef struct _Eet_Inherit_Test2 Eet_Inherit_Test2; +typedef struct _Eet_Inherit_Test3 Eet_Inherit_Test3; +typedef struct _Eet_St1 Eet_St1; +typedef struct _Eet_St2 Eet_St2; +typedef struct _Eet_St3 Eet_St3; +typedef struct _Eet_List Eet_List; + +typedef enum _Eet_Union +{ + EET_UNKNOWN, + EET_ST1, + EET_ST2, + EET_ST3 +} Eet_Union; + +struct +{ + Eet_Union u; + const char *name; +} eet_mapping[] = { + { EET_ST1, "ST1" }, + { EET_ST2, "ST2" }, + { EET_ST3, "ST3" }, + { EET_UNKNOWN, NULL } +}; + +struct _Eet_St1 +{ + double val1; + int stuff; + char *s1; +}; + +struct _Eet_St2 +{ + Eina_Bool b1; + unsigned long long v1; +}; + +struct _Eet_St3 +{ + int boby; +}; + +struct _Eet_Union_Test +{ + Eet_Union type; + + union { + Eet_St1 st1; + Eet_St2 st2; + Eet_St3 st3; + } u; +}; + +struct _Eet_Variant_Type +{ + const char *type; + Eina_Bool unknow : 1; +}; + +struct _Eet_Variant_Test +{ + Eet_Variant_Type t; + + void *data; + Eina_List *data_list; +}; + +struct _Eet_Inherit_Test1 +{ + Eet_Union type; + Eet_St1 st1; +}; +struct _Eet_Inherit_Test2 +{ + Eet_Union type; + Eet_St2 st2; +}; +struct _Eet_Inherit_Test3 +{ + Eet_Union type; + Eet_St3 st3; +}; + +struct _Eet_List +{ + Eina_List *list; +}; + +static const char * +_eet_union_type_get(const void *data, + Eina_Bool *unknow) +{ + const Eet_Union *u = data; + int i; + + if (unknow) + *unknow = EINA_FALSE; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (*u == eet_mapping[i].u) + return eet_mapping[i].name; + + if (unknow) + *unknow = EINA_TRUE; + + return NULL; +} /* _eet_union_type_get */ + +static Eina_Bool +_eet_union_type_set(const char *type, + void *data, + Eina_Bool unknow) +{ + Eet_Union *u = data; + int i; + + if (unknow) + return EINA_FALSE; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (strcmp(eet_mapping[i].name, type) == 0) + { + *u = eet_mapping[i].u; + return EINA_TRUE; + } + + return EINA_FALSE; +} /* _eet_union_type_set */ + +static const char * +_eet_variant_type_get(const void *data, + Eina_Bool *unknow) +{ + const Eet_Variant_Type *type = data; + int i; + + if (unknow) + *unknow = type->unknow; + + for (i = 0; eet_mapping[i].name != NULL; ++i) + if (strcmp(type->type, eet_mapping[i].name) == 0) + return eet_mapping[i].name; + + if (unknow) + *unknow = EINA_FALSE; + + return type->type; +} /* _eet_variant_type_get */ + +static Eina_Bool +_eet_variant_type_set(const char *type, + void *data, + Eina_Bool unknow) +{ + Eet_Variant_Type *vt = data; + + vt->type = type; + vt->unknow = unknow; + return EINA_TRUE; +} /* _eet_variant_type_set */ + +static Eet_Data_Descriptor * +_eet_st1_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St1); + res = eet_data_descriptor_stream_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "val1", val1, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "stuff", stuff, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St1, "s1", s1, EET_T_STRING); + + return res; +} /* _eet_st1_dd */ + +static void +_eet_st1_set(Eet_St1 *st1, + int i) +{ + st1->val1 = EET_TEST_DOUBLE; + st1->stuff = EET_TEST_INT + i; + st1->s1 = EET_TEST_STRING; +} /* _eet_st1_set */ + +static void +_eet_st1_cmp(Eet_St1 *st1, + int i) +{ + double tmp; + + fail_if(!st1); + + tmp = st1->val1 - EET_TEST_DOUBLE; + if (tmp < 0) + tmp = -tmp; + + fail_if(tmp > 0.005); + fail_if(st1->stuff != EET_TEST_INT + i); + fail_if(strcmp(st1->s1, EET_TEST_STRING)); +} /* _eet_st1_cmp */ + +static Eet_Data_Descriptor * +_eet_st2_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St2); + res = eet_data_descriptor_stream_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "b1", b1, EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St2, "v1", v1, EET_T_ULONG_LONG); + + return res; +} /* _eet_st2_dd */ + +static void +_eet_st2_set(Eet_St2 *st2, + int i) +{ + st2->b1 = EINA_TRUE; + st2->v1 = EET_TEST_LONG_LONG + i; +} /* _eet_st2_set */ + +static void +_eet_st2_cmp(Eet_St2 *st2, + int i) +{ + fail_if(!st2->b1); + fail_if(st2->v1 != EET_TEST_LONG_LONG + i); +} /* _eet_st2_cmp */ + +static Eet_Data_Descriptor * +_eet_st3_dd(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *res; + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_St3); + res = eet_data_descriptor_stream_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC(res, Eet_St3, "boby", boby, EET_T_INT); + + return res; +} /* _eet_st3_dd */ + +static void +_eet_st3_set(Eet_St3 *st3, + int i) +{ + st3->boby = EET_TEST_INT + i; +} /* _eet_st3_set */ + +static void +_eet_st3_cmp(Eet_St3 *st3, + int i) +{ + fail_if(st3->boby != EET_TEST_INT + i); +} /* _eet_st3_cmp */ + +START_TEST(eet_test_data_basic_type_encoding_decoding) +{ + Eet_Data_Descriptor *edd; + Eet_Test_Basic_Type *result; + Eet_Data_Descriptor_Class eddc; + Eet_Test_Basic_Type etbt; + void *transfert; + int size; + + eet_init(); + + eet_test_basic_set(&etbt, 0); + + eet_test_setup_eddc(&eddc); + eddc.name = "Eet_Test_Basic_Type"; + eddc.size = sizeof(Eet_Test_Basic_Type); + + edd = eet_data_descriptor_stream_new(&eddc); + fail_if(!edd); + + eet_build_basic_descriptor(edd); + + transfert = eet_data_descriptor_encode(edd, &etbt, &size); + fail_if(!transfert || size <= 0); + + result = eet_data_descriptor_decode(edd, transfert, size); + fail_if(!result); + + eet_test_basic_check(result, 0, EINA_FALSE); + + free(result->str); + free(result); + + eet_data_descriptor_free(edd); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_type_encoding_decoding) +{ + Eet_Data_Descriptor *edd; + Eet_Test_Ex_Type *result; + void *transfert; + Eet_Data_Descriptor_Class eddc; + Eet_Test_Ex_Type etbt; + int size; + int test; + + eet_init(); + + eet_test_ex_set(&etbt, 0); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); + etbt.slist = eina_list_prepend(NULL, "test"); + etbt.shash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); + memset(&etbt.charray, 0, sizeof(etbt.charray)); + etbt.charray[0] = "test"; + etbt.charray[5] = "plouf"; + + eet_test_setup_eddc(&eddc); + eddc.name = "Eet_Test_Ex_Type"; + eddc.size = sizeof(Eet_Test_Ex_Type); + + edd = eet_data_descriptor_file_new(&eddc); + fail_if(!edd); + + eet_build_ex_descriptor(edd, EINA_FALSE); + + transfert = eet_data_descriptor_encode(edd, &etbt, &size); + fail_if(!transfert || size <= 0); + + result = eet_data_descriptor_decode(edd, transfert, size); + fail_if(!result); + + fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0); + fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0); + fail_if(eina_list_data_get(result->ilist) == NULL); + fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); + fail_if(eina_list_data_get(result->slist) == NULL); + fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); + fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); + fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); + fail_if(strcmp(result->charray[0], "test") != 0); + fail_if(strcmp(result->charray[5], "plouf") != 0); + + test = 0; + if (result->hash) + eina_hash_foreach(result->hash, func, &test); + + fail_if(test != 0); + if (result->ihash) + eina_hash_foreach(result->ihash, func7, &test); + + fail_if(test != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_type_dump_undump) +{ + Eet_Data_Descriptor *edd; + Eet_Test_Ex_Type *result; + Eet_Data_Descriptor_Class eddc; + Eet_Test_Ex_Type etbt; + char *transfert1; + char *transfert2; + char *string1; + char *string2; + int size1; + int size2; + int test; + + eet_init(); + + eet_test_ex_set(&etbt, 0); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2)); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); + etbt.slist = eina_list_prepend(NULL, "test"); + etbt.shash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); + memset(&etbt.charray, 0, sizeof(etbt.charray)); + etbt.charray[0] = "test"; + + eet_test_setup_eddc(&eddc); + eddc.name = "Eet_Test_Ex_Type"; + eddc.size = sizeof(Eet_Test_Ex_Type); + + edd = eet_data_descriptor_file_new(&eddc); + fail_if(!edd); + + eet_build_ex_descriptor(edd, EINA_FALSE); + + transfert1 = eet_data_descriptor_encode(edd, &etbt, &size1); + fail_if(!transfert1 || size1 <= 0); + + string1 = NULL; + eet_data_text_dump(transfert1, size1, append_string, &string1); + fail_if(!string1); + + transfert2 = eet_data_text_undump(string1, string1 ? strlen( + string1) : 0, &size2); + fail_if(!transfert2 && size2 <= 0); + + string2 = NULL; + eet_data_text_dump(transfert2, size2, append_string, &string2); + fail_if(!string2); + + fail_if(strlen(string2) != strlen(string1)); + + result = eet_data_descriptor_decode(edd, transfert2, size2); + fail_if(!result); + + fail_if(eet_test_ex_check(result, 0, EINA_TRUE) != 0); + fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0); + fail_if(eina_list_data_get(result->ilist) == NULL); + fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); + fail_if(eina_list_data_get(result->slist) == NULL); + fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); + fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); + fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); + fail_if(strcmp(result->charray[0], "test") != 0); + + test = 0; + _dump_call = EINA_TRUE; + if (result->hash) + eina_hash_foreach(result->hash, func, &test); + _dump_call = EINA_FALSE; + + fail_if(test != 0); + if (result->ihash) + eina_hash_foreach(result->ihash, func7, &test); + + fail_if(test != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_type_escape_dump_undump) +{ + void *blob; + int blob_len; + int ret = 0; + const char *outputstr; + Eina_Strbuf *strbuf; + const char inputstr[] = "" + "group \"\\\\My\\\"Group\\\\\" struct {\n" + " value \"\\\\My\\\\BackSlash\\\\\" string: \"\\\\\";\n" + " value \"\\\\My\\\\DoubleQuote\\\\\" string: \"\\\"\";\n" + " value \"\\\\My\\\\NewLine\\\\\" string: \"\\n\";\n" + "}\n"; + + eet_init(); + + blob = eet_data_text_undump(inputstr, strlen(inputstr), &blob_len); + fail_if(!blob); + + strbuf = eina_strbuf_new(); + ret = eet_data_text_dump(blob, blob_len, append_strbuf_string, strbuf); + ck_assert_int_eq(ret, 1); + + outputstr = eina_strbuf_string_get(strbuf); + fail_if(!outputstr); + ck_assert_str_eq(inputstr, outputstr); + + eina_strbuf_free(strbuf); + free(blob); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_fp) +{ + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *edd_5FP; + Eet_Data_Descriptor *edd_5DBL; + Eet_5FP origin; + Eet_5DBL *convert; + Eet_5FP *build; + void *blob; + int size; + + eet_init(); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP); + edd_5FP = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32); + + eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL)); + edd_5DBL = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE); + + origin.fp32 = eina_f32p32_double_from(1.125); + origin.fp16 = eina_f16p16_int_from(2000); + origin.fp8 = eina_f8p24_int_from(125); + origin.f1 = eina_f32p32_int_from(1); + origin.f0 = 0; + + blob = eet_data_descriptor_encode(edd_5FP, &origin, &size); + fail_if(!blob || size <= 0); + + build = eet_data_descriptor_decode(edd_5FP, blob, size); + fail_if(!build); + + convert = eet_data_descriptor_decode(edd_5DBL, blob, size); + fail_if(!convert); + + fail_if(build->fp32 != eina_f32p32_double_from(1.125)); + fail_if(build->fp16 != eina_f16p16_int_from(2000)); + fail_if(build->fp8 != eina_f8p24_int_from(125)); + fail_if(build->f1 != eina_f32p32_int_from(1)); + fail_if(build->f0 != 0); + + fail_if(convert->fp32 != 1.125); + fail_if(convert->fp16 != 2000); + fail_if(convert->fp8 != 125); + fail_if(convert->f1 != 1); + fail_if(convert->f0 != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_union) +{ + Eet_Union_Test *eut; + Eet_List *l; + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *edd; + Eet_Data_Descriptor *unified; + Eet_Data_Descriptor *m; + void *blob; + int size; + int i; + + eina_init(); + eet_init(); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test); + edd = eet_data_descriptor_stream_new(&eddc); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Union_Test); + m = eet_data_descriptor_stream_new(&eddc); + + eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; + eddc.func.type_get = _eet_union_type_get; + eddc.func.type_set = _eet_union_type_set; + unified = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd()); + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd()); + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd()); + + EET_DATA_DESCRIPTOR_ADD_UNION(edd, Eet_Union_Test, "u", u, type, unified); + + EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd); + + l = calloc(1, sizeof (Eet_List)); + +#define EUT_NEW(Type_Index) \ + eut = calloc(1, sizeof (Eet_Union_Test)); \ + eut->type = EET_ST ## Type_Index; \ + _eet_st ## Type_Index ## _set(&(eut->u.st ## Type_Index), i); + + for (i = 0; i < 3; ++i) + { + EUT_NEW(1); + l->list = eina_list_append(l->list, eut); + + EUT_NEW(2); + l->list = eina_list_append(l->list, eut); + + EUT_NEW(3); + l->list = eina_list_append(l->list, eut); + } + + blob = eet_data_descriptor_encode(m, l, &size); + fail_if(!blob || size <= 0); + + l = eet_data_descriptor_decode(m, blob, size); + fail_if(!l); + + fail_if(eina_list_count(l->list) != 9); + +#define EUT_CMP(Type_Index) \ + eut = eina_list_nth(l->list, i * 3 + Type_Index - 1); \ + fail_if(eut->type != EET_ST ## Type_Index); \ + _eet_st ## Type_Index ## _cmp(&(eut->u.st ## Type_Index), i); + + for (i = 0; i < 3; ++i) + { + EUT_CMP(1); + EUT_CMP(2); + EUT_CMP(3); + } + + eet_shutdown(); + eina_shutdown(); +} +END_TEST + +START_TEST(eet_test_data_variant) +{ + Eet_Variant_Test *evt; + Eet_List *l; + Eet_St1 *st1; + Eet_St2 *st2; + Eet_St3 *st3; + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *edd; + Eet_Data_Descriptor *unified; + Eet_Data_Descriptor *m; + void *blob; + int size; + int i; + + eina_init(); + eet_init(); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test); + edd = eet_data_descriptor_stream_new(&eddc); + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Variant_Test); + m = eet_data_descriptor_stream_new(&eddc); + + eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION; + eddc.func.type_get = _eet_variant_type_get; + eddc.func.type_set = _eet_variant_type_set; + unified = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST1", _eet_st1_dd()); + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST2", _eet_st2_dd()); + EET_DATA_DESCRIPTOR_ADD_MAPPING(unified, "ST3", _eet_st3_dd()); + + EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, + Eet_Variant_Test, + "data", + data, + t, + unified); + + unified = eet_data_descriptor_stream_new(&eddc); + eet_data_descriptor_element_add(unified, "ST1", + EET_T_UNKNOW, EET_G_LIST, + 0, 0, NULL, _eet_st1_dd()); + eet_data_descriptor_element_add(unified, "ST2", + EET_T_UNKNOW, EET_G_LIST, + 0, 0, NULL, _eet_st2_dd()); + + EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, Eet_Variant_Test, + "data_list", data_list, t, unified); + + EET_DATA_DESCRIPTOR_ADD_LIST(m, Eet_List, "list", list, edd); + + l = calloc(1, sizeof (Eet_List)); + +#define EVT_NEW(Type_Index) \ + evt = calloc(1, sizeof (Eet_Variant_Test)); \ + evt->t.type = eet_mapping[Type_Index - 1].name; \ + st ## Type_Index = calloc(1, sizeof (Eet_St ## Type_Index)); \ + _eet_st ## Type_Index ## _set(st ## Type_Index, i); \ + evt->data = st ## Type_Index; + + for (i = 0; i < 3; ++i) + { + EVT_NEW(1); + l->list = eina_list_append(l->list, evt); + + st1 = calloc(1, sizeof (Eet_St1)); + _eet_st1_set(st1, i); + evt->data_list = eina_list_append(evt->data_list, st1); + + EVT_NEW(2); + l->list = eina_list_append(l->list, evt); + + EVT_NEW(3); + l->list = eina_list_append(l->list, evt); + } + + blob = eet_data_descriptor_encode(m, l, &size); + fail_if(!blob || size <= 0); + + l = eet_data_descriptor_decode(m, blob, size); + fail_if(!l); + + fail_if(eina_list_count(l->list) != 9); + +#define EVT_CMP(Type_Index) \ + evt = eina_list_nth(l->list, i * 3 + Type_Index - 1); \ + fail_if(strcmp(evt->t.type, eet_mapping[Type_Index - 1].name) != 0); \ + _eet_st ## Type_Index ## _cmp(evt->data, i); + + for (i = 0; i < 3; ++i) + { + EVT_CMP(1); + + fail_if(!evt->data_list); + fail_if(eina_list_count(evt->data_list) != 1); + + st1 = eina_list_data_get(evt->data_list); + _eet_st1_cmp(st1, i); + + EVT_CMP(2); + EVT_CMP(3); + } + + eet_shutdown(); + eina_shutdown(); +} /* START_TEST */ +END_TEST + +void eet_test_data(TCase *tc) +{ + tcase_add_test(tc, eet_test_data_basic_type_encoding_decoding); + tcase_add_test(tc, eet_test_data_type_encoding_decoding); + tcase_add_test(tc, eet_test_data_type_dump_undump); + tcase_add_test(tc, eet_test_data_type_escape_dump_undump); + tcase_add_test(tc, eet_test_data_fp); + tcase_add_test(tc, eet_test_data_union); + tcase_add_test(tc, eet_test_data_variant); +} diff --git a/src/tests/eet/eet_test_file.c b/src/tests/eet/eet_test_file.c new file mode 100644 index 0000000000..2c9efb6cb4 --- /dev/null +++ b/src/tests/eet/eet_test_file.c @@ -0,0 +1,427 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +START_TEST(eet_test_file_simple_write) +{ + const char *buffer = "Here is a string of data to save !"; + Eet_File *ef; + char *test; + char *file; + int size; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID); + + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + + fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1)); + fail_if(!eet_alias(ef, "keys/alias", "keys/tests", 0)); + fail_if(!eet_alias(ef, "keys/alias2", "keys/alias", 1)); + + fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE); + + fail_if(eet_list(ef, "*", &size) != NULL); + fail_if(eet_num_entries(ef) != -1); + + eet_close(ef); + + /* Test read of simple file */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + test = eet_read(ef, "keys/tests", &size); + fail_if(!test); + fail_if(size != (int)strlen(buffer) + 1); + + fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); + + test = eet_read(ef, "keys/alias2", &size); + fail_if(!test); + fail_if(size != (int)strlen(buffer) + 1); + + fail_if(eet_read_direct(ef, "key/alias2", &size)); + + fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ); + fail_if(eet_num_entries(ef) != 3); + + eet_close(ef); + + /* Test eet cache system */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + test = eet_read(ef, "keys/tests", &size); + fail_if(!test); + fail_if(size != (int)strlen(buffer) + 1); + + fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_file_data) +{ + Eet_Data_Descriptor *edd; + Eet_Test_Ex_Type *result; + Eet_Dictionary *ed; + Eet_File *ef; + char **list; + char *file; + Eet_Data_Descriptor_Class eddc; + Eet_Test_Ex_Type etbt; + int size; + int test; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + eet_test_ex_set(&etbt, 0); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2)); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); + etbt.slist = eina_list_prepend(NULL, "test"); + etbt.shash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); + memset(&etbt.charray, 0, sizeof(etbt.charray)); + etbt.charray[0] = "test"; + + eet_test_setup_eddc(&eddc); + eddc.name = "Eet_Test_Ex_Type"; + eddc.size = sizeof(Eet_Test_Ex_Type); + + edd = eet_data_descriptor_file_new(&eddc); + fail_if(!edd); + + eet_build_ex_descriptor(edd, EINA_FALSE); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + /* Insert an error in etbt. */ + etbt.i = 0; + + /* Save the encoded data in a file. */ + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); + + result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); + fail_if(!result); + + fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE); + + /* Test string space. */ + ed = eet_dictionary_get(ef); + + fail_if(!eet_dictionary_string_check(ed, result->str)); + fail_if(eet_dictionary_string_check(ed, result->istr)); + + eet_close(ef); + + /* Attempt to replace etbt by the correct one. */ + etbt.i = EET_TEST_INT; + + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); + + result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); + fail_if(!result); + + /* Test the resulting data. */ + fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0); + + eet_close(ef); + + /* Read back the data. */ + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0)); + + result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); + fail_if(!result); + + /* Test string space. */ + ed = eet_dictionary_get(ef); + fail_if(!ed); + + fail_if(!eet_dictionary_string_check(ed, result->str)); + fail_if(eet_dictionary_string_check(ed, result->istr)); + + /* Test the resulting data. */ + fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0); + fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0); + fail_if(eina_list_data_get(result->ilist) == NULL); + fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); + fail_if(eina_list_data_get(result->slist) == NULL); + fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); + fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); + fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); + fail_if(strcmp(result->charray[0], "test") != 0); + + test = 0; + if (result->hash) + eina_hash_foreach(result->hash, func, &test); + + fail_if(test != 0); + if (result->ihash) + eina_hash_foreach(result->ihash, func7, &test); + + fail_if(test != 0); + + list = eet_list(ef, "keys/*", &size); + fail_if(eet_num_entries(ef) != 2); + fail_if(size != 2); + fail_if(!(strcmp(list[0], + EET_TEST_FILE_KEY1) == 0 && + strcmp(list[1], EET_TEST_FILE_KEY2) == 0) + && !(strcmp(list[0], + EET_TEST_FILE_KEY2) == 0 && + strcmp(list[1], EET_TEST_FILE_KEY1) == 0)); + free(list); + + fail_if(eet_delete(ef, NULL) != 0); + fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0); + fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0); + + list = eet_list(ef, "keys/*", &size); + fail_if(size != 1); + fail_if(eet_num_entries(ef) != 1); + + /* Test some more wrong case */ + fail_if(eet_data_read(ef, edd, "plop") != NULL); + fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL); + + /* Reinsert and reread data */ + fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); + fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL); + fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_file_data_dump) +{ + Eet_Data_Descriptor *edd; + Eet_Test_Ex_Type *result; + Eet_Data_Descriptor_Class eddc; + Eet_Test_Ex_Type etbt; + Eet_File *ef; + char *string1; + char *file; + int test; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + eet_test_ex_set(&etbt, 0); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); + etbt.hash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); + eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2)); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ilist = eina_list_prepend(etbt.ilist, &i42); + etbt.ihash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); + eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); + etbt.slist = eina_list_prepend(NULL, "test"); + etbt.shash = eina_hash_string_superfast_new(NULL); + eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); + memset(&etbt.charray, 0, sizeof(etbt.charray)); + etbt.charray[0] = "test"; + + eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), + "Eet_Test_Ex_Type", + sizeof(Eet_Test_Ex_Type)); + + edd = eet_data_descriptor_file_new(&eddc); + fail_if(!edd); + + eet_build_ex_descriptor(edd, EINA_FALSE); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + /* Save the encoded data in a file. */ + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + + fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); + + eet_close(ef); + + /* Use dump/undump in the middle */ + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + string1 = NULL; + fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1); + fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0); + fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1)); + + eet_close(ef); + + /* Test the correctness of the reinsertion. */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); + fail_if(!result); + + eet_close(ef); + + /* Test the resulting data. */ + fail_if(eet_test_ex_check(result, 0, EINA_TRUE) != 0); + fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0); + fail_if(eina_list_data_get(result->ilist) == NULL); + fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); + fail_if(eina_list_data_get(result->slist) == NULL); + fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); + fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); + fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); + fail_if(strcmp(result->charray[0], "test") != 0); + + test = 0; + _dump_call = EINA_TRUE; + if (result->hash) + eina_hash_foreach(result->hash, func, &test); + _dump_call = EINA_FALSE; + + fail_if(test != 0); + if (result->ihash) + eina_hash_foreach(result->ihash, func7, &test); + + fail_if(test != 0); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_file_fp) +{ + char *file; + Eet_Data_Descriptor_Class eddc; + Eet_Data_Descriptor *edd_5FP; + Eet_Data_Descriptor *edd_5DBL; + Eet_File *ef; + Eet_5FP origin; + Eet_5DBL *convert; + Eet_5FP *build; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP); + edd_5FP = eet_data_descriptor_file_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32); + + eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL)); + edd_5DBL = eet_data_descriptor_file_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE); + + origin.fp32 = eina_f32p32_double_from(1.125); + origin.fp16 = eina_f16p16_int_from(2000); + origin.fp8 = eina_f8p24_int_from(125); + origin.f1 = eina_f32p32_int_from(1); + origin.f0 = 0; + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1)); + + build = eet_data_read(ef, edd_5FP, EET_TEST_FILE_KEY1); + fail_if(!build); + + convert = eet_data_read(ef, edd_5DBL, EET_TEST_FILE_KEY1); + fail_if(!convert); + + fail_if(build->fp32 != eina_f32p32_double_from(1.125)); + fail_if(build->fp16 != eina_f16p16_int_from(2000)); + fail_if(build->fp8 != eina_f8p24_int_from(125)); + fail_if(build->f1 != eina_f32p32_int_from(1)); + fail_if(build->f0 != 0); + + fail_if(convert->fp32 != 1.125); + fail_if(convert->fp16 != 2000); + fail_if(convert->fp8 != 125); + fail_if(convert->f1 != 1); + fail_if(convert->f0 != 0); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +void eet_test_file(TCase *tc) +{ + tcase_add_test(tc, eet_test_file_simple_write); + tcase_add_test(tc, eet_test_file_data); + tcase_add_test(tc, eet_test_file_data_dump); + tcase_add_test(tc, eet_test_file_fp); +} diff --git a/src/tests/eet/eet_test_identity.c b/src/tests/eet/eet_test_identity.c new file mode 100644 index 0000000000..4e445d546f --- /dev/null +++ b/src/tests/eet/eet_test_identity.c @@ -0,0 +1,248 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + +static char _key_pem[PATH_MAX] = ""; +static char _cert_pem[PATH_MAX] = ""; +static char _key_enc[PATH_MAX] = ""; +static char _key_enc_pem[PATH_MAX] = ""; +static char _key_enc_none_pem[PATH_MAX] = ""; + +static int +pass_get(char *pass, + int size, + EINA_UNUSED int rwflags, + EINA_UNUSED void *u) +{ + memset(pass, 0, size); + + if ((int)strlen("password") > size) + return 0; + + snprintf(pass, size, "%s", "password"); + return strlen(pass); +} + +static int +badpass_get(char *pass, + int size, + EINA_UNUSED int rwflags, + EINA_UNUSED void *u) +{ + memset(pass, 0, size); + + if ((int)strlen("bad password") > size) + return 0; + + snprintf(pass, size, "%s", "bad password"); + return strlen(pass); +} + +START_TEST(eet_test_identity_simple) +{ + const char *buffer = "Here is a string of data to save !"; + const void *tmp; + Eet_File *ef; + Eet_Key *k; + FILE *noread; + char *test; + char *file; + int size; + int fd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + fail_if(-1 == (fd = mkstemp(file))); + fail_if(!!close(fd)); + fail_if(!(noread = fopen("/dev/null", "wb"))); + + /* Sign an eet file. */ + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + + fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); + + k = eet_identity_open(_cert_pem, _key_pem, NULL); + fail_if(!k); + + fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE); + eet_identity_print(k, noread); + + eet_close(ef); + + /* Open a signed file. */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + /* check that the certificates match */ + fail_if(!eet_identity_verify(ef, _cert_pem)); + + test = eet_read(ef, "keys/tests", &size); + fail_if(!test); + fail_if(size != (int)strlen(buffer) + 1); + + fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0); + + tmp = eet_identity_x509(ef, &size); + fail_if(tmp == NULL); + + eet_identity_certificate_print(tmp, size, noread); + + eet_close(ef); + + /* As we are changing file contain in less than 1s, this could get unnoticed + by eet cache system. */ + eet_clearcache(); + + /* Corrupting the file. */ + fd = open(file, O_WRONLY | O_BINARY); + fail_if(fd < 0); + + fail_if(lseek(fd, 200, SEEK_SET) != 200); + fail_if(write(fd, "42", 2) != 2); + fail_if(lseek(fd, 50, SEEK_SET) != 50); + fail_if(write(fd, "42", 2) != 2); + fail_if(lseek(fd, 88, SEEK_SET) != 88); + fail_if(write(fd, "42", 2) != 2); + + close(fd); + + /* Attempt to open a modified file. */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_identity_open_simple) +{ + Eet_Key *k = NULL; + + eet_init(); + + k = eet_identity_open(_cert_pem, _key_pem, NULL); + fail_if(!k); + + if (k) + eet_identity_close(k); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_identity_open_pkcs8) +{ + Eet_Key *k = NULL; + + eet_init(); + + k = eet_identity_open(_cert_pem, _key_enc_none_pem, NULL); + fail_if(!k); + + if (k) + eet_identity_close(k); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_identity_open_pkcs8_enc) +{ + Eet_Key *k = NULL; + + eet_init(); + + k = eet_identity_open(_cert_pem, _key_enc_pem, NULL); + fail_if(k); + + if (k) + eet_identity_close(k); + + k = eet_identity_open(_cert_pem, _key_enc_pem, &badpass_get); + fail_if(k); + + if (k) + eet_identity_close(k); + + k = eet_identity_open(_cert_pem, _key_enc_pem, &pass_get); + fail_if(!k); + + if (k) + eet_identity_close(k); + + eet_shutdown(); +} +END_TEST + +static const char *_cert_dir_find(const char *argv0) +{ + static char base[PATH_MAX] = ""; + char path[PATH_MAX]; + struct stat st; + + eina_strlcpy(base, TESTS_SRC_DIR, sizeof(base)); + eina_str_join(path, sizeof(path), '/', base, "key.pem"); + if (stat(path, &st) == 0) + return base; + + if (base[0] != '/') + { + snprintf(base, sizeof(base), "%s/%s", TESTS_WD, TESTS_SRC_DIR); + eina_str_join(path, sizeof(path), '/', base, "key.pem"); + if (stat(path, &st) == 0) + return base; + } + + eina_strlcpy(base, argv0, sizeof(base)); + do + { + char *p = strrchr(base, '/'); + if (!p) + { + base[0] = '\0'; + break; + } + *p = '\0'; + eina_str_join(path, sizeof(path), '/', base, "key.pem"); + } + while (stat(path, &st) != 0); + + return base; +} + +void eet_test_identity(TCase *tc) +{ + const char *base; + + base = _cert_dir_find(argv0); + eina_str_join(_key_pem, sizeof(_key_pem), '/', base, "key.pem"); + eina_str_join(_cert_pem, sizeof(_cert_pem), '/', base,"cert.pem"); + eina_str_join(_key_enc, sizeof(_key_enc), '/', base, "key.enc"); + eina_str_join(_key_enc_pem, sizeof(_key_enc_pem), '/', base, "key_enc.pem"); + eina_str_join(_key_enc_none_pem, sizeof(_key_enc_none_pem), '/', + base, "key_enc_none.pem"); + + tcase_add_test(tc, eet_test_identity_simple); + tcase_add_test(tc, eet_test_identity_open_simple); + tcase_add_test(tc, eet_test_identity_open_pkcs8); + tcase_add_test(tc, eet_test_identity_open_pkcs8_enc); +} diff --git a/src/tests/eet/eet_test_image.c b/src/tests/eet/eet_test_image.c new file mode 100644 index 0000000000..f069697110 --- /dev/null +++ b/src/tests/eet/eet_test_image.c @@ -0,0 +1,502 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include + +#include "eet_suite.h" +#include "eet_test_common.h" + +#define IM0 0x00112233 +#define IM1 0x44556677 +#define IM2 0x8899aabb +#define IM3 0xccddeeff + +typedef struct _Eet_Test_Image Eet_Test_Image; +struct _Eet_Test_Image +{ + unsigned int w; + unsigned int h; + int alpha; + unsigned int color[64]; +}; + +static const Eet_Test_Image test_noalpha = { + 8, 8, 0, + { + 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, + 0x000000AA, 0x00110000, + 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, + 0x00110000, 0x00AA0000, + 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, + 0x00AA0000, 0x0000AA00, + 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, + 0x0000AA00, 0x000000AA, + 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, + 0x000000AA, 0x00110000, + 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, + 0x00110000, 0x00AA0000, + 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, + 0x00AA0000, 0x0000AA00, + 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, + 0x0000AA00, 0x000000AA + } +}; + +static const Eet_Test_Image test_alpha = { + 8, 8, 1, + { + 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, 0x0000AA00, + 0x000000AA, 0x0F110000, + 0x0000AA00, 0x0F0000AA, 0x00110000, 0x00AA0000, 0x0000AA00, 0x000000AA, + 0x0F110000, 0x00AA0000, + 0x000000AA, 0x00110000, 0x0FAA0000, 0x0000AA00, 0x000000AA, 0x0F110000, + 0x00AA0000, 0x0000AA00, + 0x00110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, 0x0F110000, 0x00AA0000, + 0x0000AA00, 0x000000AA, + 0x00AA0000, 0x0000AA00, 0x000000AA, 0x0F110000, 0x0FAA0000, 0x0000AA00, + 0x000000AA, 0x00110000, + 0x0000AA00, 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x0F0000AA, + 0x00110000, 0x00AA0000, + 0x000000AA, 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, + 0x0FAA0000, 0x0000AA00, + 0x0F110000, 0x00AA0000, 0x0000AA00, 0x000000AA, 0x00110000, 0x00AA0000, + 0x0000AA00, 0x0F0000AA + } +}; + +START_TEST(eet_test_image_normal) +{ + Eet_File *ef; + char *file; + unsigned int *data; + int compress; + int quality; + int result; + Eet_Image_Encoding lossy; + int alpha; + unsigned int w; + unsigned int h; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + eet_init(); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + /* Save the encoded data in a file. */ + ef = eet_open(file, EET_FILE_MODE_READ_WRITE); + fail_if(!ef); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "0", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 0, + 100, + 0); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "1", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 5, + 100, + 0); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "2", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 9, + 100, + 0); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "3", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 0, + 100, + 1); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "4", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 0, + 60, + 1); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "5", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 0, + 10, + 1); + fail_if(result == 0); + + result = eet_data_image_write(ef, + EET_TEST_FILE_IMAGE "6", + test_noalpha.color, + test_noalpha.w, + test_noalpha.h, + test_noalpha.alpha, + 0, + 0, + 1); + fail_if(result == 0); + + result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "7", test_alpha.color, + test_alpha.w, test_alpha.h, test_alpha.alpha, + 9, 100, 0); + fail_if(result == 0); + + result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "8", test_alpha.color, + test_alpha.w, test_alpha.h, test_alpha.alpha, + 0, 80, 1); + fail_if(result == 0); + + result = eet_data_image_write(ef, EET_TEST_FILE_IMAGE "9", test_alpha.color, + test_alpha.w, test_alpha.h, test_alpha.alpha, + 0, 100, 1); + fail_if(result == 0); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "2", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 9); + fail_if(lossy != 0); + fail_if(data[0] != test_noalpha.color[0]); + free(data); + + result = eet_data_image_header_read(ef, + EET_TEST_FILE_IMAGE "2", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result == 0); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 9); + fail_if(lossy != 0); + + eet_close(ef); + + /* Test read of image */ + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + result = eet_data_image_header_read(ef, + EET_TEST_FILE_IMAGE "0", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result == 0); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 0); + fail_if(lossy != 0); + + data = malloc(w * h * 4); + fail_if(data == NULL); + result = eet_data_image_read_to_surface(ef, + EET_TEST_FILE_IMAGE "0", + 4, + 4, + data, + 2, + 2, + w * 4, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result != 1); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 0); + fail_if(quality != 100); + fail_if(lossy != 0); + fail_if(data[0] != test_noalpha.color[4 + 4 * w]); + free(data); + + data = malloc(w * h * 4); + fail_if(data == NULL); + result = eet_data_image_read_to_surface(ef, + EET_TEST_FILE_IMAGE "0", + 0, + 0, + data, + w, + h, + w * 4, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result != 1); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 0); + fail_if(quality != 100); + fail_if(lossy != 0); + fail_if(data[0] != test_noalpha.color[0]); + free(data); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "1", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 5); + fail_if(quality != 100); + fail_if(lossy != 0); + fail_if(data[0] != test_noalpha.color[0]); + free(data); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "2", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(compress != 9); + fail_if(lossy != 0); + fail_if(data[0] != test_noalpha.color[0]); + free(data); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "3", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(lossy != 1); + free(data); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "5", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(lossy != 1); + free(data); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "6", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_noalpha.w); + fail_if(h != test_noalpha.h); + fail_if(alpha != test_noalpha.alpha); + fail_if(lossy != 1); + free(data); + + result = eet_data_image_header_read(ef, + EET_TEST_FILE_IMAGE "7", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result == 0); + fail_if(w != test_alpha.w); + fail_if(h != test_alpha.h); + fail_if(alpha != test_alpha.alpha); + fail_if(compress != 9); + fail_if(lossy != 0); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "7", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_alpha.w); + fail_if(h != test_alpha.h); + fail_if(alpha != test_alpha.alpha); + fail_if(compress != 9); + fail_if(lossy != 0); + fail_if(data[0] != test_alpha.color[0]); + free(data); + + result = eet_data_image_header_read(ef, + EET_TEST_FILE_IMAGE "9", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(result == 0); + fail_if(w != test_alpha.w); + fail_if(h != test_alpha.h); + fail_if(alpha != test_alpha.alpha); + fail_if(lossy != 1); + + data = eet_data_image_read(ef, + EET_TEST_FILE_IMAGE "9", + &w, + &h, + &alpha, + &compress, + &quality, + &lossy); + fail_if(data == NULL); + fail_if(w != test_alpha.w); + fail_if(h != test_alpha.h); + fail_if(alpha != test_alpha.alpha); + fail_if(lossy != 1); + free(data); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + eet_shutdown(); +} +END_TEST + +START_TEST(eet_test_image_small) +{ + char *file; + unsigned int image[4]; + unsigned int *data; + Eet_File *ef; + unsigned int w; + unsigned int h; + int alpha; + int compression; + int quality; + Eet_Image_Encoding lossy; + int result; + int tmpfd; + + file = strdup("/tmp/eet_suite_testXXXXXX"); + + image[0] = IM0; + image[1] = IM1; + image[2] = IM2; + image[3] = IM3; + + eet_init(); + + fail_if(-1 == (tmpfd = mkstemp(file))); + fail_if(!!close(tmpfd)); + + ef = eet_open(file, EET_FILE_MODE_WRITE); + fail_if(!ef); + + result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0); + fail_if(result == 0); + + eet_close(ef); + + ef = eet_open(file, EET_FILE_MODE_READ); + fail_if(!ef); + + data = (unsigned int *)eet_data_image_read(ef, + "/images/test", + &w, + &h, + &alpha, + &compression, + &quality, + &lossy); + fail_if(data == NULL); + + eet_close(ef); + + fail_if(unlink(file) != 0); + + fail_if(data[0] != IM0); + fail_if(data[1] != IM1); + fail_if(data[2] != IM2); + fail_if(data[3] != IM3); + + free(data); + + eet_shutdown(); +} +END_TEST + +void eet_test_image(TCase *tc) +{ + tcase_add_test(tc, eet_test_image_normal); + tcase_add_test(tc, eet_test_image_small); +} diff --git a/src/tests/eet/eet_test_init.c b/src/tests/eet/eet_test_init.c new file mode 100644 index 0000000000..9343cc15bf --- /dev/null +++ b/src/tests/eet/eet_test_init.c @@ -0,0 +1,24 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "eet_suite.h" + +START_TEST(_eet_test_init) +{ + int ret; + + ret = eet_init(); + fail_if(ret != 1); + + ret = eet_shutdown(); + fail_if(ret != 0); +} +END_TEST + +void eet_test_init(TCase *tc) +{ + tcase_add_test(tc, _eet_test_init); +} diff --git a/src/tests/eet_cxx/eet_cxx_suite.cc b/src/tests/eet_cxx/eet_cxx_suite.cc index b1f66e63b9..4733af7d9c 100644 --- a/src/tests/eet_cxx/eet_cxx_suite.cc +++ b/src/tests/eet_cxx/eet_cxx_suite.cc @@ -1,110 +1,26 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eet.hh" -#include +#include "eet_cxx_suite.h" +#include "../efl_check.h" -#include -#include - -#include - -void eet_test_descriptors(TCase* tc); - -typedef struct _Eet_Test_Case Eet_Test_Case; -struct _Eet_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eet_Test_Case etc[] = { - { "Descriptors", eet_test_descriptors }, +static const Efl_Test_Case etc[] = { + { "Descriptors", eet_cxx_test_descriptors }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eet_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -eet_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eet C++"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - int main(int argc, char* argv[]) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv(const_cast("EFL_RUN_IN_TREE=1")); - s = eet_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eet C++", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eet_cxx/eet_cxx_suite.h b/src/tests/eet_cxx/eet_cxx_suite.h new file mode 100644 index 0000000000..a2780ea784 --- /dev/null +++ b/src/tests/eet_cxx/eet_cxx_suite.h @@ -0,0 +1,11 @@ +#ifndef _EET_CXX_SUITE_H +#define _EET_CXX_SUITE_H + +#include +#include + +#include + +void eet_cxx_test_descriptors(TCase* tc); + +#endif /* _EET_CXX_SUITE_H */ diff --git a/src/tests/eet_cxx/eet_cxx_test_descriptors.cc b/src/tests/eet_cxx/eet_cxx_test_descriptors.cc index 05af641018..4dd4cf9699 100644 --- a/src/tests/eet_cxx/eet_cxx_test_descriptors.cc +++ b/src/tests/eet_cxx/eet_cxx_test_descriptors.cc @@ -1,15 +1,13 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eet.hh" - #include - #include -#include +#include + +#include "eet_cxx_suite.h" struct pod_type { @@ -141,7 +139,7 @@ START_TEST(eet_cxx_descriptors_composition) Eet_File* file = eet_open("/tmp/eet_file_test.eet", EET_FILE_MODE_READ_WRITE); ck_assert(file != 0); - + ::pod_composited pod_composited {new pod_type{5, 'a'}}; int s = eet_data_write(file, d.native_handle(), "foo", &pod_composited, false); @@ -170,7 +168,7 @@ START_TEST(eet_cxx_descriptors_composition) Eet_File* file = eet_open("/tmp/eet_file_test.eet", EET_FILE_MODE_READ_WRITE); ck_assert(file != 0); - + ::pod_composited_with_non_pod pod_composited_with_non_pod {new non_pod}; int s = eet_data_write(file, d.native_handle(), "foo", &pod_composited_with_non_pod, false); @@ -205,7 +203,7 @@ START_TEST(eet_cxx_descriptors_composition) Eet_File* file = eet_open("/tmp/eet_file_test.eet", EET_FILE_MODE_READ_WRITE); ck_assert(file != 0); - + ::pod_value_composited pod_value_composited {{5, 'a'}}; int s = eet_data_write(file, d.native_handle(), "foo", &pod_value_composited, false); @@ -227,7 +225,7 @@ START_TEST(eet_cxx_descriptors_composition) END_TEST void -eet_test_descriptors(TCase* tc) +eet_cxx_test_descriptors(TCase* tc) { tcase_add_test(tc, eet_cxx_descriptors); tcase_add_test(tc, eet_cxx_descriptors_non_pod); diff --git a/src/tests/eeze/eeze_suite.c b/src/tests/eeze/eeze_suite.c index c1b496cf85..8f8d3659a8 100644 --- a/src/tests/eeze/eeze_suite.c +++ b/src/tests/eeze/eeze_suite.c @@ -2,684 +2,29 @@ # include #endif /* ifdef HAVE_CONFIG_H */ -#include -#include - -#include - -#include - -#include -#include -#include - -#include "eeze_udev_private.h" -#include "eeze_sensor_private.h" - -START_TEST(eeze_test_init) -{ - int ret; - - ret = eeze_init(); - fail_if(ret != 1); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -static void -catch_events(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED, - void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED) -{ -} - -#if 0 -// FIXME split udev tests into pieces here -START_TEST(eeze_test_udev_types) -{ - Eina_List *type; - - eeze_init(); - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_CDROM, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_AC, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL); - type = eeze_udev_find_unlisted_similar(type); - type = eeze_udev_find_by_type(0, NULL); - type = eeze_udev_find_unlisted_similar(type); - - eeze_shutdown(); -} -END_TEST -#endif - -START_TEST(eeze_test_udev_watch) -{ - Eeze_Udev_Watch *watch; - - ecore_init(); - eeze_init(); - - /* watch never gets triggered as this is run without user interaction */ - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_KEYBOARD, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_INTERNAL, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_POWER_AC, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NET, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_BLUETOOTH, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NONE, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); - eeze_udev_watch_del(watch); - - eeze_shutdown(); - ecore_shutdown(); -} -END_TEST - -START_TEST(eeze_test_udev_syspath) -{ - Eina_List *type, *l; - const char *name; - Eina_Bool r; - - eeze_init(); - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FOREACH(type, l, name) - { - eeze_udev_syspath_get_devpath(name); - eeze_udev_find_similar_from_syspath(name); - eeze_udev_find_similar_from_syspath(NULL); - eeze_udev_syspath_get_parent(name); - eeze_udev_syspath_get_parent(NULL); - eeze_udev_syspath_get_parents(name); - eeze_udev_syspath_get_parents(NULL); - eeze_udev_syspath_get_devname(name); - eeze_udev_syspath_get_devname(NULL); - eeze_udev_syspath_get_subsystem(name); - eeze_udev_syspath_get_sysattr(name, "manufacturer"); - eeze_udev_syspath_is_mouse(name); - eeze_udev_syspath_is_kbd(name); - eeze_udev_syspath_is_touchpad(name); - eeze_udev_syspath_is_joystick(name); - eeze_udev_walk_get_sysattr(name, "manufacturer"); - eeze_udev_find_by_sysattr("manufacturer", NULL); - eeze_udev_find_by_sysattr(NULL, NULL); - eeze_udev_walk_check_sysattr(name, "manufacturer", NULL); - eeze_udev_walk_check_sysattr(name, "manufacturer", "foo"); - eeze_udev_walk_get_sysattr(NULL, "manufacturer"); - eeze_udev_walk_get_sysattr(name, NULL); - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FOREACH(type, l, name) - { - r = eeze_udev_syspath_is_mouse(name); - fail_unless(r); - - eeze_udev_syspath_is_touchpad(name); - eeze_udev_syspath_is_joystick(name); - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FOREACH(type, l, name) - { - r = eeze_udev_syspath_is_touchpad(name); - fail_unless(r); - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FOREACH(type, l, name) - { - r = eeze_udev_syspath_is_joystick(name); - fail_unless(r); - } - - eeze_udev_devpath_get_syspath("/dev/null"); - - eeze_shutdown(); -} -END_TEST - -START_TEST(eeze_test_udev_attr) -{ - Eina_List *type; - const char *name, *check, *check2; - - eeze_init(); - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); - type = eeze_udev_find_unlisted_similar(type); - eeze_udev_find_by_filter("backlight", NULL, NULL); - - eeze_udev_find_by_filter(NULL, NULL, NULL); - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FREE(type, name) - { - check = eeze_udev_syspath_get_property(name, "INTERFACE"); - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FREE(type, name) - { - check = eeze_udev_syspath_get_property(name, "ID_SERIAL"); - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FREE(type, name) - { - if ((check = eeze_udev_syspath_get_sysattr(name, "model"))) - { - check2 = eeze_udev_syspath_get_subsystem(name); - } - } - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); - type = eeze_udev_find_unlisted_similar(type); - EINA_LIST_FREE(type, name) - { - if ((check = eeze_udev_syspath_get_property(name, "DEVNAME"))) - { - if ((check2 = eeze_udev_syspath_get_sysattr(name, "name"))) - { - eina_stringshare_del(check2); - } - eina_stringshare_del(check); - } - eina_stringshare_del(name); - } - - eeze_shutdown(); -} -END_TEST - -/* -START_TEST(eeze_test_udev_device) -{ - Eina_List *type, *l; - _udev_device *device, *device2; - const char *name; - - eeze_init(); - - type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); - fail_if(type == NULL); - type = eeze_udev_find_unlisted_similar(type); - fail_if(type == NULL); - EINA_LIST_FOREACH(type, l, name) - { - device = _new_device(name); - fail_if(device == NULL); - _walk_parents_get_attr(device, "FOO", EINA_FALSE); - _walk_parents_get_attr(device, "FOO", EINA_TRUE); - _walk_children_get_attr(name, "FOO", "BAR", EINA_FALSE); - _walk_children_get_attr(name, "FOO", "BAR", EINA_TRUE); - } - - device = _new_device("Wrong path"); - fail_if(device != NULL); - - device2 = _copy_device(device); - fail_if(device2 != NULL); - - eeze_shutdown(); -} -END_TEST -*/ - -START_TEST(eeze_test_net_list) -{ - int ret; - Eina_List *list = NULL; - - ret = eeze_init(); - fail_if(ret != 1); - - list = eeze_net_list(); - fail_if(list == NULL); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -START_TEST(eeze_test_net_attr) -{ - int ret; - int idx = 0; - Eeze_Net *net = NULL; - const char *tmp = NULL; - - ret = eeze_init(); - fail_if(ret != 1); - - net = eeze_net_new("lo"); - fail_if(net == NULL); - - tmp = eeze_net_mac_get(net); - fail_if(tmp == NULL); - tmp = NULL; - - idx = eeze_net_idx_get(net); - fail_if(!idx); - - eeze_net_scan(net); - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_attribute_get(net, "carrier"); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_syspath_get(net); - fail_if(tmp == NULL); - - eeze_net_free(net); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -/* -#ifdef HAVE_IPV6 -START_TEST(eeze_test_net_attr_ipv6) -{ - int ret; - Eeze_Net *net = NULL; - const char *tmp = NULL; - - ret = eeze_init(); - fail_if(ret != 1); - - net = eeze_net_new("lo"); - fail_if(net == NULL); - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP6); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST6); - fail_if(tmp == NULL); - tmp = NULL; - - tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK6); - fail_if(tmp == NULL); - - eeze_net_free(net); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST -#endif -*/ - -START_TEST(eeze_test_sensor_read) -{ - Eeze_Sensor_Obj *sens = NULL; - int ret = 0; - float x, y, z; - int acc; - double timestamp; - Eina_Bool rc = EINA_FALSE; - - ecore_init(); - ret = eeze_init(); - fail_if(ret != 1); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_xyz_get(sens, &x, &y, &z); - fail_if(rc == EINA_FALSE); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_xyz_get(sens, &x, &y, &z); - fail_if(rc == EINA_FALSE); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_xyz_get(sens, &x, &y, &z); - fail_if(rc == EINA_FALSE); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_xyz_get(sens, &x, &y, &z); - fail_if(rc == EINA_FALSE); - - /* Use gyro with xy here even if it offers xzy */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_xy_get(sens, &x, &y); - fail_if(rc == EINA_FALSE); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_x_get(sens, &x); - fail_if(rc == EINA_FALSE); - - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - rc = eeze_sensor_read(sens); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_x_get(sens, &x); - fail_if(rc == EINA_FALSE); - - /* Call non existing type */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1); - fail_if(sens != NULL); - - /* Give NULL as sensor object */ - rc = eeze_sensor_read(NULL); - fail_if(rc != EINA_FALSE); - - /* Change sensor type after creation but before read */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - sens->type = EEZE_SENSOR_TYPE_LAST + 1; - rc = eeze_sensor_read(sens); - fail_if(rc != EINA_FALSE); - - /* Try to read from a type you can't read from */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - sens->type = EEZE_SENSOR_TYPE_LAST; - rc = eeze_sensor_read(sens); - fail_if(rc != EINA_FALSE); - - /* Try all getter functions with a NULL sensor object */ - rc = eeze_sensor_xyz_get(NULL, &x, &y, &z); - fail_if(rc != EINA_FALSE); - rc = eeze_sensor_xy_get(NULL, &x, &y); - fail_if(rc != EINA_FALSE); - rc = eeze_sensor_x_get(NULL, &x); - fail_if(rc != EINA_FALSE); - rc = eeze_sensor_accuracy_get(NULL, &acc); - fail_if(rc != EINA_FALSE); - rc = eeze_sensor_timestamp_get(NULL, ×tamp); - fail_if(rc != EINA_FALSE); - - eeze_sensor_free(sens); - - /* Try free on NULL */ - eeze_sensor_free(NULL); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -static int cb_count = 0; - -static Eina_Bool -event_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event) -{ - Eeze_Sensor_Obj *sens = NULL; - int acc; - double timestamp; - Eina_Bool rc = EINA_FALSE; - - sens = event; - fail_if(sens == NULL); - rc = eeze_sensor_accuracy_get(sens, &acc); - fail_if(rc == EINA_FALSE); - rc = eeze_sensor_timestamp_get(sens, ×tamp); - fail_if(rc == EINA_FALSE); - - /* We expect 5 callbacks from async reads right now */ - if (++cb_count == 5) - ecore_main_loop_quit(); - - return ECORE_CALLBACK_DONE; -} - -START_TEST(eeze_test_sensor_async_read) -{ - Ecore_Event_Handler *handler; - - Eeze_Sensor_Obj *sens = NULL; - int ret = 0; - Eina_Bool rc = EINA_FALSE; - - ecore_init(); - ret = eeze_init(); - fail_if(ret != 1); - - handler = ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL); - fail_if(handler == NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - ecore_event_handler_add(EEZE_SENSOR_EVENT_MAGNETIC, event_cb, NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - ecore_event_handler_add(EEZE_SENSOR_EVENT_ORIENTATION, event_cb, NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - ecore_event_handler_add(EEZE_SENSOR_EVENT_GYROSCOPE, event_cb, NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - ecore_event_handler_add(EEZE_SENSOR_EVENT_PROXIMITY, event_cb, NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - ecore_event_handler_add(EEZE_SENSOR_EVENT_LIGHT, event_cb, NULL); - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc == EINA_FALSE); - - /* Error case */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1); - fail_if(sens != NULL); - rc = eeze_sensor_async_read(NULL, NULL); - fail_if(rc != EINA_FALSE); - - /* Change sensor type after creation but before read */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - sens->type = EEZE_SENSOR_TYPE_LAST + 1; - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc != EINA_FALSE); - - /* Try to read from a type you can't read from */ - sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); - fail_if(sens == NULL); - sens->type = EEZE_SENSOR_TYPE_LAST; - rc = eeze_sensor_async_read(sens, NULL); - fail_if(rc != EINA_FALSE); - - ecore_main_loop_begin(); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -START_TEST(eeze_test_sensor_obj_get) -{ - Eeze_Sensor_Obj *obj = NULL, *obj_tmp = NULL; - int ret = 0; - - ecore_init(); - ret = eeze_init(); - fail_if(ret != 1); - - obj = calloc(1, sizeof(Eeze_Sensor_Obj)); - fail_if(obj == NULL); - - obj_tmp = obj; - - obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER); - fail_if(obj == obj_tmp); - - free(obj); - - /* Try to get non existing obj */ - obj_tmp = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LAST + 1); - fail_if(obj_tmp != NULL); - - ret = eeze_shutdown(); - fail_if(ret != 0); -} -END_TEST - -Suite * -eeze_suite(void) -{ - Suite *s; - TCase *tc; - - s = suite_create("Eeze"); - - tc = tcase_create("Eeze_Init"); - tcase_add_test(tc, eeze_test_init); - suite_add_tcase(s, tc); - - tc = tcase_create("Eeze_Udev"); - //FIXME This also fails all the time. Enable this once we verify it's not completely useless - //tcase_add_test(tc, eeze_test_udev_types); - tcase_add_test(tc, eeze_test_udev_watch); - tcase_add_test(tc, eeze_test_udev_syspath); - tcase_add_test(tc, eeze_test_udev_attr); - //FIXME Tested functions here are hidden (not EAPI) and thus can not be tested like this with - //-fvisibility=hidden turned on. - //tcase_add_test(tc, eeze_test_udev_device); - suite_add_tcase(s, tc); - - tc = tcase_create("Eeze_Net"); - tcase_add_test(tc, eeze_test_net_list); - tcase_add_test(tc, eeze_test_net_attr); -#ifdef HAVE_IPV6 - //FIXME Figure out why we fail for the ipv6 tests here (code or test) - //tcase_add_test(tc, eeze_test_net_attr_ipv6); -#endif - suite_add_tcase(s, tc); - - tc = tcase_create("Eeze Sensor"); - tcase_add_test(tc, eeze_test_sensor_read); - tcase_add_test(tc, eeze_test_sensor_async_read); - tcase_add_test(tc, eeze_test_sensor_obj_get); - suite_add_tcase(s, tc); - - tcase_set_timeout(tc, 0); - - return s; -} +#include "eeze_suite.h" +#include "../efl_check.h" + +static const Efl_Test_Case etc[] = { + { "Init", eeze_test_init }, + { "UDev", eeze_test_udev }, + { "Net", eeze_test_net }, + { "Sensor", eeze_test_sensor }, + { NULL, NULL } +}; int -main(void) +main(int argc, char *argv[]) { - Suite *s; - SRunner *sr; int failed_count; + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; + putenv("EFL_RUN_IN_TREE=1"); - s = eeze_suite(); - sr = srunner_create(s); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eeze", etc); return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/src/tests/eeze/eeze_suite.h b/src/tests/eeze/eeze_suite.h new file mode 100644 index 0000000000..d8fcfb3d57 --- /dev/null +++ b/src/tests/eeze/eeze_suite.h @@ -0,0 +1,11 @@ +#ifndef _EEZE_SUITE_H +#define _EEZE_SUITE_H + +#include + +void eeze_test_init(TCase *tc); +void eeze_test_udev(TCase *tc); +void eeze_test_net(TCase *tc); +void eeze_test_sensor(TCase *tc); + +#endif /* _EEZE_SUITE_H */ diff --git a/src/tests/eeze/eeze_test_init.c b/src/tests/eeze/eeze_test_init.c new file mode 100644 index 0000000000..6c72acbd19 --- /dev/null +++ b/src/tests/eeze/eeze_test_init.c @@ -0,0 +1,24 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "eeze_suite.h" + +START_TEST(eeze_test_eeze_init) +{ + int ret; + + ret = eeze_init(); + fail_if(ret != 1); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +void eeze_test_init(TCase *tc) +{ + tcase_add_test(tc, eeze_test_eeze_init); +} diff --git a/src/tests/eeze/eeze_test_net.c b/src/tests/eeze/eeze_test_net.c new file mode 100644 index 0000000000..6d9f8589d6 --- /dev/null +++ b/src/tests/eeze/eeze_test_net.c @@ -0,0 +1,116 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "eeze_suite.h" + +START_TEST(eeze_test_net_list) +{ + int ret; + Eina_List *list = NULL; + + ret = eeze_init(); + fail_if(ret != 1); + + list = eeze_net_list(); + fail_if(list == NULL); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +START_TEST(eeze_test_net_attr) +{ + int ret; + int idx = 0; + Eeze_Net *net = NULL; + const char *tmp = NULL; + + ret = eeze_init(); + fail_if(ret != 1); + + net = eeze_net_new("lo"); + fail_if(net == NULL); + + tmp = eeze_net_mac_get(net); + fail_if(tmp == NULL); + tmp = NULL; + + idx = eeze_net_idx_get(net); + fail_if(!idx); + + eeze_net_scan(net); + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_attribute_get(net, "carrier"); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_syspath_get(net); + fail_if(tmp == NULL); + + eeze_net_free(net); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +/* +#ifdef HAVE_IPV6 +START_TEST(eeze_test_net_attr_ipv6) +{ + int ret; + Eeze_Net *net = NULL; + const char *tmp = NULL; + + ret = eeze_init(); + fail_if(ret != 1); + + net = eeze_net_new("lo"); + fail_if(net == NULL); + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP6); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST6); + fail_if(tmp == NULL); + tmp = NULL; + + tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK6); + fail_if(tmp == NULL); + + eeze_net_free(net); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST +#endif +*/ + +void eeze_test_net(TCase *tc) +{ + tcase_add_test(tc, eeze_test_net_list); + tcase_add_test(tc, eeze_test_net_attr); +#ifdef HAVE_IPV6 + //FIXME Figure out why we fail for the ipv6 tests here (code or test) + //tcase_add_test(tc, eeze_test_net_attr_ipv6); +#endif +} diff --git a/src/tests/eeze/eeze_test_sensor.c b/src/tests/eeze/eeze_test_sensor.c new file mode 100644 index 0000000000..7cd415e65d --- /dev/null +++ b/src/tests/eeze/eeze_test_sensor.c @@ -0,0 +1,280 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include + +#include "eeze_suite.h" +#include "eeze_sensor_private.h" + +static int cb_count = 0; + +static Eina_Bool +event_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event) +{ + Eeze_Sensor_Obj *sens = NULL; + int acc; + double timestamp; + Eina_Bool rc = EINA_FALSE; + + sens = event; + fail_if(sens == NULL); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + + /* We expect 5 callbacks from async reads right now */ + if (++cb_count == 5) + ecore_main_loop_quit(); + + return ECORE_CALLBACK_DONE; +} + +START_TEST(eeze_test_sensor_read) +{ + Eeze_Sensor_Obj *sens = NULL; + int ret = 0; + float x, y, z; + int acc; + double timestamp; + Eina_Bool rc = EINA_FALSE; + + ecore_init(); + ret = eeze_init(); + fail_if(ret != 1); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_xyz_get(sens, &x, &y, &z); + fail_if(rc == EINA_FALSE); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_xyz_get(sens, &x, &y, &z); + fail_if(rc == EINA_FALSE); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_xyz_get(sens, &x, &y, &z); + fail_if(rc == EINA_FALSE); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_xyz_get(sens, &x, &y, &z); + fail_if(rc == EINA_FALSE); + + /* Use gyro with xy here even if it offers xzy */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_xy_get(sens, &x, &y); + fail_if(rc == EINA_FALSE); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_x_get(sens, &x); + fail_if(rc == EINA_FALSE); + + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + rc = eeze_sensor_read(sens); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_accuracy_get(sens, &acc); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_timestamp_get(sens, ×tamp); + fail_if(rc == EINA_FALSE); + rc = eeze_sensor_x_get(sens, &x); + fail_if(rc == EINA_FALSE); + + /* Call non existing type */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1); + fail_if(sens != NULL); + + /* Give NULL as sensor object */ + rc = eeze_sensor_read(NULL); + fail_if(rc != EINA_FALSE); + + /* Change sensor type after creation but before read */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + sens->type = EEZE_SENSOR_TYPE_LAST + 1; + rc = eeze_sensor_read(sens); + fail_if(rc != EINA_FALSE); + + /* Try to read from a type you can't read from */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + sens->type = EEZE_SENSOR_TYPE_LAST; + rc = eeze_sensor_read(sens); + fail_if(rc != EINA_FALSE); + + /* Try all getter functions with a NULL sensor object */ + rc = eeze_sensor_xyz_get(NULL, &x, &y, &z); + fail_if(rc != EINA_FALSE); + rc = eeze_sensor_xy_get(NULL, &x, &y); + fail_if(rc != EINA_FALSE); + rc = eeze_sensor_x_get(NULL, &x); + fail_if(rc != EINA_FALSE); + rc = eeze_sensor_accuracy_get(NULL, &acc); + fail_if(rc != EINA_FALSE); + rc = eeze_sensor_timestamp_get(NULL, ×tamp); + fail_if(rc != EINA_FALSE); + + eeze_sensor_free(sens); + + /* Try free on NULL */ + eeze_sensor_free(NULL); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +START_TEST(eeze_test_sensor_async_read) +{ + Ecore_Event_Handler *handler; + + Eeze_Sensor_Obj *sens = NULL; + int ret = 0; + Eina_Bool rc = EINA_FALSE; + + ecore_init(); + ret = eeze_init(); + fail_if(ret != 1); + + handler = ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL); + fail_if(handler == NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + ecore_event_handler_add(EEZE_SENSOR_EVENT_MAGNETIC, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + ecore_event_handler_add(EEZE_SENSOR_EVENT_ORIENTATION, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + ecore_event_handler_add(EEZE_SENSOR_EVENT_GYROSCOPE, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + ecore_event_handler_add(EEZE_SENSOR_EVENT_PROXIMITY, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + ecore_event_handler_add(EEZE_SENSOR_EVENT_LIGHT, event_cb, NULL); + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc == EINA_FALSE); + + /* Error case */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1); + fail_if(sens != NULL); + rc = eeze_sensor_async_read(NULL, NULL); + fail_if(rc != EINA_FALSE); + + /* Change sensor type after creation but before read */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + sens->type = EEZE_SENSOR_TYPE_LAST + 1; + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc != EINA_FALSE); + + /* Try to read from a type you can't read from */ + sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); + fail_if(sens == NULL); + sens->type = EEZE_SENSOR_TYPE_LAST; + rc = eeze_sensor_async_read(sens, NULL); + fail_if(rc != EINA_FALSE); + + ecore_main_loop_begin(); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +START_TEST(eeze_test_sensor_obj_get) +{ + Eeze_Sensor_Obj *obj = NULL, *obj_tmp = NULL; + int ret = 0; + + ecore_init(); + ret = eeze_init(); + fail_if(ret != 1); + + obj = calloc(1, sizeof(Eeze_Sensor_Obj)); + fail_if(obj == NULL); + + obj_tmp = obj; + + obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER); + fail_if(obj == obj_tmp); + + free(obj); + + /* Try to get non existing obj */ + obj_tmp = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LAST + 1); + fail_if(obj_tmp != NULL); + + ret = eeze_shutdown(); + fail_if(ret != 0); +} +END_TEST + +void eeze_test_sensor(TCase *tc) +{ + tcase_add_test(tc, eeze_test_sensor_read); + tcase_add_test(tc, eeze_test_sensor_async_read); + tcase_add_test(tc, eeze_test_sensor_obj_get); +} diff --git a/src/tests/eeze/eeze_test_udev.c b/src/tests/eeze/eeze_test_udev.c new file mode 100644 index 0000000000..1e8b3c821a --- /dev/null +++ b/src/tests/eeze/eeze_test_udev.c @@ -0,0 +1,254 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "eeze_suite.h" +/* #include "eeze_udev_private.h" */ + +static void +catch_events(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED, + void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED) +{ +} + +#if 0 +// FIXME split udev tests into pieces here +START_TEST(eeze_test_udev_types) +{ + Eina_List *type; + + eeze_init(); + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_CDROM, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_AC, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL); + type = eeze_udev_find_unlisted_similar(type); + type = eeze_udev_find_by_type(0, NULL); + type = eeze_udev_find_unlisted_similar(type); + + eeze_shutdown(); +} +END_TEST +#endif + +START_TEST(eeze_test_udev_watch) +{ + Eeze_Udev_Watch *watch; + + ecore_init(); + eeze_init(); + + /* watch never gets triggered as this is run without user interaction */ + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_KEYBOARD, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_INTERNAL, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_POWER_AC, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NET, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_BLUETOOTH, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NONE, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL); + eeze_udev_watch_del(watch); + + eeze_shutdown(); + ecore_shutdown(); +} +END_TEST + +START_TEST(eeze_test_udev_syspath) +{ + Eina_List *type, *l; + const char *name; + Eina_Bool r; + + eeze_init(); + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FOREACH(type, l, name) + { + eeze_udev_syspath_get_devpath(name); + eeze_udev_find_similar_from_syspath(name); + eeze_udev_find_similar_from_syspath(NULL); + eeze_udev_syspath_get_parent(name); + eeze_udev_syspath_get_parent(NULL); + eeze_udev_syspath_get_parents(name); + eeze_udev_syspath_get_parents(NULL); + eeze_udev_syspath_get_devname(name); + eeze_udev_syspath_get_devname(NULL); + eeze_udev_syspath_get_subsystem(name); + eeze_udev_syspath_get_sysattr(name, "manufacturer"); + eeze_udev_syspath_is_mouse(name); + eeze_udev_syspath_is_kbd(name); + eeze_udev_syspath_is_touchpad(name); + eeze_udev_syspath_is_joystick(name); + eeze_udev_walk_get_sysattr(name, "manufacturer"); + eeze_udev_find_by_sysattr("manufacturer", NULL); + eeze_udev_find_by_sysattr(NULL, NULL); + eeze_udev_walk_check_sysattr(name, "manufacturer", NULL); + eeze_udev_walk_check_sysattr(name, "manufacturer", "foo"); + eeze_udev_walk_get_sysattr(NULL, "manufacturer"); + eeze_udev_walk_get_sysattr(name, NULL); + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FOREACH(type, l, name) + { + r = eeze_udev_syspath_is_mouse(name); + fail_unless(r); + + eeze_udev_syspath_is_touchpad(name); + eeze_udev_syspath_is_joystick(name); + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FOREACH(type, l, name) + { + r = eeze_udev_syspath_is_touchpad(name); + fail_unless(r); + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FOREACH(type, l, name) + { + r = eeze_udev_syspath_is_joystick(name); + fail_unless(r); + } + + eeze_udev_devpath_get_syspath("/dev/null"); + + eeze_shutdown(); +} +END_TEST + +START_TEST(eeze_test_udev_attr) +{ + Eina_List *type; + const char *name, *check, *check2; + + eeze_init(); + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); + type = eeze_udev_find_unlisted_similar(type); + eeze_udev_find_by_filter("backlight", NULL, NULL); + + eeze_udev_find_by_filter(NULL, NULL, NULL); + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FREE(type, name) + { + check = eeze_udev_syspath_get_property(name, "INTERFACE"); + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FREE(type, name) + { + check = eeze_udev_syspath_get_property(name, "ID_SERIAL"); + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FREE(type, name) + { + if ((check = eeze_udev_syspath_get_sysattr(name, "model"))) + { + check2 = eeze_udev_syspath_get_subsystem(name); + } + } + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); + type = eeze_udev_find_unlisted_similar(type); + EINA_LIST_FREE(type, name) + { + if ((check = eeze_udev_syspath_get_property(name, "DEVNAME"))) + { + if ((check2 = eeze_udev_syspath_get_sysattr(name, "name"))) + { + eina_stringshare_del(check2); + } + eina_stringshare_del(check); + } + eina_stringshare_del(name); + } + + eeze_shutdown(); +} +END_TEST + +/* +START_TEST(eeze_test_udev_device) +{ + Eina_List *type, *l; + _udev_device *device, *device2; + const char *name; + + eeze_init(); + + type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL); + fail_if(type == NULL); + type = eeze_udev_find_unlisted_similar(type); + fail_if(type == NULL); + EINA_LIST_FOREACH(type, l, name) + { + device = _new_device(name); + fail_if(device == NULL); + _walk_parents_get_attr(device, "FOO", EINA_FALSE); + _walk_parents_get_attr(device, "FOO", EINA_TRUE); + _walk_children_get_attr(name, "FOO", "BAR", EINA_FALSE); + _walk_children_get_attr(name, "FOO", "BAR", EINA_TRUE); + } + + device = _new_device("Wrong path"); + fail_if(device != NULL); + + device2 = _copy_device(device); + fail_if(device2 != NULL); + + eeze_shutdown(); +} +END_TEST +*/ + +void eeze_test_udev(TCase *tc) +{ + //FIXME This also fails all the time. Enable this once we verify it's not completely useless + //tcase_add_test(tc, eeze_test_udev_types); + tcase_add_test(tc, eeze_test_udev_watch); + tcase_add_test(tc, eeze_test_udev_syspath); + tcase_add_test(tc, eeze_test_udev_attr); + //FIXME Tested functions here are hidden (not EAPI) and thus can not be tested like this with + //-fvisibility=hidden turned on. + //tcase_add_test(tc, eeze_test_udev_device); +} diff --git a/src/tests/efl_check.h b/src/tests/efl_check.h new file mode 100644 index 0000000000..77fd1591c3 --- /dev/null +++ b/src/tests/efl_check.h @@ -0,0 +1,117 @@ +#ifndef EFL_CHECK_H +#define EFL_CHECK_H + +#include /* getenv */ +#include /* fprintf, fputs */ +#include /* strcmp */ + +typedef struct _Efl_Test_Case Efl_Test_Case; +struct _Efl_Test_Case +{ + const char *test_case; + void (*build)(TCase *tc); +}; + +static void +_efl_tests_list(const Efl_Test_Case *etc) +{ + const Efl_Test_Case *itr = etc; + fputs("Available Test Cases:\n", stderr); + for (; itr->test_case; itr++) + fprintf(stderr, "\t%s\n", itr->test_case); +} + +static int +_efl_test_option_disp(int argc, char **argv, const Efl_Test_Case *etc) +{ + int i; + + for (i = 1; i < argc; i++) + { + if ((strcmp(argv[i], "-h") == 0) || + (strcmp(argv[i], "--help") == 0)) + { + fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", + argv[0]); + _efl_tests_list(etc); + return 0; + } + else if ((strcmp(argv[i], "-l") == 0) || + (strcmp(argv[i], "--list") == 0)) + { + _efl_tests_list(etc); + return 0; + } + } + + return 1; +} + +static int +_efl_test_use(int argc, const char **argv, const char *test_case) +{ + if (argc < 1) + return 1; + + for (; argc > 0; argc--, argv++) + if (strcmp(test_case, *argv) == 0) + return 1; + return 0; +} + +static int +_efl_test_fork_has(SRunner *sr) +{ + if (srunner_fork_status(sr) == CK_FORK) + return 1; + else if (srunner_fork_status(sr) == CK_NOFORK) + return 0; + else if (srunner_fork_status(sr) == CK_FORK_GETENV) + { + char *res; + + res = getenv("CF_FORK"); + if (res && (strcmp(res, "no") == 0)) + return 0; + else + return 1; + } + + /* should never get there */ + return 0; +} + +static int +_efl_suite_build_and_run(int argc, const char **argv, const char *suite_name, const Efl_Test_Case *etc) +{ + Suite *s; + SRunner *sr; + TCase *tc; + int i, failed_count; + + s = suite_create(suite_name); + sr = srunner_create(s); + + for (i = 0; etc[i].test_case; ++i) + { + if (!_efl_test_use(argc, argv, etc[i].test_case)) + continue; + + tc = tcase_create(etc[i].test_case); + + if (_efl_test_fork_has(sr)) + tcase_set_timeout(tc, 0); + + etc[i].build(tc); + suite_add_tcase(s, tc); + } + + srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); + srunner_run_all(sr, CK_ENV); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + return failed_count; +} + +#endif diff --git a/src/tests/efreet/ef_cache.c b/src/tests/efreet/ef_cache.c index c83aa0110f..847c97bf00 100644 --- a/src/tests/efreet/ef_cache.c +++ b/src/tests/efreet/ef_cache.c @@ -1,13 +1,12 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif #include -#include -#include "Efreet.h" +#include +#include + #include "ef_test.h" #if 0 diff --git a/src/tests/efreet/ef_data_dirs.c b/src/tests/efreet/ef_data_dirs.c index 894e2e00d7..d79b742c85 100644 --- a/src/tests/efreet/ef_data_dirs.c +++ b/src/tests/efreet/ef_data_dirs.c @@ -1,15 +1,13 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" - -#include +#include #include #include -#include + +#include +#include int ef_cb_efreet_data_home(void) diff --git a/src/tests/efreet/ef_desktop.c b/src/tests/efreet/ef_desktop.c index 2ceed1ba22..c4fa675c8c 100644 --- a/src/tests/efreet/ef_desktop.c +++ b/src/tests/efreet/ef_desktop.c @@ -1,16 +1,15 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" -#include "config.h" +#include #include #include -#include #include #include + +#include + #include "ef_test.h" typedef struct diff --git a/src/tests/efreet/ef_icon_theme.c b/src/tests/efreet/ef_icon_theme.c index a0d1f1a7fc..7b4cb5bca1 100644 --- a/src/tests/efreet/ef_icon_theme.c +++ b/src/tests/efreet/ef_icon_theme.c @@ -1,16 +1,15 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "Efreet.h" +#include #include #include -#include #include + #include #include +#include #define SIZE 128 #define THEME "Tango" diff --git a/src/tests/efreet/ef_ini.c b/src/tests/efreet/ef_ini.c index 9fb95cade4..57457e0dc1 100644 --- a/src/tests/efreet/ef_ini.c +++ b/src/tests/efreet/ef_ini.c @@ -1,14 +1,13 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" -#include "config.h" +#include #include #include -#include + +#include + #include "ef_test.h" int diff --git a/src/tests/efreet/ef_locale.c b/src/tests/efreet/ef_locale.c index 7ad47f264a..3d52f6fafd 100644 --- a/src/tests/efreet/ef_locale.c +++ b/src/tests/efreet/ef_locale.c @@ -1,16 +1,15 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" -#define EFREET_MODULE_LOG_DOM /* no logging in this file */ -#include "efreet_private.h" #include #include #include +#include +#define EFREET_MODULE_LOG_DOM /* no logging in this file */ +#include "efreet_private.h" + int ef_cb_locale(void) { diff --git a/src/tests/efreet/ef_menu.c b/src/tests/efreet/ef_menu.c index ba53bff133..49173417ea 100644 --- a/src/tests/efreet/ef_menu.c +++ b/src/tests/efreet/ef_menu.c @@ -1,13 +1,12 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" -#include "config.h" #include #include + +#include + #include "ef_test.h" #if 0 diff --git a/src/tests/efreet/ef_mime.c b/src/tests/efreet/ef_mime.c index 8940974ca6..adbb2aa5a3 100644 --- a/src/tests/efreet/ef_mime.c +++ b/src/tests/efreet/ef_mime.c @@ -1,16 +1,15 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include "Efreet.h" -#include "Efreet_Mime.h" -#include "config.h" #include #include #include + #include +#include +#include + #include "ef_test.h" #define THEME "Tango" diff --git a/src/tests/efreet/ef_test.h b/src/tests/efreet/ef_test.h index 5d2b83a1df..4fdde4ddc6 100644 --- a/src/tests/efreet/ef_test.h +++ b/src/tests/efreet/ef_test.h @@ -1,8 +1,6 @@ #ifndef EF_TEST #define EF_TEST -#include "config.h" - #include #define IF_FREE(x) do { if (x) free(x); x = NULL; } while (0); diff --git a/src/tests/efreet/ef_utils.c b/src/tests/efreet/ef_utils.c index 75f520d6dc..7ecda39661 100644 --- a/src/tests/efreet/ef_utils.c +++ b/src/tests/efreet/ef_utils.c @@ -1,8 +1,11 @@ -#include "config.h" +#ifdef HAVE_CONFIG_H +# include +#endif -#include "Efreet.h" #include +#include + int ef_cb_utils(void) { diff --git a/src/tests/efreet/efreet_async_test.c b/src/tests/efreet/efreet_async_test.c index ce85e429bb..49acaa0c16 100644 --- a/src/tests/efreet/efreet_async_test.c +++ b/src/tests/efreet/efreet_async_test.c @@ -1,6 +1,9 @@ -#include "config.h" +#ifdef HAVE_CONFIG_H +# include +#endif #include + #include #include #include diff --git a/src/tests/efreet/efreet_icon_cache_dump.c b/src/tests/efreet/efreet_icon_cache_dump.c index 095f8facc5..313c890933 100644 --- a/src/tests/efreet/efreet_icon_cache_dump.c +++ b/src/tests/efreet/efreet_icon_cache_dump.c @@ -1,10 +1,9 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include + #include +#include #include #include #include @@ -18,7 +17,7 @@ #define EFREET_MODULE_LOG_DOM /* no logging in this file */ -#include "Efreet.h" +#include #include "efreet_private.h" #include "efreet_cache_private.h" diff --git a/src/tests/efreet/efreet_spec_test.c b/src/tests/efreet/efreet_spec_test.c index 92ce538226..c2091070eb 100644 --- a/src/tests/efreet/efreet_spec_test.c +++ b/src/tests/efreet/efreet_spec_test.c @@ -1,12 +1,11 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include #include #include + +#include #include "ef_test.h" static void dump(Efreet_Menu *menu, const char *path); diff --git a/src/tests/efreet/efreet_suite.c b/src/tests/efreet/efreet_suite.c index bbfd69c40e..732e1010a1 100644 --- a/src/tests/efreet/efreet_suite.c +++ b/src/tests/efreet/efreet_suite.c @@ -1,111 +1,28 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif -#include -#include - -#include - #include "efreet_suite.h" +#include "../efl_check.h" -typedef struct _Efreet_Test_Case Efreet_Test_Case; - -struct _Efreet_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Efreet_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Efreet", efreet_test_efreet }, { "Efreet Cache", efreet_test_efreet_cache }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Efreet_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -efreet_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Efreet"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = efreet_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_NORMAL); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Efreet", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/efreet/efreet_test_efreet.c b/src/tests/efreet/efreet_test_efreet.c index a21a38825d..d35ec9effd 100644 --- a/src/tests/efreet/efreet_test_efreet.c +++ b/src/tests/efreet/efreet_test_efreet.c @@ -1,5 +1,3 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif diff --git a/src/tests/efreet/efreet_test_efreet_cache.c b/src/tests/efreet/efreet_test_efreet_cache.c index 1e1595323f..2f8972de33 100644 --- a/src/tests/efreet/efreet_test_efreet_cache.c +++ b/src/tests/efreet/efreet_test_efreet_cache.c @@ -1,5 +1,3 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif diff --git a/src/tests/efreet/efreet_user_dir.c b/src/tests/efreet/efreet_user_dir.c index 7a37fb09dd..1555efdc6a 100644 --- a/src/tests/efreet/efreet_user_dir.c +++ b/src/tests/efreet/efreet_user_dir.c @@ -1,5 +1,3 @@ -#include "config.h" - #ifdef HAVE_CONFIG_H # include #endif diff --git a/src/tests/efreet/main.c b/src/tests/efreet/main.c index 4bf269715c..6c8a7002ba 100644 --- a/src/tests/efreet/main.c +++ b/src/tests/efreet/main.c @@ -1,15 +1,17 @@ -#include "config.h" +#ifdef HAVE_CONFIG_H +# include +#endif -#include "Efreet.h" +#include +#include +#include + +#include +#include +#include /* no logging */ #define EFREET_MODULE_LOG_DOM #include "efreet_private.h" -#include "Efreet_Mime.h" -#include "config.h" -#include -#include -#include -#include int ef_cb_efreet_data_home(void); int ef_cb_efreet_config_home(void); diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c index b5c8759988..dc193eeed3 100644 --- a/src/tests/eina/eina_suite.c +++ b/src/tests/eina/eina_suite.c @@ -20,19 +20,12 @@ # include "config.h" #endif +#include + #include "eina_suite.h" -#include "Eina.h" -#include -#include +#include "../efl_check.h" -typedef struct _Eina_Test_Case Eina_Test_Case; -struct _Eina_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eina_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "FixedPoint", eina_test_fp }, { "Inarray", eina_test_inarray }, { "Array", eina_test_array }, @@ -88,54 +81,6 @@ static const Eina_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eina_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -eina_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eina"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - /* FIXME this is a copy from eina_test_mempool * we should remove the duplication */ @@ -156,7 +101,7 @@ static void _mempool_shutdown(void) { unsigned int i; Eina_Array_Iterator it; - Eina_Module *module; + Eina_Module *module; eina_module_list_free(_modules); if (_modules) { @@ -170,38 +115,17 @@ static void _mempool_shutdown(void) int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = eina_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - _mempool_init(); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eina", etc); _mempool_shutdown(); diff --git a/src/tests/eina/eina_test_accessor.c b/src/tests/eina/eina_test_accessor.c index a995429139..c6bd1e0d4b 100644 --- a/src/tests/eina/eina_test_accessor.c +++ b/src/tests/eina/eina_test_accessor.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Bool eina_accessor_check(EINA_UNUSED const Eina_Array *array, diff --git a/src/tests/eina/eina_test_array.c b/src/tests/eina/eina_test_array.c index 1929601834..37ac3c2c62 100644 --- a/src/tests/eina/eina_test_array.c +++ b/src/tests/eina/eina_test_array.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_array_simple) { diff --git a/src/tests/eina/eina_test_barrier.c b/src/tests/eina/eina_test_barrier.c index 678adec06f..2dea3d3bb8 100644 --- a/src/tests/eina/eina_test_barrier.c +++ b/src/tests/eina/eina_test_barrier.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Thread wk1, wk2, wk3, wk4, wk5; static Eina_Barrier barrier; diff --git a/src/tests/eina/eina_test_bezier.c b/src/tests/eina/eina_test_bezier.c index a7a1598971..3ee007f41c 100644 --- a/src/tests/eina/eina_test_bezier.c +++ b/src/tests/eina/eina_test_bezier.c @@ -20,11 +20,12 @@ # include "config.h" #endif -#include #include +#include + +#include #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_bezier_test_values) { diff --git a/src/tests/eina/eina_test_binbuf.c b/src/tests/eina/eina_test_binbuf.c index ce778038f5..af8f4699b9 100644 --- a/src/tests/eina/eina_test_binbuf.c +++ b/src/tests/eina/eina_test_binbuf.c @@ -21,8 +21,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(binbuf_simple) { diff --git a/src/tests/eina/eina_test_binshare.c b/src/tests/eina/eina_test_binshare.c index b2e77ae55f..1b4a200597 100644 --- a/src/tests/eina/eina_test_binshare.c +++ b/src/tests/eina/eina_test_binshare.c @@ -25,8 +25,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" #define TEST0 "te\0st/0" #define TEST0_SIZE 7 diff --git a/src/tests/eina/eina_test_clist.c b/src/tests/eina/eina_test_clist.c index 8aaf6fc7db..76af179057 100644 --- a/src/tests/eina/eina_test_clist.c +++ b/src/tests/eina/eina_test_clist.c @@ -6,7 +6,8 @@ #include #include -#include "Eina.h" +#include + #include "eina_suite.h" Eina_Clist string_list = EINA_CLIST_INIT(string_list); diff --git a/src/tests/eina/eina_test_convert.c b/src/tests/eina/eina_test_convert.c index 68472ab0cc..8dd06e65fe 100644 --- a/src/tests/eina/eina_test_convert.c +++ b/src/tests/eina/eina_test_convert.c @@ -26,8 +26,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_convert_simple) { diff --git a/src/tests/eina/eina_test_counter.c b/src/tests/eina/eina_test_counter.c index 83fe29bec4..b686a50ec5 100644 --- a/src/tests/eina/eina_test_counter.c +++ b/src/tests/eina/eina_test_counter.c @@ -23,10 +23,11 @@ #include #include -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_safety_checks.h" +#include "eina_suite.h" + #ifdef EINA_SAFETY_CHECKS struct log_ctx { const char *msg; diff --git a/src/tests/eina/eina_test_cow.c b/src/tests/eina/eina_test_cow.c index a4e1422e56..b00101a6e9 100644 --- a/src/tests/eina/eina_test_cow.c +++ b/src/tests/eina/eina_test_cow.c @@ -20,8 +20,9 @@ # include "config.h" #endif +#include + #include "eina_suite.h" -#include "Eina.h" typedef struct _Eina_Cow_Test Eina_Cow_Test; struct _Eina_Cow_Test diff --git a/src/tests/eina/eina_test_crc.c b/src/tests/eina/eina_test_crc.c index 34a00f31b1..61db0e22eb 100644 --- a/src/tests/eina/eina_test_crc.c +++ b/src/tests/eina/eina_test_crc.c @@ -6,8 +6,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_crc_simple) { diff --git a/src/tests/eina/eina_test_error.c b/src/tests/eina/eina_test_error.c index 2824518d73..1c27213822 100644 --- a/src/tests/eina/eina_test_error.c +++ b/src/tests/eina/eina_test_error.c @@ -28,8 +28,9 @@ # include #endif +#include + #include "eina_suite.h" -#include "Eina.h" #define TEST_TEXT "The big test\n" diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c index fc832073a8..c82f60031b 100644 --- a/src/tests/eina/eina_test_file.c +++ b/src/tests/eina/eina_test_file.c @@ -27,11 +27,12 @@ #include #include -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_safety_checks.h" #include "eina_file_common.h" +#include "eina_suite.h" + #ifdef _WIN32 # define PATH_SEP_C '\\' #else diff --git a/src/tests/eina/eina_test_fp.c b/src/tests/eina/eina_test_fp.c index 63b1a61658..9100c57e8c 100644 --- a/src/tests/eina/eina_test_fp.c +++ b/src/tests/eina/eina_test_fp.c @@ -20,11 +20,12 @@ # include "config.h" #endif -#include #include +#include + +#include #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_fp_cos) { diff --git a/src/tests/eina/eina_test_hash.c b/src/tests/eina/eina_test_hash.c index cc44bffd0a..c96ca0f079 100644 --- a/src/tests/eina/eina_test_hash.c +++ b/src/tests/eina/eina_test_hash.c @@ -24,10 +24,11 @@ #include #include -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_hash.h" +#include "eina_suite.h" + #define EINA_HASH_BUCKET_SIZE 8 static unsigned int diff --git a/src/tests/eina/eina_test_inarray.c b/src/tests/eina/eina_test_inarray.c index e54a5cf3c7..f8e271e8ca 100644 --- a/src/tests/eina/eina_test_inarray.c +++ b/src/tests/eina/eina_test_inarray.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_inarray_test_simple) { diff --git a/src/tests/eina/eina_test_inlist.c b/src/tests/eina/eina_test_inlist.c index 2a26169e77..6d9ea2676e 100644 --- a/src/tests/eina/eina_test_inlist.c +++ b/src/tests/eina/eina_test_inlist.c @@ -23,10 +23,11 @@ #include #include -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_safety_checks.h" +#include "eina_suite.h" + typedef struct _Eina_Test_Inlist Eina_Test_Inlist; struct _Eina_Test_Inlist { diff --git a/src/tests/eina/eina_test_iterator.c b/src/tests/eina/eina_test_iterator.c index 5c4b88d414..463861ef5d 100644 --- a/src/tests/eina/eina_test_iterator.c +++ b/src/tests/eina/eina_test_iterator.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Bool eina_iterator_array_check(EINA_UNUSED const Eina_Array *array, diff --git a/src/tests/eina/eina_test_lalloc.c b/src/tests/eina/eina_test_lalloc.c index 13fd6078a8..c9752e314b 100644 --- a/src/tests/eina/eina_test_lalloc.c +++ b/src/tests/eina/eina_test_lalloc.c @@ -23,8 +23,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" typedef struct _Eina_Lazy_Allocator_Test Eina_Lazy_Allocator_Test; struct _Eina_Lazy_Allocator_Test diff --git a/src/tests/eina/eina_test_list.c b/src/tests/eina/eina_test_list.c index b23fa87b1f..42c6718872 100644 --- a/src/tests/eina/eina_test_list.c +++ b/src/tests/eina/eina_test_list.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Bool eina_list_sorted_check(const Eina_List *list) { diff --git a/src/tests/eina/eina_test_lock.c b/src/tests/eina/eina_test_lock.c index d1ff0108de..d15703c6d6 100644 --- a/src/tests/eina/eina_test_lock.c +++ b/src/tests/eina/eina_test_lock.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" #ifdef __MACH__ # include diff --git a/src/tests/eina/eina_test_log.c b/src/tests/eina/eina_test_log.c index fb9c06fd07..cc20bfc98b 100644 --- a/src/tests/eina/eina_test_log.c +++ b/src/tests/eina/eina_test_log.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" struct log_ctx { int level; diff --git a/src/tests/eina/eina_test_magic.c b/src/tests/eina/eina_test_magic.c index a5d07cbddb..b6f8fdc369 100644 --- a/src/tests/eina/eina_test_magic.c +++ b/src/tests/eina/eina_test_magic.c @@ -26,10 +26,11 @@ #define EINA_MAGIC_DEBUG -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_safety_checks.h" +#include "eina_suite.h" + #define EINA_MAGIC_TEST 0x7781fee7 #define EINA_MAGIC_TEST2 0x42241664 #define EINA_MAGIC_STRING "Eina Magic Test" diff --git a/src/tests/eina/eina_test_main.c b/src/tests/eina/eina_test_main.c index 04364a15a2..434f415fb1 100644 --- a/src/tests/eina/eina_test_main.c +++ b/src/tests/eina/eina_test_main.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_simple) { diff --git a/src/tests/eina/eina_test_matrix.c b/src/tests/eina/eina_test_matrix.c index cac2163a53..1a0d9ae6d3 100644 --- a/src/tests/eina/eina_test_matrix.c +++ b/src/tests/eina/eina_test_matrix.c @@ -22,11 +22,12 @@ #define DBL_EPSILON 0.0000001 -#include #include +#include + +#include #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_matrix2) { diff --git a/src/tests/eina/eina_test_matrixsparse.c b/src/tests/eina/eina_test_matrixsparse.c index 1aaf4e62ab..faa7f41f81 100644 --- a/src/tests/eina/eina_test_matrixsparse.c +++ b/src/tests/eina/eina_test_matrixsparse.c @@ -4,8 +4,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" #define MAX_ROWS 10 #define MAX_COLS 10 diff --git a/src/tests/eina/eina_test_mempool.c b/src/tests/eina/eina_test_mempool.c index bdcd295d20..00a65df62e 100644 --- a/src/tests/eina/eina_test_mempool.c +++ b/src/tests/eina/eina_test_mempool.c @@ -20,8 +20,9 @@ # include "config.h" #endif +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Array *_modules; @@ -43,7 +44,7 @@ _mempool_shutdown(void) { unsigned int i; Eina_Array_Iterator it; - Eina_Module *module; + Eina_Module *module; eina_module_list_free(_modules); if (_modules) { @@ -191,5 +192,3 @@ eina_test_mempool(TCase *tc) tcase_add_test(tc, eina_mempool_ememoa_unknown); #endif } - - diff --git a/src/tests/eina/eina_test_model.c b/src/tests/eina/eina_test_model.c index 5f494f9ea7..7541970194 100644 --- a/src/tests/eina/eina_test_model.c +++ b/src/tests/eina/eina_test_model.c @@ -23,8 +23,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" static void _eina_test_model_check_safety_null(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) diff --git a/src/tests/eina/eina_test_module.c b/src/tests/eina/eina_test_module.c index 018e0623ab..4cd5bd5a29 100644 --- a/src/tests/eina/eina_test_module.c +++ b/src/tests/eina/eina_test_module.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" static Eina_Bool list_cb(Eina_Module *m, void *data EINA_UNUSED) { diff --git a/src/tests/eina/eina_test_module_dummy.c b/src/tests/eina/eina_test_module_dummy.c index d42b530f74..bb9916db43 100644 --- a/src/tests/eina/eina_test_module_dummy.c +++ b/src/tests/eina/eina_test_module_dummy.c @@ -4,7 +4,7 @@ #include -#include "Eina.h" +#include Eina_Bool dummy_module_init(void) { diff --git a/src/tests/eina/eina_test_quad.c b/src/tests/eina/eina_test_quad.c index eb1638f4a2..b65f5c2c88 100644 --- a/src/tests/eina/eina_test_quad.c +++ b/src/tests/eina/eina_test_quad.c @@ -2,11 +2,12 @@ # include "config.h" #endif -#include #include +#include + +#include #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_quad_simple) { diff --git a/src/tests/eina/eina_test_quadtree.c b/src/tests/eina/eina_test_quadtree.c index 52faeec3cc..3a64b96582 100644 --- a/src/tests/eina/eina_test_quadtree.c +++ b/src/tests/eina/eina_test_quadtree.c @@ -20,11 +20,12 @@ # include "config.h" #endif -#include #include +#include + +#include #include "eina_suite.h" -#include "Eina.h" static Eina_Quad_Direction _eina_quadtree_rectangle_vert(const void *object, size_t middle) diff --git a/src/tests/eina/eina_test_quaternion.c b/src/tests/eina/eina_test_quaternion.c index b3c133a984..a43ad03d6f 100644 --- a/src/tests/eina/eina_test_quaternion.c +++ b/src/tests/eina/eina_test_quaternion.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" #define FLOAT_CMP(a, b) (fabs((float)a - (float)b) <= FLT_MIN) diff --git a/src/tests/eina/eina_test_rbtree.c b/src/tests/eina/eina_test_rbtree.c index e55538749f..f8ecff864f 100644 --- a/src/tests/eina/eina_test_rbtree.c +++ b/src/tests/eina/eina_test_rbtree.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" static const unsigned int r1[1000] = { diff --git a/src/tests/eina/eina_test_rectangle.c b/src/tests/eina/eina_test_rectangle.c index 08f8384dfa..bf13b58d2c 100644 --- a/src/tests/eina/eina_test_rectangle.c +++ b/src/tests/eina/eina_test_rectangle.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_rectangle_pool) { diff --git a/src/tests/eina/eina_test_sched.c b/src/tests/eina/eina_test_sched.c index 12c427381f..78ce182d8d 100644 --- a/src/tests/eina/eina_test_sched.c +++ b/src/tests/eina/eina_test_sched.c @@ -25,8 +25,9 @@ #include #endif +#include + #include "eina_suite.h" -#include "Eina.h" #ifdef __linux__ diff --git a/src/tests/eina/eina_test_simple_xml_parser.c b/src/tests/eina/eina_test_simple_xml_parser.c index ef056f1fa9..ad4bc8900d 100644 --- a/src/tests/eina/eina_test_simple_xml_parser.c +++ b/src/tests/eina/eina_test_simple_xml_parser.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" static const char *get_file_full_path(const char *filename) { diff --git a/src/tests/eina/eina_test_str.c b/src/tests/eina/eina_test_str.c index 97b3865a9d..9a47dcf8ac 100644 --- a/src/tests/eina/eina_test_str.c +++ b/src/tests/eina/eina_test_str.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(str_simple) { diff --git a/src/tests/eina/eina_test_strbuf.c b/src/tests/eina/eina_test_strbuf.c index c42541198e..b8f27f03f3 100644 --- a/src/tests/eina/eina_test_strbuf.c +++ b/src/tests/eina/eina_test_strbuf.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(strbuf_simple) { diff --git a/src/tests/eina/eina_test_stringshare.c b/src/tests/eina/eina_test_stringshare.c index 66f2995ddd..ec5391137f 100644 --- a/src/tests/eina/eina_test_stringshare.c +++ b/src/tests/eina/eina_test_stringshare.c @@ -25,8 +25,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" #define TEST0 "test/0" #define TEST1 "test/1" diff --git a/src/tests/eina/eina_test_tiler.c b/src/tests/eina/eina_test_tiler.c index bb159234f9..f53cdd2ed8 100644 --- a/src/tests/eina/eina_test_tiler.c +++ b/src/tests/eina/eina_test_tiler.c @@ -22,8 +22,9 @@ #include +#include + #include "eina_suite.h" -#include "Eina.h" struct test_rect { diff --git a/src/tests/eina/eina_test_tmpstr.c b/src/tests/eina/eina_test_tmpstr.c index 4959dd3a3e..e341ec62cd 100644 --- a/src/tests/eina/eina_test_tmpstr.c +++ b/src/tests/eina/eina_test_tmpstr.c @@ -20,10 +20,11 @@ # include "config.h" #endif -#include "eina_suite.h" -#include "Eina.h" +#include #include "eina_tmpstr.h" +#include "eina_suite.h" + START_TEST(tmpstr_simple) { eina_init(); diff --git a/src/tests/eina/eina_test_trash.c b/src/tests/eina/eina_test_trash.c index b56d4afad0..92346eb7ba 100644 --- a/src/tests/eina/eina_test_trash.c +++ b/src/tests/eina/eina_test_trash.c @@ -19,8 +19,9 @@ # include "config.h" #endif +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(trash_simple) { @@ -30,11 +31,11 @@ START_TEST(trash_simple) int inp_int = 9; int inp_char = inp_int + '0'; void *data; - + eina_init(); - + trash = calloc(1, sizeof(Eina_Trash)); - fail_if(trash == NULL); + fail_if(trash == NULL); eina_trash_init(&trash); for (i = 1; i < 51; ++i) @@ -54,9 +55,9 @@ START_TEST(trash_simple) fail_if(*((char *)eina_array_data_get(data, 0)) != inp_char); data = eina_trash_pop(&trash); fail_if(!data); - fail_if(*((int *)eina_array_data_get(data, 0)) != inp_int); + fail_if(*((int *)eina_array_data_get(data, 0)) != inp_int); free(data); - + i = 0; EINA_TRASH_CLEAN(&trash, data) { @@ -66,7 +67,7 @@ START_TEST(trash_simple) } fail_if(i != 98); - + eina_shutdown(); } END_TEST @@ -76,4 +77,3 @@ eina_test_trash(TCase *tc) { tcase_add_test(tc, trash_simple); } - diff --git a/src/tests/eina/eina_test_ustr.c b/src/tests/eina/eina_test_ustr.c index fb36fd9013..eba07e37e2 100644 --- a/src/tests/eina/eina_test_ustr.c +++ b/src/tests/eina/eina_test_ustr.c @@ -25,8 +25,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" #ifdef EINA_SAFETY_CHECKS struct log_ctx { @@ -634,4 +635,3 @@ eina_test_ustr(TCase *tc) tcase_add_test(tc,eina_unicode_utf8_conversion); } - diff --git a/src/tests/eina/eina_test_ustringshare.c b/src/tests/eina/eina_test_ustringshare.c index 1b1ffb262d..8a31cf3144 100644 --- a/src/tests/eina/eina_test_ustringshare.c +++ b/src/tests/eina/eina_test_ustringshare.c @@ -25,8 +25,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" static const Eina_Unicode TEST0[] = {'t', 'e', 's', 't', '/', '0', 0}; static const Eina_Unicode TEST1[] = {'t', 'e', 's', 't', '/', '1', 0}; diff --git a/src/tests/eina/eina_test_value.c b/src/tests/eina/eina_test_value.c index 9e1b8081eb..287a200c0a 100644 --- a/src/tests/eina/eina_test_value.c +++ b/src/tests/eina/eina_test_value.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" #define FP_ERR (1) #define CHECK_FP(a, b) ((a - b) <= FP_ERR) @@ -1043,7 +1044,7 @@ START_TEST(eina_value_test_convert_uchar) eina_shutdown(); } END_TEST - + START_TEST(eina_value_test_convert_short) { Eina_Value *value, conv; @@ -1797,7 +1798,7 @@ START_TEST(eina_value_test_convert_float) float max_float_value = FLT_MAX; float min_float_value = FLT_MIN; - + eina_init(); value = eina_value_new(EINA_VALUE_TYPE_FLOAT); @@ -1899,7 +1900,7 @@ START_TEST(eina_value_test_convert_float) eina_value_flush(&conv); fail_unless(eina_value_set(value, min_float_value)); - + fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT)); fail_unless(eina_value_convert(value, &conv)); fail_unless(eina_value_get(&conv, &f)); @@ -1949,7 +1950,7 @@ START_TEST(eina_value_test_convert_float) eina_value_free(value); eina_shutdown(); - + } END_TEST @@ -2761,7 +2762,7 @@ START_TEST(eina_value_test_optional_int) /* ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_INT, &expected_value)); */ /* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */ /* ck_assert(!is_empty); */ - + /* // gets the actual value */ /* ck_assert(eina_value_optional_pget(value, &actual_value)); */ /* ck_assert_int_eq(expected_value, actual_value); */ @@ -2865,7 +2866,7 @@ START_TEST(eina_value_test_optional_struct_members) eina_value_flush(&actual_value); eina_value_flush(&expected_value); - + eina_value_free(value); eina_shutdown(); diff --git a/src/tests/eina/eina_test_vector.c b/src/tests/eina/eina_test_vector.c index 7f8cdbdf02..8657685295 100644 --- a/src/tests/eina/eina_test_vector.c +++ b/src/tests/eina/eina_test_vector.c @@ -24,8 +24,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" START_TEST(eina_test_vector2_operations) { diff --git a/src/tests/eina/eina_test_xattr.c b/src/tests/eina/eina_test_xattr.c index 43a315aee3..858c6b552b 100644 --- a/src/tests/eina/eina_test_xattr.c +++ b/src/tests/eina/eina_test_xattr.c @@ -25,8 +25,9 @@ #include #include +#include + #include "eina_suite.h" -#include "Eina.h" Eina_Tmpstr* get_file_path(const char* tmpdirname, const char* filename) diff --git a/src/tests/eina_cxx/eina_cxx_suite.cc b/src/tests/eina_cxx/eina_cxx_suite.cc index 3bb028d1a4..6a03f22f81 100644 --- a/src/tests/eina_cxx/eina_cxx_suite.cc +++ b/src/tests/eina_cxx/eina_cxx_suite.cc @@ -1,36 +1,11 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include "eina_cxx_suite.h" +#include "../efl_check.h" -#include -#include - -#include - -void eina_test_inlist(TCase* tc); -void eina_test_inarray(TCase* tc); -void eina_test_ptrlist(TCase* tc); -void eina_test_ptrarray(TCase* tc); -void eina_test_iterator(TCase* tc); -void eina_test_stringshare(TCase* tc); -void eina_test_error(TCase* tc); -void eina_test_accessor(TCase* tc); -void eina_test_thread(TCase* tc); -void eina_test_optional(TCase* tc); -void eina_test_value(TCase* tc); -void eina_test_log(TCase* tc); - -typedef struct _Eina_Test_Case Eina_Test_Case; -struct _Eina_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eina_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Ptr_List", eina_test_ptrlist }, { "Ptr_Array", eina_test_ptrarray }, { "Inlist", eina_test_inlist }, @@ -46,88 +21,18 @@ static const Eina_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) +int +main(int argc, char* argv[]) { - const Eina_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} + int failed_count; -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -eina_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eina C++"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - -int main(int argc, char* argv[]) -{ - Suite *s; - SRunner *sr; - int i, failed_count; - - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv(const_cast("EFL_RUN_IN_TREE=1")); - s = eina_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); - - eina_shutdown(); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eina C++", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eina_cxx/eina_cxx_suite.h b/src/tests/eina_cxx/eina_cxx_suite.h new file mode 100644 index 0000000000..41e9af7f6a --- /dev/null +++ b/src/tests/eina_cxx/eina_cxx_suite.h @@ -0,0 +1,22 @@ +#ifndef _EINA_CXX_SUITE_H +#define _EINA_CXX_SUITE_H + +#include +#include + +#include + +void eina_test_inlist(TCase* tc); +void eina_test_inarray(TCase* tc); +void eina_test_ptrlist(TCase* tc); +void eina_test_ptrarray(TCase* tc); +void eina_test_iterator(TCase* tc); +void eina_test_stringshare(TCase* tc); +void eina_test_error(TCase* tc); +void eina_test_accessor(TCase* tc); +void eina_test_thread(TCase* tc); +void eina_test_optional(TCase* tc); +void eina_test_value(TCase* tc); +void eina_test_log(TCase* tc); + +#endif /* _EINA_CXX_SUITE_H */ diff --git a/src/tests/eina_cxx/eina_cxx_test_accessor.cc b/src/tests/eina_cxx/eina_cxx_test_accessor.cc index af49fb9bf2..9737f0d383 100644 --- a/src/tests/eina_cxx/eina_cxx_test_accessor.cc +++ b/src/tests/eina_cxx/eina_cxx_test_accessor.cc @@ -1,14 +1,11 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" -#include "Eo.hh" +#include +#include -#include - -#include +#include "eina_cxx_suite.h" extern "C" { #include "simple.eo.h" diff --git a/src/tests/eina_cxx/eina_cxx_test_error.cc b/src/tests/eina_cxx/eina_cxx_test_error.cc index 8cea5b55b0..28c5b4b741 100644 --- a/src/tests/eina_cxx/eina_cxx_test_error.cc +++ b/src/tests/eina_cxx/eina_cxx_test_error.cc @@ -1,11 +1,10 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include -#include +#include "eina_cxx_suite.h" Eina_Error my_error, my_error_2; @@ -16,7 +15,7 @@ START_TEST(eina_cxx_get_error) my_error = ::eina_error_msg_static_register("Message 1"); ::eina_error_set(0); - + efl::eina::error_code ec1 = efl::eina::get_error_code(); ck_assert(!ec1); @@ -24,14 +23,14 @@ START_TEST(eina_cxx_get_error) efl::eina::error_code ec2 = efl::eina::get_error_code(); ck_assert(!!ec2); - + ck_assert(ec2.message() == "Message 1"); ::eina_error_set(EINA_ERROR_OUT_OF_MEMORY); efl::eina::error_code ec3 = efl::eina::get_error_code(); ck_assert(!!ec3); - + ck_assert(ec3.message() == "Out of memory"); } END_TEST diff --git a/src/tests/eina_cxx/eina_cxx_test_inarray.cc b/src/tests/eina_cxx/eina_cxx_test_inarray.cc index 995ae9bfc6..2792c19168 100644 --- a/src/tests/eina_cxx/eina_cxx_test_inarray.cc +++ b/src/tests/eina_cxx/eina_cxx_test_inarray.cc @@ -1,16 +1,13 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" - -#include #include - #include -#include +#include + +#include "eina_cxx_suite.h" START_TEST(eina_cxx_inarray_pod_push_back) { @@ -139,7 +136,7 @@ START_TEST(eina_cxx_inarray_pod_erase) array1.push_back(20); array1.push_back(25); array1.push_back(30); - + efl::eina::inarray::iterator it = array1.begin(), it2; it = array1.erase(it); @@ -152,7 +149,7 @@ START_TEST(eina_cxx_inarray_pod_erase) it = array1.erase(it); ck_assert(*it == 20); ck_assert(array1.size() == 4); - + it = array1.end() - 1; it = array1.erase(it); ck_assert(it == array1.end()); @@ -354,7 +351,7 @@ START_TEST(eina_cxx_inarray_nonpod_erase) array1.push_back(20); array1.push_back(25); array1.push_back(30); - + efl::eina::inarray::iterator it = array1.begin(), it2; it = array1.erase(it); @@ -367,13 +364,13 @@ START_TEST(eina_cxx_inarray_nonpod_erase) it = array1.erase(it); ck_assert(*it == 20); ck_assert(array1.size() == 4); - + it = array1.end() - 1; it = array1.erase(it); ck_assert(it == array1.end()); ck_assert(array1.size() == 3); ck_assert(array1.back() == 25); - + it = array1.begin() + 1; it2 = array1.end() - 1; it = array1.erase(it, it2); diff --git a/src/tests/eina_cxx/eina_cxx_test_inlist.cc b/src/tests/eina_cxx/eina_cxx_test_inlist.cc index 144dfe4488..717eb0c70f 100644 --- a/src/tests/eina_cxx/eina_cxx_test_inlist.cc +++ b/src/tests/eina_cxx/eina_cxx_test_inlist.cc @@ -1,14 +1,12 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" - -#include #include -#include +#include + +#include "eina_cxx_suite.h" struct Eina_Test_Inlist { @@ -180,7 +178,7 @@ START_TEST(eina_cxx_inlist_erase) list1.push_back(20); list1.push_back(25); list1.push_back(30); - + efl::eina::inlist::iterator it = list1.begin(), it2; it = list1.erase(it); @@ -197,7 +195,7 @@ START_TEST(eina_cxx_inlist_erase) ck_assert(it == it2); ck_assert(list1.size() == 4); ck_assert(*it2 == 20); - + it = list1.end(); --it; it = list1.erase(it); @@ -232,7 +230,7 @@ START_TEST(eina_cxx_inlist_range) list.push_back(30); efl::eina::range_inlist range_list(list); - + ck_assert(range_list.size() == 6u); int result[] = {5, 10, 15, 20, 25, 30}; diff --git a/src/tests/eina_cxx/eina_cxx_test_iterator.cc b/src/tests/eina_cxx/eina_cxx_test_iterator.cc index 5a0a393479..8f7136a9fc 100644 --- a/src/tests/eina_cxx/eina_cxx_test_iterator.cc +++ b/src/tests/eina_cxx/eina_cxx_test_iterator.cc @@ -1,13 +1,10 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include -#include - -#include +#include "eina_cxx_suite.h" START_TEST(eina_cxx_iterator_equal) { @@ -21,7 +18,7 @@ START_TEST(eina_cxx_iterator_equal) list.push_back(new int(10)); list.push_back(new int(15)); list.push_back(new int(20)); - + efl::eina::iterator iterator = list.ibegin() , last_iterator = list.iend(); diff --git a/src/tests/eina_cxx/eina_cxx_test_log.cc b/src/tests/eina_cxx/eina_cxx_test_log.cc index e20ebdffdf..6e51780dde 100644 --- a/src/tests/eina_cxx/eina_cxx_test_log.cc +++ b/src/tests/eina_cxx/eina_cxx_test_log.cc @@ -1,13 +1,10 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include -#include - -#include +#include "eina_cxx_suite.h" bool expensive_called = false; diff --git a/src/tests/eina_cxx/eina_cxx_test_optional.cc b/src/tests/eina_cxx/eina_cxx_test_optional.cc index 4043cb064c..31e9ffe12b 100644 --- a/src/tests/eina_cxx/eina_cxx_test_optional.cc +++ b/src/tests/eina_cxx/eina_cxx_test_optional.cc @@ -1,16 +1,13 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" - -#include - -#include - #include +#include + +#include "eina_cxx_suite.h" + std::size_t nonpod_constructed = 0u , nonpod_destructed = 0u; diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc index 2bf8bb5580..6b2f6271d8 100644 --- a/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc +++ b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc @@ -1,16 +1,13 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" -#include "Eo.hh" - +#include #include +#include -#include +#include "eina_cxx_suite.h" -#include extern "C" { #include "simple.eo.h" } @@ -32,7 +29,7 @@ START_TEST(eina_cxx_ptrarray_push_back) wrapper const w1(eo_add(SIMPLE_CLASS, NULL)); wrapper const w2(eo_add(SIMPLE_CLASS, NULL)); wrapper const w3(eo_add(SIMPLE_CLASS, NULL)); - + { efl::eina::ptr_array array; @@ -335,7 +332,7 @@ START_TEST(eina_cxx_ptrarray_erase) int rresult[] = {30, 25, 20, 15, 10, 5}; ck_assert(std::equal(array1.begin(), array1.end(), result)); ck_assert(std::equal(array1.rbegin(), array1.rend(), rresult)); - + efl::eina::ptr_array::iterator it = array1.erase(array1.begin()); ck_assert(it == array1.begin()); ck_assert(array1.size() == 5); @@ -346,7 +343,7 @@ START_TEST(eina_cxx_ptrarray_erase) it = array1.erase(array1.begin() + 1); ck_assert(*it == 20); ck_assert(array1.size() == 4); - + it = array1.erase(array1.end() - 1); ck_assert(it == array1.end()); ck_assert(array1.size() == 3); @@ -365,9 +362,9 @@ START_TEST(eina_cxx_ptrarray_erase) wrapper const w4(eo_add(SIMPLE_CLASS, NULL)); wrapper const w5(eo_add(SIMPLE_CLASS, NULL)); wrapper const w6(eo_add(SIMPLE_CLASS, NULL)); - + efl::eina::array array1; - + array1.push_back(w1); array1.push_back(w2); array1.push_back(w3); @@ -379,7 +376,7 @@ START_TEST(eina_cxx_ptrarray_erase) wrapper rresult[] = {w6, w5, w4, w3, w2, w1}; ck_assert(std::equal(array1.begin(), array1.end(), result_)); ck_assert(std::equal(array1.rbegin(), array1.rend(), rresult)); - + efl::eina::array::iterator it = array1.erase(array1.begin()); ck_assert(it == array1.begin()); ck_assert(array1.size() == 5); @@ -390,7 +387,7 @@ START_TEST(eina_cxx_ptrarray_erase) it = array1.erase(array1.begin() + 1); ck_assert(*it == w4); ck_assert(array1.size() == 4); - + it = array1.erase(array1.end() - 1); ck_assert(it == array1.end()); ck_assert(array1.size() == 3); @@ -420,7 +417,7 @@ START_TEST(eina_cxx_ptrarray_range) array.push_back(new int(30)); efl::eina::range_ptr_array range_array(array); - + ck_assert(range_array.size() == 6u); int result[] = {5, 10, 15, 20, 25, 30}; @@ -456,7 +453,7 @@ START_TEST(eina_cxx_ptrarray_range) array.push_back(w6); // efl::eina::range_array range_array(array); - + // ck_assert(range_array.size() == 6u); // wrapper result[] = {5, 10, 15, 20, 25, 30}; diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc index 281740d851..039ef971bc 100644 --- a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc +++ b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc @@ -1,17 +1,14 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" -#include "Eo.hh" - -#include - -#include #include -#include +#include +#include +#include + +#include "eina_cxx_suite.h" extern "C" { #include "simple.eo.h" @@ -34,7 +31,7 @@ START_TEST(eina_cxx_ptrlist_push_back) wrapper const w1(eo_add(SIMPLE_CLASS, NULL)); wrapper const w2(eo_add(SIMPLE_CLASS, NULL)); wrapper const w3(eo_add(SIMPLE_CLASS, NULL)); - + { efl::eina::ptr_list list; @@ -162,7 +159,7 @@ START_TEST(eina_cxx_ptrlist_push_front) ck_assert(list.size() == 3); ck_assert(std::equal(list.begin(), list.end(), result)); ck_assert(std::equal(list.rbegin(), list.rend(), rresult)); - } + } } END_TEST @@ -408,7 +405,7 @@ START_TEST(eina_cxx_ptrlist_erase) list1.push_back(new int(20)); list1.push_back(new int(25)); list1.push_back(new int(30)); - + efl::eina::ptr_list::iterator it = list1.begin(), it2; it = list1.erase(it); @@ -425,7 +422,7 @@ START_TEST(eina_cxx_ptrlist_erase) ck_assert(it == it2); ck_assert(list1.size() == 4); ck_assert(*it2 == 20); - + it = list1.end(); --it; it = list1.erase(it); @@ -460,7 +457,7 @@ START_TEST(eina_cxx_ptrlist_range) list.push_back(new int(30)); efl::eina::range_ptr_list range_list(list); - + ck_assert(range_list.size() == 6u); int result[] = {5, 10, 15, 20, 25, 30}; diff --git a/src/tests/eina_cxx/eina_cxx_test_stringshare.cc b/src/tests/eina_cxx/eina_cxx_test_stringshare.cc index d10ad362e3..11bce25c7f 100644 --- a/src/tests/eina_cxx/eina_cxx_test_stringshare.cc +++ b/src/tests/eina_cxx/eina_cxx_test_stringshare.cc @@ -3,12 +3,11 @@ # include #endif -#include "Eina.hh" - -#include #include -#include +#include + +#include "eina_cxx_suite.h" START_TEST(eina_cxx_stringshare_constructors) { diff --git a/src/tests/eina_cxx/eina_cxx_test_thread.cc b/src/tests/eina_cxx/eina_cxx_test_thread.cc index abf1c7aa18..f464c26667 100644 --- a/src/tests/eina_cxx/eina_cxx_test_thread.cc +++ b/src/tests/eina_cxx/eina_cxx_test_thread.cc @@ -1,13 +1,10 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include -#include - -#include +#include "eina_cxx_suite.h" bool no_args = false , args_1 = false diff --git a/src/tests/eina_cxx/eina_cxx_test_value.cc b/src/tests/eina_cxx/eina_cxx_test_value.cc index d57980a303..d4864b6ac0 100644 --- a/src/tests/eina_cxx/eina_cxx_test_value.cc +++ b/src/tests/eina_cxx/eina_cxx_test_value.cc @@ -1,11 +1,10 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eina.hh" +#include -#include +#include "eina_cxx_suite.h" START_TEST(eina_cxx_value_constructors) { diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c index 270cb870ad..c6aa8d8639 100644 --- a/src/tests/eio/eio_model_test_file.c +++ b/src/tests/eio/eio_model_test_file.c @@ -4,14 +4,15 @@ # include #endif -#include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include +#include + +#include "eio_suite.h" #define EFL_MODEL_TEST_FILENAME_PATH "/tmp" #define EFL_MODEL_MAX_TEST_CHILDS 16 @@ -176,7 +177,7 @@ START_TEST(eio_model_test_test_file) handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL); ecore_main_loop_begin(); - + eo_do(filemodel, status = efl_model_property_get("filename", &value_prop)); str = eina_value_to_string(value_prop); printf("efl_model_test filename %s, load status %d\n", str, status); @@ -216,4 +217,3 @@ eio_model_test_file(TCase *tc) { tcase_add_test(tc, eio_model_test_test_file); } - diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c index 8230ec2f26..a0ad69ef7d 100644 --- a/src/tests/eio/eio_model_test_monitor_add.c +++ b/src/tests/eio/eio_model_test_monitor_add.c @@ -4,14 +4,15 @@ # include #endif -#include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include +#include + +#include "eio_suite.h" Eina_Bool children_added = EINA_FALSE; Eina_Tmpstr* temp_filename = NULL; @@ -123,7 +124,7 @@ START_TEST(eio_model_test_test_monitor_add) fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); tmpdir = eina_environment_tmp_get(); - + filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(tmpdir)); fail_if(!filemodel, "ERROR: Cannot init model!\n"); @@ -150,4 +151,3 @@ eio_model_test_monitor_add(TCase *tc) { tcase_add_test(tc, eio_model_test_test_monitor_add); } - diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c index 4dfdbfbc5a..39ce8f769a 100644 --- a/src/tests/eio/eio_suite.c +++ b/src/tests/eio/eio_suite.c @@ -2,22 +2,10 @@ # include #endif -#include -#include - -#include - #include "eio_suite.h" +#include "../efl_check.h" -typedef struct _Eio_Test_Case Eio_Test_Case; - -struct _Eio_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eio_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { {"Eio_Monitor", eio_test_monitor}, {"Eio Model", eio_model_test_file}, {"Eio Model Monitor", eio_model_test_monitor_add}, @@ -28,86 +16,18 @@ static const Eio_Test_Case etc[] = { {NULL, NULL} }; -static void -_list_tests(void) -{ - const Eio_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -eio_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eio"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); - tcase_set_timeout(tc, 0); - } - - return s; -} - - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = eio_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eio", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eio/eio_test_file.c b/src/tests/eio/eio_test_file.c index c17246ec26..5513e9013a 100644 --- a/src/tests/eio/eio_test_file.c +++ b/src/tests/eio/eio_test_file.c @@ -8,9 +8,9 @@ #include #include -#include #include #include +#include #include "eio_suite.h" @@ -374,4 +374,3 @@ eio_test_file(TCase *tc) tcase_add_test(tc, eio_file_test_ls); tcase_add_test(tc, eio_file_test_file); } - diff --git a/src/tests/eio/eio_test_monitor.c b/src/tests/eio/eio_test_monitor.c index daf2a3fd0d..fbf813486b 100644 --- a/src/tests/eio/eio_test_monitor.c +++ b/src/tests/eio/eio_test_monitor.c @@ -6,9 +6,9 @@ #include #include -#include #include #include +#include #include "eio_suite.h" @@ -147,9 +147,9 @@ START_TEST(eio_test_monitor_add_and_remove) //monitor directory monitor = eio_monitor_add(filename); - + usleep(500000); - + eio_monitor_del(monitor); _common_shutdown(dirname); @@ -172,9 +172,9 @@ START_TEST(eio_test_monitor_add_remove_add) //monitor directory monitor1 = eio_monitor_add(filename); eio_monitor_del(monitor1); - + usleep(500000); - + monitor2 = eio_monitor_add(filename); eio_monitor_del(monitor2); @@ -199,7 +199,7 @@ START_TEST(eio_test_monitor_add_add_remove_remove) usleep(500000); //monitor directory - monitor1 = eio_monitor_add(filename1); + monitor1 = eio_monitor_add(filename1); monitor2 = eio_monitor_add(filename2); usleep(500000); eio_monitor_del(monitor2); @@ -727,7 +727,7 @@ void eio_test_monitor(TCase *tc) tcase_add_test(tc, eio_test_monitor_add_and_remove); tcase_add_test(tc, eio_test_monitor_add_remove_add); tcase_add_test(tc, eio_test_monitor_add_add_remove_remove); - + tcase_add_test(tc, eio_test_monitor_directory_file_created_notify); tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify); tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify); diff --git a/src/tests/eio/eio_test_xattr.c b/src/tests/eio/eio_test_xattr.c index 6f15fac44c..0b1b298cb8 100644 --- a/src/tests/eio/eio_test_xattr.c +++ b/src/tests/eio/eio_test_xattr.c @@ -7,9 +7,9 @@ #include #include -#include #include #include +#include #include "eio_suite.h" diff --git a/src/tests/eldbus/eldbus_fake_server.c b/src/tests/eldbus/eldbus_fake_server.c index da1f4022da..ea6e4eaa5a 100644 --- a/src/tests/eldbus/eldbus_fake_server.c +++ b/src/tests/eldbus/eldbus_fake_server.c @@ -2,11 +2,10 @@ #include "config.h" #endif -#include "eldbus_fake_server.h" - #include -#include +#include "eldbus_suite.h" +#include "eldbus_fake_server.h" #define FAKE_SERVER_DATA_KEY "data" diff --git a/src/tests/eldbus/eldbus_suite.c b/src/tests/eldbus/eldbus_suite.c index 8b6a181e1e..dd79e33cb1 100644 --- a/src/tests/eldbus/eldbus_suite.c +++ b/src/tests/eldbus/eldbus_suite.c @@ -2,22 +2,10 @@ # include #endif -#include -#include - -#include - #include "eldbus_suite.h" +#include "../efl_check.h" -typedef struct _Eldbus_Test_Case Eldbus_Test_Case; - -struct _Eldbus_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eldbus_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "eldbus_init", eldbus_test_eldbus_init }, { "eldbus_model", eldbus_test_eldbus_model }, { "eldbus_model_connection", eldbus_test_eldbus_model_connection }, @@ -29,89 +17,18 @@ static const Eldbus_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eldbus_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - printf("\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - { - if (strcmp(test_case, *argv) == 0) - return 1; - } - return 0; -} - -static Suite * -eldbus_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eldbus"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = eldbus_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eldbus", etc); return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/src/tests/eldbus/eldbus_test_eldbus_model.c b/src/tests/eldbus/eldbus_test_eldbus_model.c index ebf91d7108..771d942948 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model.c @@ -2,18 +2,18 @@ # include #endif -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" - -#include -#include -#include -#include - #include #include #include +#include +#include +#include +#include + +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" + static Eina_Bool _eo_event_quit_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, diff --git a/src/tests/eldbus/eldbus_test_eldbus_model.h b/src/tests/eldbus/eldbus_test_eldbus_model.h index 2d8603a72d..b1909170d6 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model.h +++ b/src/tests/eldbus/eldbus_test_eldbus_model.h @@ -1,9 +1,9 @@ #ifndef _ELDBUS_TEST_ELDBUS_MODEL_H #define _ELDBUS_TEST_ELDBUS_MODEL_H +#include #include #include -#include void check_init(void); void check_shutdown(void); diff --git a/src/tests/eldbus/eldbus_test_eldbus_model_connection.c b/src/tests/eldbus/eldbus_test_eldbus_model_connection.c index 4dc9f3decd..ffcc7950a3 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model_connection.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model_connection.c @@ -2,14 +2,14 @@ # include #endif -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" static Eo *connection = NULL; static Eo *unloaded_connection = NULL; diff --git a/src/tests/eldbus/eldbus_test_eldbus_model_method.c b/src/tests/eldbus/eldbus_test_eldbus_model_method.c index 6c9dc5b008..e4f7a814e1 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model_method.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model_method.c @@ -2,15 +2,15 @@ # include #endif -#include "eldbus_fake_server.h" -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_fake_server.h" +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" #define ARGUMENT_A "arg0" #define ARGUMENT_B "arg1" diff --git a/src/tests/eldbus/eldbus_test_eldbus_model_object.c b/src/tests/eldbus/eldbus_test_eldbus_model_object.c index a03edccd4b..c1f12485d9 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model_object.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model_object.c @@ -2,14 +2,14 @@ # include #endif -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" static Eo *object = NULL; static Eo *unloaded_object = NULL; diff --git a/src/tests/eldbus/eldbus_test_eldbus_model_proxy.c b/src/tests/eldbus/eldbus_test_eldbus_model_proxy.c index e0fca2a1fc..98ce124d1e 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model_proxy.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model_proxy.c @@ -2,14 +2,14 @@ # include #endif -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" static Eo *dbus_object1 = NULL; static Eo *dbus_object2 = NULL; diff --git a/src/tests/eldbus/eldbus_test_eldbus_model_signal.c b/src/tests/eldbus/eldbus_test_eldbus_model_signal.c index 1a7e907905..3185f2ec68 100644 --- a/src/tests/eldbus/eldbus_test_eldbus_model_signal.c +++ b/src/tests/eldbus/eldbus_test_eldbus_model_signal.c @@ -2,15 +2,15 @@ # include #endif -#include "eldbus_fake_server.h" -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_fake_server.h" +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" #define ARGUMENT_A "arg0" diff --git a/src/tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c b/src/tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c index d4161b6b99..7a12d326b1 100644 --- a/src/tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c +++ b/src/tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c @@ -2,15 +2,15 @@ # include #endif -#include "eldbus_fake_server.h" -#include "eldbus_suite.h" -#include "eldbus_test_eldbus_model.h" +#include -#include #include +#include #include -#include +#include "eldbus_fake_server.h" +#include "eldbus_test_eldbus_model.h" +#include "eldbus_suite.h" static Eo *fake_server_object = NULL; static Eo *fake_server_proxy = NULL; @@ -92,7 +92,7 @@ START_TEST(property_get) Efl_Model_Load_Status status; eo_do(fake_server_proxy, status = efl_model_property_get(FAKE_SERVER_WRITEONLY_PROPERTY, &dummy)); ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_ERROR, status); - + _teardown(); } END_TEST diff --git a/src/tests/eldbus_cxx/eldbus_cxx_suite.cc b/src/tests/eldbus_cxx/eldbus_cxx_suite.cc index c7b6b527d1..ca15b776c8 100644 --- a/src/tests/eldbus_cxx/eldbus_cxx_suite.cc +++ b/src/tests/eldbus_cxx/eldbus_cxx_suite.cc @@ -1,112 +1,27 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include -#include "Eldbus.hh" +#include "eldbus_cxx_suite.h" +#include "../efl_check.h" -#include -#include - -#include - -void eldbus_test_connection(TCase* tc); -void eldbus_test_client(TCase* tc); - -typedef struct _Eldbus_Test_Case Eldbus_Test_Case; -struct _Eldbus_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eldbus_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "connection", eldbus_test_connection }, { "client", eldbus_test_client }, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eldbus_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -eldbus_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eldbus"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - int main(int argc, char* argv[]) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv(const_cast("EFL_RUN_IN_TREE=1")); - s = eldbus_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eldbus C++", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eldbus_cxx/eldbus_cxx_suite.h b/src/tests/eldbus_cxx/eldbus_cxx_suite.h new file mode 100644 index 0000000000..1dd4a6461a --- /dev/null +++ b/src/tests/eldbus_cxx/eldbus_cxx_suite.h @@ -0,0 +1,12 @@ +#ifndef _ELDBUS_CXX_SUITE_H +#define _ELDBUS_CXX_SUITE_H + +#include +#include + +#include + +void eldbus_test_connection(TCase* tc); +void eldbus_test_client(TCase* tc); + +#endif /* _ELDBUS_CXX_SUITE_H */ diff --git a/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc b/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc index e54645bcfc..95eed8c8c4 100644 --- a/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc +++ b/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_client.cc @@ -1,18 +1,15 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eldbus.hh" -#include "Ecore.hh" - -#include - #include - #include -#include +#include +#include +#include + +#include "eldbus_cxx_suite.h" const char g_bus[] = "org.Enlightenment"; const char g_path[] = "/org/enlightenment"; @@ -396,7 +393,7 @@ START_TEST(eldbus_cxx_client) ("SendStringAndBool" , -1 , std::bind - ([expected_string, expected_bool] + ([expected_string, expected_bool] (std::error_code const& ec, edb::const_message const& msg, std::string i, bool b) { if(!ec) diff --git a/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_connect.cc b/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_connect.cc index ffac324b9a..7c4be04b6a 100644 --- a/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_connect.cc +++ b/src/tests/eldbus_cxx/eldbus_cxx_test_eldbus_connect.cc @@ -1,16 +1,14 @@ - #ifdef HAVE_CONFIG_H # include #endif -#include "Eldbus.hh" -#include "Ecore.hh" - #include - #include -#include +#include +#include + +#include "eldbus_cxx_suite.h" START_TEST(eldbus_cxx_session_connection) { diff --git a/src/tests/elua/elua_lib.c b/src/tests/elua/elua_lib.c index ef043bab63..c6a5b6341f 100644 --- a/src/tests/elua/elua_lib.c +++ b/src/tests/elua/elua_lib.c @@ -5,8 +5,9 @@ #include #include -#include -#include "Elua.h" +#include +#include + #include "elua_suite.h" START_TEST(elua_api) diff --git a/src/tests/elua/elua_suite.c b/src/tests/elua/elua_suite.c index 13a6df8f85..1bf0ec81c3 100644 --- a/src/tests/elua/elua_suite.c +++ b/src/tests/elua/elua_suite.c @@ -2,107 +2,28 @@ # include #endif -#include -#include - -#include #include "elua_suite.h" +#include "../efl_check.h" -typedef struct _Elua_Test_Case Elua_Test_Case; - -struct _Elua_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Elua_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Elua Library", elua_lib_test}, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Elua_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -elua_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Elua"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; + setenv("CK_FORK", "no", 0); - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h" ) == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l" ) == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = elua_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Elua", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/elua/elua_suite.h b/src/tests/elua/elua_suite.h index 0d48d02617..7485f5346b 100644 --- a/src/tests/elua/elua_suite.h +++ b/src/tests/elua/elua_suite.h @@ -6,4 +6,3 @@ void elua_lib_test(TCase *tc); #endif /* _ELUA_SUITE_H */ - diff --git a/src/tests/emile/emile_suite.c b/src/tests/emile/emile_suite.c index 1e421fba39..2c968cfc34 100644 --- a/src/tests/emile/emile_suite.c +++ b/src/tests/emile/emile_suite.c @@ -1,231 +1,28 @@ #ifdef HAVE_CONFIG_H #include -#endif /* ifdef HAVE_CONFIG_H */ - -#include -#include - -#include - -#include -#include - -START_TEST(emile_test_init) -{ - fail_if(emile_init() <= 0); - fail_if(emile_shutdown() != 0); -} -END_TEST - -/* All cases are taken from https://en.wikipedia.org/wiki/Base64 */ -static const struct { - char *decoded_str; - char *encoded_normal; - char *encoded_url; - unsigned int len; - Eina_Bool not; -} base64_tests[] = { - { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3VyZS4=", "YW55IGNhcm5hbCBwbGVhc3VyZS4", 20 }, - { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3VyZQ==", "YW55IGNhcm5hbCBwbGVhc3VyZQ", 19 }, - { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3Vy", "YW55IGNhcm5hbCBwbGVhc3Vy", 18 }, - { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3U=", "YW55IGNhcm5hbCBwbGVhc3U", 17 }, - { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhcw==", "YW55IGNhcm5hbCBwbGVhcw", 16 }, - { "pleasure.", "cGxlYXN1cmUu", "cGxlYXN1cmUu", 9 }, - { "leasure.", "bGVhc3VyZS4=", "bGVhc3VyZS4", 8 }, - { "easure.", "ZWFzdXJlLg==", "ZWFzdXJlLg", 7 }, - { "asure.", "YXN1cmUu", "YXN1cmUu", 6 }, - { "sure.", "c3VyZS4=", "c3VyZS4", 5 }, - /* The following 2 cases are manually generated for -/ testing*/ - { "aabc123!?", "YWFiYzEyMyE/", "YWFiYzEyMyE_", 9 }, - { "abc123!?$*&()'-=@~", "YWJjMTIzIT8kKiYoKSctPUB+", "YWJjMTIzIT8kKiYoKSctPUB-", 18 } -}; - -START_TEST(emile_test_base64) -{ - Eina_Binbuf *buffer, *decoded; - Eina_Strbuf *str, *encoded; - unsigned int i; - - buffer = eina_binbuf_new(); - str = eina_strbuf_new(); - - for (i = 0; i < sizeof (base64_tests) / sizeof (base64_tests[0]); i++) - { - eina_binbuf_append_length(buffer, (const unsigned char *) base64_tests[i].decoded_str, base64_tests[i].len); - eina_strbuf_append(str, base64_tests[i].encoded_normal); - - encoded = emile_base64_encode(buffer); - fail_if(strcmp(eina_strbuf_string_get(encoded), base64_tests[i].encoded_normal)); - - decoded = emile_base64_decode(str); - fail_if(memcmp(eina_binbuf_string_get(decoded), base64_tests[i].decoded_str, base64_tests[i].len)); - - fail_if(eina_binbuf_length_get(decoded) != base64_tests[i].len); - - eina_strbuf_free(encoded); - eina_binbuf_free(decoded); - - eina_binbuf_reset(buffer); - eina_strbuf_reset(str); - } - - //Failure scenarios. - decoded = emile_base64_decode(NULL); - fail_if(decoded); - - eina_strbuf_append(str, "TWFu"); - decoded = emile_base64_decode(str); - eina_strbuf_reset(str); - - fail_if(memcmp(eina_binbuf_string_get(decoded), "Man", 3)); - eina_binbuf_free(decoded); - - eina_strbuf_append(str, "abc"); - decoded = emile_base64_decode(str); - eina_strbuf_reset(str); - fail_if(decoded); -} -END_TEST - -START_TEST(emile_test_base64url) -{ - Eina_Binbuf *buffer, *decoded; - Eina_Strbuf *str, *encoded; - unsigned int i; - - buffer = eina_binbuf_new(); - str = eina_strbuf_new(); - - for (i = 0; i < sizeof (base64_tests) / sizeof (base64_tests[0]); i++) - { - eina_binbuf_append_length(buffer, (const unsigned char *) base64_tests[i].decoded_str, base64_tests[i].len); - eina_strbuf_append(str, base64_tests[i].encoded_url); - - encoded = emile_base64url_encode(buffer); - fail_if(strcmp(eina_strbuf_string_get(encoded), base64_tests[i].encoded_url)); - - decoded = emile_base64url_decode(str); - fail_if(memcmp(eina_binbuf_string_get(decoded), base64_tests[i].decoded_str, base64_tests[i].len)); - - fail_if(eina_binbuf_length_get(decoded) != base64_tests[i].len); - - eina_strbuf_free(encoded); - eina_binbuf_free(decoded); - - eina_binbuf_reset(buffer); - eina_strbuf_reset(str); - } - - //Failure scenarios. - decoded = emile_base64url_decode(NULL); - fail_if(decoded); - - eina_strbuf_append(str, "TWFu"); - decoded = emile_base64url_decode(str); - fail_if(memcmp(eina_binbuf_string_get(decoded), "Man", 3)); -} -END_TEST - -static void -emile_base_test(TCase *tc) -{ - tcase_add_test(tc, emile_test_init); -} - -static void -emile_base64_test(TCase *tc) -{ - tcase_add_test(tc, emile_test_base64); - tcase_add_test(tc, emile_test_base64url); -} - -static const struct -{ - const char *name; - void (*build)(TCase *tc); -} tests[] = { - { "Emile_Base", emile_base_test }, - { "Emile_Base64", emile_base64_test } -}; - -static void -_list_tests(void) -{ - unsigned int i; - - fputs("Available tests cases :\n", stderr); - for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) - fprintf(stderr, "\t%s\n", tests[i].name); -} - -static Eina_Bool -_use_test(const char *name, int argc, const char *argv[]) -{ - argc--; - argv--; - - if (argc < 1) - return EINA_TRUE; - - for (; argc > 1; argc--, argv++) - if (strcmp(name, *argv) == 0) - return EINA_TRUE; - return EINA_FALSE; -} - -static Suite * -emile_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - unsigned int i; - - s = suite_create("Emile"); - - for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i) - { - if (!_use_test(tests[i].name, argc, argv)) - continue; - - tc = tcase_create(tests[i].name); - tests[i].build(tc); - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); #endif - } - return s; -} +#include "emile_suite.h" +#include "../efl_check.h" + +static const Efl_Test_Case etc[] = { + { "Emile_Base", emile_test_base }, + { "Emile_Base64", emile_test_base64 }, + { NULL, NULL } +}; int main(int argc, char *argv[]) { - SRunner *sr; - Suite *s; int failed_count; - int j; - for (j = 1; j < argc; j++) - if ((strcmp(argv[j], "-h") == 0) || (strcmp(argv[j], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[j], "-l") == 0) || (strcmp(argv[j], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; - s = emile_suite_build(argc, (const char **)argv); - sr = srunner_create(s); + putenv("EFL_RUN_IN_TREE=1"); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Emile", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/emile/emile_suite.h b/src/tests/emile/emile_suite.h new file mode 100644 index 0000000000..9e940d107a --- /dev/null +++ b/src/tests/emile/emile_suite.h @@ -0,0 +1,9 @@ +#ifndef _EMILE_SUITE_H +#define _EMILE_SUITE_H + +#include + +void emile_test_base(TCase *tc); +void emile_test_base64(TCase *tc); + +#endif /* _EMILE_SUITE_H */ diff --git a/src/tests/emile/emile_test_base.c b/src/tests/emile/emile_test_base.c new file mode 100644 index 0000000000..d4514d1ea8 --- /dev/null +++ b/src/tests/emile/emile_test_base.c @@ -0,0 +1,20 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "emile_suite.h" + +START_TEST(emile_test_init) +{ + fail_if(emile_init() <= 0); + fail_if(emile_shutdown() != 0); +} +END_TEST + +void emile_test_base(TCase *tc) +{ + tcase_add_test(tc, emile_test_init); +} diff --git a/src/tests/emile/emile_test_base64.c b/src/tests/emile/emile_test_base64.c new file mode 100644 index 0000000000..ca035766c8 --- /dev/null +++ b/src/tests/emile/emile_test_base64.c @@ -0,0 +1,124 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "emile_suite.h" + +/* All cases are taken from https://en.wikipedia.org/wiki/Base64 */ +static const struct { + char *decoded_str; + char *encoded_normal; + char *encoded_url; + unsigned int len; + Eina_Bool not; +} base64_tests[] = { + { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3VyZS4=", "YW55IGNhcm5hbCBwbGVhc3VyZS4", 20 }, + { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3VyZQ==", "YW55IGNhcm5hbCBwbGVhc3VyZQ", 19 }, + { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3Vy", "YW55IGNhcm5hbCBwbGVhc3Vy", 18 }, + { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhc3U=", "YW55IGNhcm5hbCBwbGVhc3U", 17 }, + { "any carnal pleasure.", "YW55IGNhcm5hbCBwbGVhcw==", "YW55IGNhcm5hbCBwbGVhcw", 16 }, + { "pleasure.", "cGxlYXN1cmUu", "cGxlYXN1cmUu", 9 }, + { "leasure.", "bGVhc3VyZS4=", "bGVhc3VyZS4", 8 }, + { "easure.", "ZWFzdXJlLg==", "ZWFzdXJlLg", 7 }, + { "asure.", "YXN1cmUu", "YXN1cmUu", 6 }, + { "sure.", "c3VyZS4=", "c3VyZS4", 5 }, + /* The following 2 cases are manually generated for -/ testing*/ + { "aabc123!?", "YWFiYzEyMyE/", "YWFiYzEyMyE_", 9 }, + { "abc123!?$*&()'-=@~", "YWJjMTIzIT8kKiYoKSctPUB+", "YWJjMTIzIT8kKiYoKSctPUB-", 18 } +}; + +START_TEST(emile_test_base64_normal) +{ + Eina_Binbuf *buffer, *decoded; + Eina_Strbuf *str, *encoded; + unsigned int i; + + buffer = eina_binbuf_new(); + str = eina_strbuf_new(); + + for (i = 0; i < sizeof (base64_tests) / sizeof (base64_tests[0]); i++) + { + eina_binbuf_append_length(buffer, (const unsigned char *) base64_tests[i].decoded_str, base64_tests[i].len); + eina_strbuf_append(str, base64_tests[i].encoded_normal); + + encoded = emile_base64_encode(buffer); + fail_if(strcmp(eina_strbuf_string_get(encoded), base64_tests[i].encoded_normal)); + + decoded = emile_base64_decode(str); + fail_if(memcmp(eina_binbuf_string_get(decoded), base64_tests[i].decoded_str, base64_tests[i].len)); + + fail_if(eina_binbuf_length_get(decoded) != base64_tests[i].len); + + eina_strbuf_free(encoded); + eina_binbuf_free(decoded); + + eina_binbuf_reset(buffer); + eina_strbuf_reset(str); + } + + //Failure scenarios. + decoded = emile_base64_decode(NULL); + fail_if(decoded); + + eina_strbuf_append(str, "TWFu"); + decoded = emile_base64_decode(str); + eina_strbuf_reset(str); + + fail_if(memcmp(eina_binbuf_string_get(decoded), "Man", 3)); + eina_binbuf_free(decoded); + + eina_strbuf_append(str, "abc"); + decoded = emile_base64_decode(str); + eina_strbuf_reset(str); + fail_if(decoded); +} +END_TEST + +START_TEST(emile_test_base64_url) +{ + Eina_Binbuf *buffer, *decoded; + Eina_Strbuf *str, *encoded; + unsigned int i; + + buffer = eina_binbuf_new(); + str = eina_strbuf_new(); + + for (i = 0; i < sizeof (base64_tests) / sizeof (base64_tests[0]); i++) + { + eina_binbuf_append_length(buffer, (const unsigned char *) base64_tests[i].decoded_str, base64_tests[i].len); + eina_strbuf_append(str, base64_tests[i].encoded_url); + + encoded = emile_base64url_encode(buffer); + fail_if(strcmp(eina_strbuf_string_get(encoded), base64_tests[i].encoded_url)); + + decoded = emile_base64url_decode(str); + fail_if(memcmp(eina_binbuf_string_get(decoded), base64_tests[i].decoded_str, base64_tests[i].len)); + + fail_if(eina_binbuf_length_get(decoded) != base64_tests[i].len); + + eina_strbuf_free(encoded); + eina_binbuf_free(decoded); + + eina_binbuf_reset(buffer); + eina_strbuf_reset(str); + } + + //Failure scenarios. + decoded = emile_base64url_decode(NULL); + fail_if(decoded); + + eina_strbuf_append(str, "TWFu"); + decoded = emile_base64url_decode(str); + fail_if(memcmp(eina_binbuf_string_get(decoded), "Man", 3)); +} +END_TEST + +void +emile_test_base64(TCase *tc) +{ + tcase_add_test(tc, emile_test_base64_normal); + tcase_add_test(tc, emile_test_base64_url); +} diff --git a/src/tests/eo/suite/eo_suite.c b/src/tests/eo/suite/eo_suite.c index 7b5702343e..2a62f7b2c6 100644 --- a/src/tests/eo/suite/eo_suite.c +++ b/src/tests/eo/suite/eo_suite.c @@ -2,21 +2,10 @@ # include #endif -#include -#include - -#include "Eo.h" #include "eo_suite.h" +#include "../../efl_check.h" -typedef struct _Eo_Test_Case Eo_Test_Case; - -struct _Eo_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eo_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Eo init", eo_test_init }, { "Eo general", eo_test_general }, { "Eo class errors", eo_test_class_errors }, @@ -27,86 +16,18 @@ static const Eo_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eo_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -eo_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eo"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = eo_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eo", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eo/suite/eo_test_call_errors.c b/src/tests/eo/suite/eo_test_call_errors.c index 5a03cd83b7..48d8a55dfb 100644 --- a/src/tests/eo/suite/eo_test_call_errors.c +++ b/src/tests/eo/suite/eo_test_call_errors.c @@ -4,7 +4,8 @@ #include -#include "Eo.h" +#include + #include "eo_suite.h" #include "eo_error_msgs.h" #include "eo_test_class_simple.h" diff --git a/src/tests/eo/suite/eo_test_class_behaviour_errors.c b/src/tests/eo/suite/eo_test_class_behaviour_errors.c index 8ca7f3d600..83628f69df 100644 --- a/src/tests/eo/suite/eo_test_class_behaviour_errors.c +++ b/src/tests/eo/suite/eo_test_class_behaviour_errors.c @@ -4,7 +4,8 @@ #include -#include "Eo.h" +#include + #include "eo_suite.h" #include "eo_error_msgs.h" #include "eo_test_class_simple.h" diff --git a/src/tests/eo/suite/eo_test_class_errors.c b/src/tests/eo/suite/eo_test_class_errors.c index 2cb84f13d2..6fc6e3be52 100644 --- a/src/tests/eo/suite/eo_test_class_errors.c +++ b/src/tests/eo/suite/eo_test_class_errors.c @@ -4,7 +4,8 @@ #include -#include "Eo.h" +#include + #include "eo_suite.h" #include "eo_error_msgs.h" #include "eo_test_class_simple.h" diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c index 584826db57..f44538944a 100644 --- a/src/tests/eo/suite/eo_test_general.c +++ b/src/tests/eo/suite/eo_test_general.c @@ -6,7 +6,8 @@ #define EO_BASE_BETA -#include "Eo.h" +#include + #include "eo_suite.h" #include "eo_test_class_simple.h" diff --git a/src/tests/eo/suite/eo_test_init.c b/src/tests/eo/suite/eo_test_init.c index daccf7e0f1..ef04d31758 100644 --- a/src/tests/eo/suite/eo_test_init.c +++ b/src/tests/eo/suite/eo_test_init.c @@ -2,12 +2,11 @@ # include "config.h" #endif -#include +#include -#include "Eo.h" #include "eo_suite.h" -START_TEST(eo_simple) +START_TEST(eo_test_simple) { fail_if(!eo_init()); /* one init by test suite */ fail_if(!eo_init()); @@ -16,7 +15,7 @@ START_TEST(eo_simple) } END_TEST -START_TEST(eo_init_shutdown) +START_TEST(eo_test_init_shutdown) { fail_if(!eo_init()); ck_assert_str_eq("Eo_Base", eo_class_name_get(EO_BASE_CLASS)); @@ -30,6 +29,6 @@ END_TEST void eo_test_init(TCase *tc) { - tcase_add_test(tc, eo_simple); - tcase_add_test(tc, eo_init_shutdown); + tcase_add_test(tc, eo_test_simple); + tcase_add_test(tc, eo_test_init_shutdown); } diff --git a/src/tests/eo/suite/eo_test_threaded_calls.c b/src/tests/eo/suite/eo_test_threaded_calls.c index e58b88b613..82a0b98401 100644 --- a/src/tests/eo/suite/eo_test_threaded_calls.c +++ b/src/tests/eo/suite/eo_test_threaded_calls.c @@ -4,7 +4,8 @@ #include -#include "Eo.h" +#include + #include "eo_suite.h" static Eina_Barrier barrier; diff --git a/src/tests/eo/suite/eo_test_value.c b/src/tests/eo/suite/eo_test_value.c index 2372d069ba..cbc7cd762e 100644 --- a/src/tests/eo/suite/eo_test_value.c +++ b/src/tests/eo/suite/eo_test_value.c @@ -4,7 +4,8 @@ #include -#include "Eo.h" +#include + #include "eo_suite.h" #include "eo_test_class_simple.h" diff --git a/src/tests/eolian/eolian_generation.c b/src/tests/eolian/eolian_generation.c index ac8a16a2e9..9512e338c3 100644 --- a/src/tests/eolian/eolian_generation.c +++ b/src/tests/eolian/eolian_generation.c @@ -5,14 +5,15 @@ #include #include -#include -#include "Eolian.h" -#include "eolian_suite.h" - #ifdef HAVE_EVIL #include "Evil.h" #endif +#include +#include + +#include "eolian_suite.h" + static Eina_Bool _files_compare (const char *ref_filename, const char *tmp_filename) { @@ -190,4 +191,3 @@ void eolian_generation_test(TCase *tc) tcase_add_test(tc, eolian_import); tcase_add_test(tc, eolian_docs); } - diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c index 5f66e2d678..feec478cd9 100644 --- a/src/tests/eolian/eolian_parsing.c +++ b/src/tests/eolian/eolian_parsing.c @@ -5,8 +5,9 @@ #include #include -#include -#include "Eolian.h" +#include +#include + #include "eolian_suite.h" START_TEST(eolian_namespaces) @@ -1323,4 +1324,3 @@ void eolian_parsing_test(TCase *tc) tcase_add_test(tc, eolian_decl); tcase_add_test(tc, eolian_docs); } - diff --git a/src/tests/eolian/eolian_suite.c b/src/tests/eolian/eolian_suite.c index ee735495e0..c640a57e7f 100644 --- a/src/tests/eolian/eolian_suite.c +++ b/src/tests/eolian/eolian_suite.c @@ -2,108 +2,33 @@ # include #endif -#include -#include +#ifdef _WIN32 +# include /* setenv */ +#endif -#include #include "eolian_suite.h" +#include "../efl_check.h" -typedef struct _Eolian_Test_Case Eolian_Test_Case; - -struct _Eolian_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eolian_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Eolian Parsing", eolian_parsing_test}, { "Eolian Generation", eolian_generation_test}, { NULL, NULL } }; -static void -_list_tests(void) -{ - const Eolian_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -eolian_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eolian"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; + setenv("CK_FORK", "no", 0); - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = eolian_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eolian", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eolian_cxx/a.c b/src/tests/eolian_cxx/a.c index 885c9ea173..067639f7de 100644 --- a/src/tests/eolian_cxx/a.c +++ b/src/tests/eolian_cxx/a.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -21,4 +20,3 @@ static Eo *_a_eo_base_constructor(Eo *obj EINA_UNUSED, A_Data *pd EINA_UNUSED) } #include "a.eo.c" - diff --git a/src/tests/eolian_cxx/b.c b/src/tests/eolian_cxx/b.c index f32617b38d..4efe49491b 100644 --- a/src/tests/eolian_cxx/b.c +++ b/src/tests/eolian_cxx/b.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -22,4 +21,3 @@ static Eo *_b_eo_base_constructor(Eo *obj EINA_UNUSED, B_Data *pd EINA_UNUSED) } #include "b.eo.c" - diff --git a/src/tests/eolian_cxx/c.c b/src/tests/eolian_cxx/c.c index f113c8f813..c95e2a364c 100644 --- a/src/tests/eolian_cxx/c.c +++ b/src/tests/eolian_cxx/c.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -22,4 +21,3 @@ static Eo *_c_eo_base_constructor(Eo *obj EINA_UNUSED, C_Data *pd EINA_UNUSED) } #include "c.eo.c" - diff --git a/src/tests/eolian_cxx/callback.c b/src/tests/eolian_cxx/callback.c index 62612546d7..4ad49fff52 100644 --- a/src/tests/eolian_cxx/callback.c +++ b/src/tests/eolian_cxx/callback.c @@ -1,13 +1,12 @@ - #ifdef HAVE_CONFIG_H # include #endif +#include + #include #include -#include - #include "callback.eo.h" struct _Callback_Data @@ -57,4 +56,3 @@ static void _callback_test_global_callbacks(Eo *obj EINA_UNUSED, void *pd EINA_U } #include "callback.eo.c" - diff --git a/src/tests/eolian_cxx/d.c b/src/tests/eolian_cxx/d.c index 8ef24d6916..e68a29ecc2 100644 --- a/src/tests/eolian_cxx/d.c +++ b/src/tests/eolian_cxx/d.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -24,4 +23,3 @@ static Eo *_d_eo_base_constructor(Eo *obj EINA_UNUSED, D_Data *pd EINA_UNUSED) } #include "d.eo.c" - diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.cc b/src/tests/eolian_cxx/eolian_cxx_suite.cc index 7f8043914b..f925b09edf 100644 --- a/src/tests/eolian_cxx/eolian_cxx_suite.cc +++ b/src/tests/eolian_cxx/eolian_cxx_suite.cc @@ -1,24 +1,11 @@ -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include +#endif -void eolian_cxx_test_parse(TCase* tc); -void eolian_cxx_test_wrapper(TCase* tc); -void eolian_cxx_test_generate(TCase* tc); -void eolian_cxx_test_callback(TCase* tc); -void eolian_cxx_test_address_of(TCase* tc); -void eolian_cxx_test_inheritance(TCase* tc); -void eolian_cxx_test_binding(TCase* tc); +#include "eolian_cxx_suite.h" +#include "../efl_check.h" -typedef struct _Eolian_Cxx_Test_Case Eolian_Cxx_Test_Case; -struct _Eolian_Cxx_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Eolian_Cxx_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Eolian-Cxx Parsing", eolian_cxx_test_parse }, { "Eolian-Cxx Wrapper", eolian_cxx_test_wrapper }, { "Eolian-Cxx Generation", eolian_cxx_test_generate }, @@ -29,87 +16,18 @@ static const Eolian_Cxx_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) +int +main(int argc, char* argv[]) { - const Eolian_Cxx_Test_Case *itr; + int failed_count; - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -Suite * -eolian_cxx_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Eolian C++"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - -int main(int argc, char* argv[]) -{ - Suite *s; - SRunner *sr; - int i, failed_count; - - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv(const_cast("EFL_RUN_IN_TREE=1")); - s = eolian_cxx_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Eolian C++", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.h b/src/tests/eolian_cxx/eolian_cxx_suite.h new file mode 100644 index 0000000000..73e6dc2169 --- /dev/null +++ b/src/tests/eolian_cxx/eolian_cxx_suite.h @@ -0,0 +1,14 @@ +#ifndef _EOLIAN_CXX_SUITE_H +#define _EOLIAN_CXX_SUITE_H + +#include + +void eolian_cxx_test_parse(TCase* tc); +void eolian_cxx_test_wrapper(TCase* tc); +void eolian_cxx_test_generate(TCase* tc); +void eolian_cxx_test_callback(TCase* tc); +void eolian_cxx_test_address_of(TCase* tc); +void eolian_cxx_test_inheritance(TCase* tc); +void eolian_cxx_test_binding(TCase* tc); + +#endif /* _EOLIAN_CXX_SUITE_H */ diff --git a/src/tests/eolian_cxx/eolian_cxx_test_address_of.cc b/src/tests/eolian_cxx/eolian_cxx_test_address_of.cc index c76fa5f025..9a1283be6c 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_address_of.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_address_of.cc @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -8,7 +7,7 @@ #include #include -#include +#include "eolian_cxx_suite.h" START_TEST(eolian_cxx_test_addess_of_conversions) { diff --git a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc index a6d8ebb310..4a189bb058 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc @@ -1,13 +1,10 @@ - -// test EFL++ generated bindings - #ifdef HAVE_CONFIG_H # include #endif #include -#include +#include "eolian_cxx_suite.h" START_TEST(eolian_cxx_test_binding_constructor_only_required) { diff --git a/src/tests/eolian_cxx/eolian_cxx_test_callback.cc b/src/tests/eolian_cxx/eolian_cxx_test_callback.cc index 42caa4a34c..6ffaf50590 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_callback.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_callback.cc @@ -1,19 +1,18 @@ - #ifdef HAVE_CONFIG_H # include #endif +#include +#include +#include +#include + #include #include #include -#include - -#include -#include -#include -#include +#include "eolian_cxx_suite.h" void foo(void*) {} @@ -106,7 +105,7 @@ START_TEST(eolian_cxx_test_callback_event_del) )); ++called4; })); - + fail_if(called1 != 2); fail_if(called2 != 2); fail_if(called3 != 2); diff --git a/src/tests/eolian_cxx/eolian_cxx_test_generate.cc b/src/tests/eolian_cxx/eolian_cxx_test_generate.cc index d9770ad710..acb32dd8e2 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_generate.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_generate.cc @@ -1,12 +1,12 @@ - #ifdef HAVE_CONFIG_H # include #endif +#include + #include -#include -#include +#include "eolian_cxx_suite.h" START_TEST(eolian_cxx_test_generate_complex_types) { diff --git a/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc index 1337135528..9804a80359 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif @@ -8,7 +7,7 @@ #include -#include +#include "eolian_cxx_suite.h" struct bar : efl::eo::inherit diff --git a/src/tests/eolian_cxx/eolian_cxx_test_parse.cc b/src/tests/eolian_cxx/eolian_cxx_test_parse.cc index 3fd283fc22..48d414663e 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_parse.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_parse.cc @@ -1,9 +1,13 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include #include -#include -#include -#include +#include "eolian_cxx_suite.h" START_TEST(eolian_cxx_test_parse_complex_types) { diff --git a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc index a2ab990bfd..bf794a7eb7 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc @@ -1,6 +1,3 @@ - -// Test Eolian-Cxx wrappers - #ifdef HAVE_CONFIG_H # include #endif @@ -10,7 +7,7 @@ #include -#include +#include "eolian_cxx_suite.h" START_TEST(eolian_cxx_test_wrapper_size) { diff --git a/src/tests/eolian_cxx/generic.c b/src/tests/eolian_cxx/generic.c index 97f6b98187..81edb672d0 100644 --- a/src/tests/eolian_cxx/generic.c +++ b/src/tests/eolian_cxx/generic.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include #endif diff --git a/src/tests/eolian_cxx/simple.c b/src/tests/eolian_cxx/simple.c index 1009b37831..79d4d80c10 100644 --- a/src/tests/eolian_cxx/simple.c +++ b/src/tests/eolian_cxx/simple.c @@ -1,13 +1,12 @@ - #ifdef HAVE_CONFIG_H # include #endif +#include + #include #include -#include - #include "simple.eo.h" #define MY_CLASS SIMPLE_CLASS @@ -35,4 +34,3 @@ static Eina_Bool _simple_name_get(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, con } #include "simple.eo.c" - diff --git a/src/tests/evas/evas_suite.c b/src/tests/evas/evas_suite.c index 3654ab60dc..3021f2c582 100644 --- a/src/tests/evas/evas_suite.c +++ b/src/tests/evas/evas_suite.c @@ -2,22 +2,12 @@ # include #endif -#include -#include - #include #include "evas_suite.h" +#include "../efl_check.h" -typedef struct _Evas_Test_Case Evas_Test_Case; - -struct _Evas_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Evas_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Evas", evas_test_init }, { "Object", evas_test_object }, { "Object Textblock", evas_test_textblock }, @@ -34,88 +24,22 @@ static const Evas_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Evas_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -evas_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Evas"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); evas_init(); - s = evas_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Evas", etc); evas_shutdown(); + return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/evas/evas_test_callbacks.c b/src/tests/evas/evas_test_callbacks.c index f4244358ca..3f83847202 100644 --- a/src/tests/evas/evas_test_callbacks.c +++ b/src/tests/evas/evas_test_callbacks.c @@ -1,12 +1,12 @@ - #ifdef HAVE_CONFIG_H # include "config.h" #endif #include +#include + #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" #define START_CALLBACK_TEST() \ diff --git a/src/tests/evas/evas_test_evasgl.c b/src/tests/evas/evas_test_evasgl.c index 3263cfa74f..181ed2b031 100644 --- a/src/tests/evas/evas_test_evasgl.c +++ b/src/tests/evas/evas_test_evasgl.c @@ -17,10 +17,12 @@ #endif #define EFL_GFX_FILTER_BETA + +#include +#include +#include + #include "evas_suite.h" -#include "Evas.h" -#include "Evas_GL.h" -#include "Ecore_Evas.h" static int _detect_osmesa(void) diff --git a/src/tests/evas/evas_test_filters.c b/src/tests/evas/evas_test_filters.c index 188bb0bfc4..47e9b4cf9a 100644 --- a/src/tests/evas/evas_test_filters.c +++ b/src/tests/evas/evas_test_filters.c @@ -10,10 +10,12 @@ #include #define EFL_GFX_FILTER_BETA -#include "evas_suite.h" -#include "Evas.h" -#include "Ecore_Evas.h" + +#include #include "../../lib/evas/include/evas_filter.h" +#include + +#include "evas_suite.h" #define TEST_FONT_NAME "DejaVuSans,UnDotum" #define TEST_FONT_SOURCE TESTS_SRC_DIR "/TestFont.eet" diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c index cfb0f9402c..e56db7ef39 100644 --- a/src/tests/evas/evas_test_image.c +++ b/src/tests/evas/evas_test_image.c @@ -2,13 +2,14 @@ # include "config.h" #endif +#include #include #include #include -#include + +#include #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" #define TESTS_IMG_DIR TESTS_SRC_DIR"/images" diff --git a/src/tests/evas/evas_test_init.c b/src/tests/evas/evas_test_init.c index 7637d9cb2a..827798f3ef 100644 --- a/src/tests/evas/evas_test_init.c +++ b/src/tests/evas/evas_test_init.c @@ -1,12 +1,12 @@ - #ifdef HAVE_CONFIG_H # include "config.h" #endif #include +#include + #include "evas_suite.h" -#include "Evas.h" START_TEST(evas_simple) { diff --git a/src/tests/evas/evas_test_mask.c b/src/tests/evas/evas_test_mask.c index 1f055122a3..d3518d0558 100644 --- a/src/tests/evas/evas_test_mask.c +++ b/src/tests/evas/evas_test_mask.c @@ -4,9 +4,10 @@ #ifdef BUILD_ENGINE_BUFFER +#include +#include + #include "evas_suite.h" -#include "Evas.h" -#include "Ecore_Evas.h" #include "evas_tests_helpers.h" #define TEST_FONT_NAME "DejaVuSans,UnDotum" diff --git a/src/tests/evas/evas_test_matrix.c b/src/tests/evas/evas_test_matrix.c index d365d24e75..b6df8f28de 100644 --- a/src/tests/evas/evas_test_matrix.c +++ b/src/tests/evas/evas_test_matrix.c @@ -2,15 +2,16 @@ # include "config.h" #endif +#include #include #include #include -#include +#include #include "../../lib/evas/include/evas_common_private.h" #include "../../lib/evas/include/evas_private.h" + #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" START_TEST(evas_matrix) diff --git a/src/tests/evas/evas_test_mesh.c b/src/tests/evas/evas_test_mesh.c index fe82f576d6..d70ab3225a 100644 --- a/src/tests/evas/evas_test_mesh.c +++ b/src/tests/evas/evas_test_mesh.c @@ -2,13 +2,14 @@ # include "config.h" #endif -#include #include +#include +#include #include "../../lib/evas/include/evas_common_private.h" #include "../../lib/evas/include/evas_private.h" + #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" #define TESTS_MESH_DIR TESTS_SRC_DIR"/meshes" diff --git a/src/tests/evas/evas_test_object.c b/src/tests/evas/evas_test_object.c index 48770b72b1..6b722a5d88 100644 --- a/src/tests/evas/evas_test_object.c +++ b/src/tests/evas/evas_test_object.c @@ -4,8 +4,9 @@ #include +#include + #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" START_TEST(evas_object_various) diff --git a/src/tests/evas/evas_test_object_smart.c b/src/tests/evas/evas_test_object_smart.c index 6f31197220..23a43b7ac3 100644 --- a/src/tests/evas/evas_test_object_smart.c +++ b/src/tests/evas/evas_test_object_smart.c @@ -8,10 +8,11 @@ #endif #include + #include +#include #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" #define TEST_FONT_SOURCE TESTS_SRC_DIR "/TestFont.eet" diff --git a/src/tests/evas/evas_test_render_engines.c b/src/tests/evas/evas_test_render_engines.c index 0f98bccc78..3f3ab09f56 100644 --- a/src/tests/evas/evas_test_render_engines.c +++ b/src/tests/evas/evas_test_render_engines.c @@ -4,8 +4,9 @@ #include +#include + #include "evas_suite.h" -#include "Evas.h" static Eina_Bool _find_list(const Eina_List *lst, const char *item) diff --git a/src/tests/evas/evas_test_text.c b/src/tests/evas/evas_test_text.c index fe5644aed8..746fbee39b 100644 --- a/src/tests/evas/evas_test_text.c +++ b/src/tests/evas/evas_test_text.c @@ -5,8 +5,9 @@ #include +#include + #include "evas_suite.h" -#include "Evas.h" #include "evas_tests_helpers.h" #define TEST_FONT_NAME "DejaVuSans,UnDotum" diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index 895021bf45..379bc2eafd 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -8,16 +8,14 @@ #endif #include +#include #include +#include #include "evas_suite.h" -#include "Evas.h" - #include "evas_tests_helpers.h" -#include - /* Functions defined in evas_object_textblock.c */ EAPI Eina_Bool _evas_textblock_check_item_node_link(Evas_Object *obj); diff --git a/src/tests/evil/evil_suite.c b/src/tests/evil/evil_suite.c index 2699bee32a..bc8bd79025 100644 --- a/src/tests/evil/evil_suite.c +++ b/src/tests/evil/evil_suite.c @@ -23,18 +23,10 @@ #include #include -#include - #include "evil_suite.h" +#include "../efl_check.h" -typedef struct _Evil_Test_Case Evil_Test_Case; -struct _Evil_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Evil_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { /* { "Dirent", evil_test_dirent }, */ { "Dlfcn", evil_test_dlfcn }, /* { "Fcntl", evil_test_fcntl }, */ @@ -54,85 +46,18 @@ static const Evil_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Evil_Test_Case *itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} - -static unsigned char -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - - return 0; -} - -Suite * -evil_build_suite(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Evil"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) - continue; - - tc = tcase_create(etc[i].test_case); -#ifndef _WIN32 - tcase_set_timeout(tc, 0); -#endif - - etc[i].build(tc); - suite_add_tcase(s, tc); - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = evil_build_suite(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Evil", etc); return (failed_count == 0) ? 0 : 255; }