From 04cc8138137e7ba936288ac6b084b569f72514b8 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Fri, 2 May 2014 19:20:10 +0300 Subject: [PATCH] Eolian: add test for generator. The test checks the dev code generator. --- src/Makefile_Eolian.am | 8 +- src/bin/eolian/main.c | 38 +++--- .../eolian/data/{object.eo => object_impl.eo} | 0 src/tests/eolian/data/object_impl_add.eo | 14 +++ src/tests/eolian/data/object_impl_add_ref.c | 87 ++++++++++++++ src/tests/eolian/data/object_impl_ref.c | 75 ++++++++++++ src/tests/eolian/eolian_generation.c | 111 ++++++++++++++++++ src/tests/eolian/eolian_suite.c | 1 + src/tests/eolian/eolian_suite.h | 1 + 9 files changed, 315 insertions(+), 20 deletions(-) rename src/tests/eolian/data/{object.eo => object_impl.eo} (100%) create mode 100644 src/tests/eolian/data/object_impl_add.eo create mode 100644 src/tests/eolian/data/object_impl_add_ref.c create mode 100644 src/tests/eolian/data/object_impl_ref.c create mode 100644 src/tests/eolian/eolian_generation.c diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am index e31111176f..a945ea1ecd 100644 --- a/src/Makefile_Eolian.am +++ b/src/Makefile_Eolian.am @@ -66,12 +66,14 @@ tests/eolian/eolian_suite tests_eolian_eolian_suite_SOURCES = \ tests/eolian/eolian_parsing.c \ +tests/eolian/eolian_generation.c \ tests/eolian/eolian_suite.c \ tests/eolian/eolian_suite.h tests_eolian_eolian_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ -DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eolian\" \ -DPACKAGE_DATA_DIR=\"$(top_srcdir)/src/tests/eolian\" \ +-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)\" \ @CHECK_CFLAGS@ \ @EOLIAN_CFLAGS@ TESTS += tests/eolian/eolian_suite @@ -87,5 +89,9 @@ tests/eolian/data/class_simple.eo \ tests/eolian/data/scope.eo \ tests/eolian/data/ctor_dtor.eo \ tests/eolian/data/complex_type.eo \ -tests/eolian/data/typedef.eo +tests/eolian/data/typedef.eo \ +tests/eolian/data/object_impl.eo \ +tests/eolian/data/object_impl_ref.c \ +tests/eolian/data/object_impl_add.eo \ +tests/eolian/data/object_impl_add_ref.c diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c index 576d18cf5f..8ceb3cf16f 100644 --- a/src/bin/eolian/main.c +++ b/src/bin/eolian/main.c @@ -124,29 +124,29 @@ _generate_impl_c_file(char *filename, const char *classname) { Eina_Bool ret = EINA_FALSE; long file_size = 0; + Eina_Strbuf *buffer = NULL; FILE* fd = fopen(filename, "rb"); - if (!fd) + if (fd) { - ERR("Couldnt open file %s for reading", filename); - goto end; + fseek(fd, 0, SEEK_END); + file_size = ftell(fd); + fseek(fd, 0, SEEK_SET); + char *content = malloc(file_size + 1); + fread(content, file_size, 1, fd); + content[file_size] = '\0'; + fclose(fd); + + if (!content) + { + ERR("Couldnt read file %s", filename); + goto end; + } + + buffer = eina_strbuf_manage_new(content); } - - fseek(fd, 0, SEEK_END); - file_size = ftell(fd); - fseek(fd, 0, SEEK_SET); - char *content = malloc(file_size + 1); - fread(content, file_size, 1, fd); - content[file_size] = '\0'; - fclose(fd); - - if (!content) - { - ERR("Couldnt read file %s", filename); - goto end; - } - - Eina_Strbuf *buffer = eina_strbuf_manage_new(content); + else + buffer = eina_strbuf_new(); if (!impl_source_generate(classname, buffer)) { diff --git a/src/tests/eolian/data/object.eo b/src/tests/eolian/data/object_impl.eo similarity index 100% rename from src/tests/eolian/data/object.eo rename to src/tests/eolian/data/object_impl.eo diff --git a/src/tests/eolian/data/object_impl_add.eo b/src/tests/eolian/data/object_impl_add.eo new file mode 100644 index 0000000000..b4d6737bc1 --- /dev/null +++ b/src/tests/eolian/data/object_impl_add.eo @@ -0,0 +1,14 @@ +class Object (Base) { + properties { + c { + set { + } + get { + /* set as virtual pure - no implementation expected */ + } + values { + @own Eina_List * value; + } + } + } +} diff --git a/src/tests/eolian/data/object_impl_add_ref.c b/src/tests/eolian/data/object_impl_add_ref.c new file mode 100644 index 0000000000..e4ddfda3fd --- /dev/null +++ b/src/tests/eolian/data/object_impl_add_ref.c @@ -0,0 +1,87 @@ +#define EFL_BETA_API_SUPPORT +#include +#include "object.eo.h" + +typedef struct +{ + +} Object_Data; + +EOLIAN static Eina_Bool +_object_a_set(Eo *obj, Object_Data *pd, const char *part, const Eina_List *value) +{ + +} + +EOLIAN static Eina_List * +_object_a_get(Eo *obj, Object_Data *pd, const char *part) +{ + +} + +EOLIAN static void +_object_b_set(Eo *obj, Object_Data *pd, Eina_List *value) +{ + +} + +EOLIAN static char * +_object_foo1(Eo *obj, Object_Data *pd, int a, char *b, double *c) +{ + +} + +EOLIAN static void +_object_foo2(const Eo *obj, Object_Data *pd, int a, const char *b) +{ + +} + +EOLIAN static void +_object_constructor_1(Eo *obj, Object_Data *pd, int a, char b) +{ + +} + +EOLIAN static void +_object_constructor_2(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_base_constructor(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_base_destructor(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_class_constructor(Eo_Class *klass) +{ + +} + +EOLIAN static void +_object_class_destructor(Eo_Class *klass) +{ + +} + +EOLIAN static void +_object_c_set(Eo *obj, Object_Data *pd, Eina_List *value) +{ + +} + +EOLIAN static Eina_List * +_object_c_get(Eo *obj, Object_Data *pd) +{ + +} + diff --git a/src/tests/eolian/data/object_impl_ref.c b/src/tests/eolian/data/object_impl_ref.c new file mode 100644 index 0000000000..aa2b78834f --- /dev/null +++ b/src/tests/eolian/data/object_impl_ref.c @@ -0,0 +1,75 @@ +#define EFL_BETA_API_SUPPORT +#include +#include "object.eo.h" + +typedef struct +{ + +} Object_Data; + +EOLIAN static Eina_Bool +_object_a_set(Eo *obj, Object_Data *pd, const char *part, const Eina_List *value) +{ + +} + +EOLIAN static Eina_List * +_object_a_get(Eo *obj, Object_Data *pd, const char *part) +{ + +} + +EOLIAN static void +_object_b_set(Eo *obj, Object_Data *pd, Eina_List *value) +{ + +} + +EOLIAN static char * +_object_foo1(Eo *obj, Object_Data *pd, int a, char *b, double *c) +{ + +} + +EOLIAN static void +_object_foo2(const Eo *obj, Object_Data *pd, int a, const char *b) +{ + +} + +EOLIAN static void +_object_constructor_1(Eo *obj, Object_Data *pd, int a, char b) +{ + +} + +EOLIAN static void +_object_constructor_2(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_base_constructor(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_base_destructor(Eo *obj, Object_Data *pd) +{ + +} + +EOLIAN static void +_object_class_constructor(Eo_Class *klass) +{ + +} + +EOLIAN static void +_object_class_destructor(Eo_Class *klass) +{ + +} + diff --git a/src/tests/eolian/eolian_generation.c b/src/tests/eolian/eolian_generation.c new file mode 100644 index 0000000000..0b4c596467 --- /dev/null +++ b/src/tests/eolian/eolian_generation.c @@ -0,0 +1,111 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include +#include "Eolian.h" +#include "eolian_suite.h" + +#define MAX_PATH 1024 + +#ifdef HAVE_EVIL +#include "Evil.h" +#endif + +static Eina_Bool +_files_compare (const char *ref_filename, const char *tmp_filename) +{ + Eina_Bool result = EINA_FALSE; + + FILE *tmp_file = NULL, *ref_file = NULL; + char *tmp_content = NULL, *ref_content = NULL; + + tmp_file = fopen(tmp_filename, "rb"); + if (!tmp_file) + { + printf("Unable to open %s\n", tmp_filename); + goto end; + } + ref_file = fopen(ref_filename, "rb"); + if (!ref_file) + { + printf("Unable to open %s\n", ref_filename); + goto end; + } + + fseek(tmp_file, 0, SEEK_END); + int tmp_filesize = ftell(tmp_file); + fseek(tmp_file, 0, SEEK_SET); + tmp_content = malloc(tmp_filesize + 1); + fread(tmp_content, tmp_filesize, 1, tmp_file); + tmp_content[tmp_filesize] = '\0'; + + fseek(ref_file, 0, SEEK_END); + int ref_filesize = ftell(ref_file); + fseek(ref_file, 0, SEEK_SET); + ref_content = malloc(ref_filesize + 1); + fread(ref_content, ref_filesize, 1, ref_file); + ref_content[ref_filesize] = '\0'; + + if (tmp_filesize != ref_filesize) goto end; + + result = !memcmp(ref_content, tmp_content, ref_filesize); +end: + if (tmp_file) fclose(tmp_file); + if (ref_file) fclose(ref_file); + if (tmp_content) free(tmp_content); + if (ref_content) free(ref_content); + + return result; +} + +static int +_eolian_gen_execute(const char *eo_filename, const char *output_filename) +{ + char eolian_gen_path[PATH_MAX] = ""; + char command[PATH_MAX]; + + if (getenv("EFL_RUN_IN_TREE")) + { + snprintf(eolian_gen_path, sizeof(eolian_gen_path), + "%s/src/bin/eolian/eolian_gen", + PACKAGE_BUILD_DIR); + } + if (eolian_gen_path[0] == '\0') + return -1; + + snprintf(command, PATH_MAX, + "%s --eo --gi -I "PACKAGE_DATA_DIR"/data -o %s %s", + eolian_gen_path, output_filename, eo_filename); + return system(command); +} + +START_TEST(eolian_dev_impl_code) +{ + char output_filepath[MAX_PATH] = ""; + snprintf(output_filepath, PATH_MAX, "%s/object_impl.c", +#ifdef HAVE_EVIL + (char *)evil_tmpdir_get() +#else + "/tmp" +#endif + ); + remove(output_filepath); + fail_if(0 != _eolian_gen_execute(PACKAGE_DATA_DIR"/data/object_impl.eo", output_filepath)); + fail_if(!_files_compare(PACKAGE_DATA_DIR"/data/object_impl_ref.c", output_filepath)); + /* Check that nothing is added */ + fail_if(0 != _eolian_gen_execute(PACKAGE_DATA_DIR"/data/object_impl.eo", output_filepath)); + fail_if(!_files_compare(PACKAGE_DATA_DIR"/data/object_impl_ref.c", output_filepath)); + fail_if(0 != _eolian_gen_execute(PACKAGE_DATA_DIR"/data/object_impl_add.eo", output_filepath)); + fail_if(!_files_compare(PACKAGE_DATA_DIR"/data/object_impl_add_ref.c", output_filepath)); +} +END_TEST + +void eolian_generation_test(TCase *tc) +{ + tcase_add_test(tc, eolian_dev_impl_code); +} + diff --git a/src/tests/eolian/eolian_suite.c b/src/tests/eolian/eolian_suite.c index e97694086f..36cff51393 100644 --- a/src/tests/eolian/eolian_suite.c +++ b/src/tests/eolian/eolian_suite.c @@ -18,6 +18,7 @@ struct _Eolian_Test_Case static const Eolian_Test_Case etc[] = { { "Eolian Parsing", eolian_parsing_test}, + { "Eolian Generation", eolian_generation_test}, { NULL, NULL } }; diff --git a/src/tests/eolian/eolian_suite.h b/src/tests/eolian/eolian_suite.h index fef23e1d64..0c1a99b161 100644 --- a/src/tests/eolian/eolian_suite.h +++ b/src/tests/eolian/eolian_suite.h @@ -4,6 +4,7 @@ #include void eolian_parsing_test(TCase *tc); +void eolian_generation_test(TCase *tc); #endif /* _EOLIAN_SUITE_H */