Eolian: add test for generator.
authorDaniel Zaoui <daniel.zaoui@samsung.com>
Fri, 2 May 2014 16:20:10 +0000 (19:20 +0300)
committerDaniel Zaoui <daniel.zaoui@samsung.com>
Mon, 26 May 2014 10:56:06 +0000 (13:56 +0300)
The test checks the dev code generator.

src/Makefile_Eolian.am
src/bin/eolian/main.c
src/tests/eolian/data/object.eo [deleted file]
src/tests/eolian/data/object_impl.eo [new file with mode: 0644]
src/tests/eolian/data/object_impl_add.eo [new file with mode: 0644]
src/tests/eolian/data/object_impl_add_ref.c [new file with mode: 0644]
src/tests/eolian/data/object_impl_ref.c [new file with mode: 0644]
src/tests/eolian/eolian_generation.c [new file with mode: 0644]
src/tests/eolian/eolian_suite.c
src/tests/eolian/eolian_suite.h

index e31111176f93a055ecbd6af25eda9b5a60477986..a945ea1ecde6c11eee7f8e634575665749066c9b 100644 (file)
@@ -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
 
index 576d18cf5f830fce8ea3ab206fd85a094b2932d5..8ceb3cf16f23d4cf0a4253e723b8cc4f4b67d525 100644 (file)
@@ -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.eo
deleted file mode 100644 (file)
index d250c85..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-class Object (Base) {
-   constructors {
-      constructor_1 {
-         params {
-            @in int a;
-            @in char b;
-         }
-      }
-      constructor_2 {
-      }
-   }
-   properties {
-      a {
-         set {
-            return Eina_Bool(EINA_FALSE);
-            value: const;
-         }
-         get {
-         }
-         keys {
-            const char *part;
-         }
-         values {
-            @own Eina_List *<int> value;
-         }
-      }
-      b {
-         set {
-         }
-         get {
-            /* set as virtual pure - no implementation expected */
-         }
-         values {
-            @own Eina_List *<int> value;
-         }
-      }
-   }
-   methods {
-      foo1 {
-         /*@ comment foo */
-         params {
-            @in int a; /*@ a */
-            @inout char *b;
-            @out double c;
-         }
-         return char *(NULL); /*@ comment for method return */
-      }
-      foo2 {
-         /*@ comment foo */
-         params {
-            @in int a;
-            @in const char *b;
-         }
-         const;
-      }
-      pure_foo3 {
-         /* set as virtual pure - no implementation expected */
-      }
-   }
-   implements {
-      class::constructor;
-      class::destructor;
-      Base::constructor;
-      Base::destructor;
-      virtual::pure_foo3;
-      virtual::b::get;
-   }
-}
diff --git a/src/tests/eolian/data/object_impl.eo b/src/tests/eolian/data/object_impl.eo
new file mode 100644 (file)
index 0000000..d250c85
--- /dev/null
@@ -0,0 +1,68 @@
+class Object (Base) {
+   constructors {
+      constructor_1 {
+         params {
+            @in int a;
+            @in char b;
+         }
+      }
+      constructor_2 {
+      }
+   }
+   properties {
+      a {
+         set {
+            return Eina_Bool(EINA_FALSE);
+            value: const;
+         }
+         get {
+         }
+         keys {
+            const char *part;
+         }
+         values {
+            @own Eina_List *<int> value;
+         }
+      }
+      b {
+         set {
+         }
+         get {
+            /* set as virtual pure - no implementation expected */
+         }
+         values {
+            @own Eina_List *<int> value;
+         }
+      }
+   }
+   methods {
+      foo1 {
+         /*@ comment foo */
+         params {
+            @in int a; /*@ a */
+            @inout char *b;
+            @out double c;
+         }
+         return char *(NULL); /*@ comment for method return */
+      }
+      foo2 {
+         /*@ comment foo */
+         params {
+            @in int a;
+            @in const char *b;
+         }
+         const;
+      }
+      pure_foo3 {
+         /* set as virtual pure - no implementation expected */
+      }
+   }
+   implements {
+      class::constructor;
+      class::destructor;
+      Base::constructor;
+      Base::destructor;
+      virtual::pure_foo3;
+      virtual::b::get;
+   }
+}
diff --git a/src/tests/eolian/data/object_impl_add.eo b/src/tests/eolian/data/object_impl_add.eo
new file mode 100644 (file)
index 0000000..b4d6737
--- /dev/null
@@ -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 (file)
index 0000000..e4ddfda
--- /dev/null
@@ -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 (file)
index 0000000..aa2b788
--- /dev/null
@@ -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 (file)
index 0000000..0b4c596
--- /dev/null
@@ -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);
+}
+
index e97694086f60f1bd2f76df38e614f580e3bf0a65..36cff513938e68a61f48333aef448ccbaff2399f 100644 (file)
@@ -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 }
 };
 
index fef23e1d6435ff8470db7b2d400f07b488194173..0c1a99b16136e53eb6b94c7ccf9ee2d73b13f892 100644 (file)
@@ -4,6 +4,7 @@
 #include <check.h>
 
 void eolian_parsing_test(TCase *tc);
+void eolian_generation_test(TCase *tc);
 
 #endif /* _EOLIAN_SUITE_H */