jackdanielz pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=04cc8138137e7ba936288ac6b084b569f72514b8

commit 04cc8138137e7ba936288ac6b084b569f72514b8
Author: Daniel Zaoui <daniel.za...@samsung.com>
Date:   Fri May 2 19:20:10 2014 +0300

    Eolian: add test for generator.
    
    The test checks the dev code generator.
---
 src/Makefile_Eolian.am                             |   8 +-
 src/bin/eolian/main.c                              |  36 +++----
 .../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, 314 insertions(+), 19 deletions(-)

diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am
index e311111..a945ea1 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 576d18c..8ceb3cf 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);
+        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;
+          }
 
-   if (!content)
-     {
-        ERR("Couldnt read file %s", filename);
-        goto end;
+        buffer = eina_strbuf_manage_new(content);
      }
-
-   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 0000000..b4d6737
--- /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 *<int> 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 0000000..e4ddfda
--- /dev/null
+++ b/src/tests/eolian/data/object_impl_add_ref.c
@@ -0,0 +1,87 @@
+#define EFL_BETA_API_SUPPORT
+#include <Eo.h>
+#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 0000000..aa2b788
--- /dev/null
+++ b/src/tests/eolian/data/object_impl_ref.c
@@ -0,0 +1,75 @@
+#define EFL_BETA_API_SUPPORT
+#include <Eo.h>
+#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 0000000..0b4c596
--- /dev/null
+++ b/src/tests/eolian/eolian_generation.c
@@ -0,0 +1,111 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include<Eina.h>
+#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 e976940..36cff51 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 fef23e1..0c1a99b 100644
--- a/src/tests/eolian/eolian_suite.h
+++ b/src/tests/eolian/eolian_suite.h
@@ -4,6 +4,7 @@
 #include <check.h>
 
 void eolian_parsing_test(TCase *tc);
+void eolian_generation_test(TCase *tc);
 
 #endif /* _EOLIAN_SUITE_H */
 

-- 


Reply via email to