commit 997b338270221b276483e3afa4c6bfb9c2f59fff Author: Andy Williams Date: Fri Oct 17 21:36:03 2014 +0100 Base addition of elm_code area within the edi codebase, including an empty test to verify it's working diff --git a/legacy/elm_code/Makefile.am b/legacy/elm_code/Makefile.am new file mode 100644 index 0000000000..d01d7e3fde --- /dev/null +++ b/legacy/elm_code/Makefile.am @@ -0,0 +1,4 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = lib tests + diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h new file mode 100644 index 0000000000..13f6369ab9 --- /dev/null +++ b/legacy/elm_code/lib/Elm_Code.h @@ -0,0 +1,95 @@ +#ifndef ELM_CODE_H_ +# define ELM_CODE_H_ + +#include + +#ifdef EAPI +# undef EAPI +#endif + +#ifdef _WIN32 +# ifdef EFL_ELM_CODE_BUILD +# ifdef DLL_EXPORT +# define EAPI __declspec(dllexport) +# else +# define EAPI +# endif /* ! DLL_EXPORT */ +# else +# define EAPI __declspec(dllimport) +# endif /* ! EFL_ELM_CODE_BUILD */ +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif /* ! _WIN32 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with files using Elm Code. + */ + +/** + * @brief Init / shutdown functions. + * @defgroup Init Init / Shutdown + * + * @{ + * + * Functions of obligatory usage, handling proper initialization + * and shutdown routines. + * + * Before the usage of any other function, Elm Code should be properly + * initialized with @ref elm_code_init() and the last call to Elm Code's + * functions should be @ref elm_code_shutdown(), so everything will + * be correctly freed. + * + * Elm Code logs everything with Eina Log, using the "elm_code" log domain. + * + */ + +/** + * Initialize Elm Code. + * + * Initializes Elm Code, its dependencies and modules. Should be the first + * function of Elm Code to be called. + * + * @return The init counter value. + * + * @see elm_code_shutdown(). + * + * @ingroup Init + */ +EAPI int elm_code_init(void); + +/** + * Shutdown Elm Code + * + * Shutdown Elm Code. If init count reaches 0, all the internal structures will + * be freed. Any Elm Code library call after this point will leads to an error. + * + * @return Elm Code's init counter value. + * + * @see elm_code_init(). + * + * @ingroup Init + */ +EAPI int elm_code_shutdown(void); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_H_ */ diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am new file mode 100644 index 0000000000..468b75abf4 --- /dev/null +++ b/legacy/elm_code/lib/Makefile.am @@ -0,0 +1,19 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I$(top_srcdir)/elm_code/lib \ +-I$(top_builddir)/elm_code/lib \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +@EFL_CFLAGS@ \ +-DEFL_EFL_BUILD + +lib_LTLIBRARIES = libelm_code.la + +includes_HEADERS = Elm_Code.h +includesdir = $(includedir)/edi-@VMAJ@ + +libelm_code_la_SOURCES = \ +elm_code.c +libelm_code_la_LIBADD = @EFL_LIBS@ -lm +libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c new file mode 100644 index 0000000000..0532ce6eac --- /dev/null +++ b/legacy/elm_code/lib/elm_code.c @@ -0,0 +1,58 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +static int _elm_code_init = 0; +int _elm_code_lib_log_dom = -1; + +EAPI int +elm_code_init(void) +{ + _elm_code_init++; + if (_elm_code_init > 1) return _elm_code_init; + + eina_init(); + + _elm_code_lib_log_dom = eina_log_domain_register("elm_code", EINA_COLOR_CYAN); + if (_elm_code_lib_log_dom < 0) + { + EINA_LOG_ERR("Elm Code can not create its log domain."); + goto shutdown_eina; + } + + // Put here your initialization logic of your library + + eina_log_timing(_elm_code_lib_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); + + return _elm_code_init; + + shutdown_eina: + eina_shutdown(); + _elm_code_init--; + + return _elm_code_init; +} + +EAPI int +elm_code_shutdown(void) +{ + _elm_code_init--; + if (_elm_code_init != 0) return _elm_code_init; + + eina_log_timing(_elm_code_lib_log_dom, + EINA_LOG_STATE_START, + EINA_LOG_STATE_SHUTDOWN); + + // Put here your shutdown logic + + eina_log_domain_unregister(_elm_code_lib_log_dom); + _elm_code_lib_log_dom = -1; + + eina_shutdown(); + + return _elm_code_init; +} diff --git a/legacy/elm_code/lib/elm_code_private.h b/legacy/elm_code/lib/elm_code_private.h new file mode 100644 index 0000000000..d1ff3284d4 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_private.h @@ -0,0 +1,27 @@ +#ifndef ELM_CODE_PRIVATE_H +# define ELM_CODE_PRIVATE_H + +extern int _elm_code_lib_log_dom; + +#ifdef ERR +# undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef INF +# undef INF +#endif +#define INF(...) EINA_LOG_DOM_INFO(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef WRN +# undef WRN +#endif +#define WRN(...) EINA_LOG_DOM_WARN(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef CRIT +# undef CRIT +#endif +#define CRIT(...) EINA_LOG_DOM_CRIT(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef DBG +# undef DBG +#endif +#define DBG(...) EINA_LOG_DOM_DBG(_elm_code_lib_log_dom, __VA_ARGS__) + +#endif diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am new file mode 100644 index 0000000000..565279993d --- /dev/null +++ b/legacy/elm_code/tests/Makefile.am @@ -0,0 +1,21 @@ + +if EFL_HAVE_TESTS + +check_PROGRAMS = elm_code_suite + +elm_code_suite_SOURCES = \ +elm_code_test_load.c \ +elm_code_suite.c + +elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ +-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ +-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ +@EFL_CFLAGS@ \ +@CHECK_CFLAGS@ + +elm_code_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la + +endif + +EXTRA_DIST = elm_code_suite.h diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c new file mode 100644 index 0000000000..7b74ec2a73 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -0,0 +1,122 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "Elm_Code.h" +#include "elm_code_suite.h" + +#define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." + +static const struct { + const char *name; + void (*build)(TCase *tc); +} tests[] = { + { "load", elm_code_test_load }, +}; + +START_TEST(elm_code_initialization) +{ + fail_if(elm_code_init() != 1); + +// TODO add other init checks here + + fail_if(elm_code_shutdown() != 0); +} +END_TEST + +void +edi_test_basic(TCase *tc) +{ + tcase_add_test(tc, elm_code_initialization); +} + +static const Ecore_Getopt optdesc = { + "elm_code", + "%prog [options]", + PACKAGE_VERSION, + COPYRIGHT, + "BSD with advertisement clause", + "Elm Code", + 0, + { + ECORE_GETOPT_STORE_TRUE('l', "list", "list available tests"), + ECORE_GETOPT_STORE_STR('t', "test", "test to run"), + ECORE_GETOPT_LICENSE('L', "license"), + ECORE_GETOPT_COPYRIGHT('C', "copyright"), + ECORE_GETOPT_VERSION('V', "version"), + ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_SENTINEL + } +}; + +int +main(int argc EINA_UNUSED, char **argv EINA_UNUSED) +{ + Suite *s; + SRunner *sr; + TCase *tc = NULL; + char *test = NULL; + unsigned int i; + int failed_count = -1; + int args; + Eina_Bool quit_option = EINA_FALSE; + Eina_Bool list_option = EINA_FALSE; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_BOOL(list_option), + ECORE_GETOPT_VALUE_STR(test), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_NONE + }; + + eina_init(); + + args = ecore_getopt_parse(&optdesc, values, argc, argv); + if (args < 0) + { + EINA_LOG_CRIT("Could not parse arguments."); + goto end; + } + else if (quit_option) + { + goto end; + } + else if (list_option) + { + fprintf(stdout, "Available tests :\n"); + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + fprintf(stdout, "\t%s\n", tests[i].name); + goto end; + } + + s = suite_create("Elm_Code"); + + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + { + if (test && strcmp(tests[i].name, test)) + continue ; + + tc = tcase_create(tests[i].name); + tcase_set_timeout(tc, 0); + + tests[i].build(tc); + suite_add_tcase(s, tc); + } + + sr = srunner_create(s); + srunner_set_xml(sr, PACKAGE_BUILD_DIR "/check-results.xml"); + + srunner_run_all(sr, CK_ENV); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + end: + eina_shutdown(); + + return (failed_count == 0) ? 0 : 255; +} diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h new file mode 100644 index 0000000000..2cdf523169 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -0,0 +1,10 @@ +#ifndef _ELM_CODE_SUITE_H +#define _ELM_CODE_SUITE_H + +#include + +#include + +void elm_code_test_load(TCase *tc); + +#endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c new file mode 100644 index 0000000000..807e06ec52 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -0,0 +1,17 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_load) +{ + ck_assert(1); +} +END_TEST + +void elm_code_test_load(TCase *tc) +{ + tcase_add_test(tc, elm_code_load); +} +