Eolian: add test for generator.

The test checks the dev code generator.
This commit is contained in:
Daniel Zaoui 2014-05-02 19:20:10 +03:00
parent a541aecf76
commit 04cc813813
9 changed files with 315 additions and 20 deletions

View 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

View 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);
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))
{

View File

@ -0,0 +1,14 @@
class Object (Base) {
properties {
c {
set {
}
get {
/* set as virtual pure - no implementation expected */
}
values {
@own Eina_List *<int> value;
}
}
}
}

View File

@ -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)
{
}

View File

@ -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)
{
}

View File

@ -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);
}

View 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 }
};

View File

@ -4,6 +4,7 @@
#include <check.h>
void eolian_parsing_test(TCase *tc);
void eolian_generation_test(TCase *tc);
#endif /* _EOLIAN_SUITE_H */