2014-05-02 09:20:10 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-04 06:04:45 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
#include <Eolian.h>
|
|
|
|
|
|
|
|
#include "eolian_suite.h"
|
|
|
|
|
2014-05-02 09:20:10 -07:00
|
|
|
static Eina_Bool
|
2016-10-07 04:13:27 -07:00
|
|
|
_files_compare (const char *ref_filename, const char *tmp_filename, const char *ext)
|
2014-05-02 09:20:10 -07:00
|
|
|
{
|
|
|
|
Eina_Bool result = EINA_FALSE;
|
|
|
|
|
|
|
|
FILE *tmp_file = NULL, *ref_file = NULL;
|
|
|
|
char *tmp_content = NULL, *ref_content = NULL;
|
|
|
|
|
2016-10-07 04:13:27 -07:00
|
|
|
char ifnbuf[PATH_MAX];
|
|
|
|
snprintf(ifnbuf, sizeof(ifnbuf), "%s.%s", tmp_filename, ext);
|
|
|
|
|
|
|
|
tmp_file = fopen(ifnbuf, "rb");
|
2014-05-02 09:20:10 -07:00
|
|
|
if (!tmp_file)
|
|
|
|
{
|
2016-10-07 04:13:27 -07:00
|
|
|
printf("Unable to open %s\n", ifnbuf);
|
2014-05-02 09:20:10 -07:00
|
|
|
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);
|
2014-05-27 19:18:03 -07:00
|
|
|
long tmp_filesize = ftell(tmp_file);
|
|
|
|
if (tmp_filesize < 0) goto end;
|
2014-05-02 09:20:10 -07:00
|
|
|
fseek(tmp_file, 0, SEEK_SET);
|
|
|
|
tmp_content = malloc(tmp_filesize + 1);
|
2014-05-27 19:18:03 -07:00
|
|
|
if (fread(tmp_content, tmp_filesize, 1, tmp_file) != 1)
|
|
|
|
goto end;
|
2014-05-02 09:20:10 -07:00
|
|
|
tmp_content[tmp_filesize] = '\0';
|
2015-09-28 10:50:07 -07:00
|
|
|
while (tmp_content[tmp_filesize - 1] == '\n')
|
|
|
|
tmp_content[--tmp_filesize] = '\0';
|
2014-05-02 09:20:10 -07:00
|
|
|
|
|
|
|
fseek(ref_file, 0, SEEK_END);
|
2014-05-27 19:18:03 -07:00
|
|
|
long ref_filesize = ftell(ref_file);
|
|
|
|
if (ref_filesize < 0) goto end;
|
2014-05-02 09:20:10 -07:00
|
|
|
fseek(ref_file, 0, SEEK_SET);
|
|
|
|
ref_content = malloc(ref_filesize + 1);
|
2014-05-27 19:18:03 -07:00
|
|
|
if (fread(ref_content, ref_filesize, 1, ref_file) != 1)
|
|
|
|
goto end;
|
2014-05-02 09:20:10 -07:00
|
|
|
ref_content[ref_filesize] = '\0';
|
2015-09-28 10:50:07 -07:00
|
|
|
while (ref_content[ref_filesize - 1] == '\n')
|
|
|
|
ref_content[--ref_filesize] = '\0';
|
2014-05-02 09:20:10 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-07 04:13:27 -07:00
|
|
|
static void
|
|
|
|
_remove_ref(const char *base, const char *ext)
|
|
|
|
{
|
|
|
|
char ifnbuf[PATH_MAX];
|
2018-11-07 07:07:55 -08:00
|
|
|
if (snprintf(ifnbuf, sizeof(ifnbuf), "%s.%s", base, ext) > PATH_MAX)
|
|
|
|
{
|
|
|
|
printf("remove ref too long for buffer\n");
|
|
|
|
abort();
|
|
|
|
}
|
2016-10-07 04:13:27 -07:00
|
|
|
remove(ifnbuf);
|
|
|
|
}
|
|
|
|
|
2014-05-02 09:20:10 -07:00
|
|
|
static int
|
2014-06-07 22:13:20 -07:00
|
|
|
_eolian_gen_execute(const char *eo_filename, const char *options, const char *output_filename)
|
2014-05-02 09:20:10 -07:00
|
|
|
{
|
|
|
|
char command[PATH_MAX];
|
2018-11-07 07:07:55 -08:00
|
|
|
if (snprintf(command, PATH_MAX,
|
|
|
|
EOLIAN_GEN" %s -S -I \""TESTS_SRC_DIR"/data\" -o %s %s",
|
|
|
|
options, output_filename, eo_filename) > PATH_MAX)
|
|
|
|
{
|
|
|
|
printf("eolian gen command too long for buffer\n");
|
|
|
|
abort();
|
|
|
|
}
|
2014-05-02 09:20:10 -07:00
|
|
|
return system(command);
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_dev_impl_code)
|
2014-05-02 09:20:10 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_object_impl",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2016-10-07 04:13:27 -07:00
|
|
|
_remove_ref(output_filepath, "c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/object_impl.eo", "-gi", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/object_impl_ref.c", output_filepath, "c"));
|
2014-05-02 09:20:10 -07:00
|
|
|
/* Check that nothing is added */
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/object_impl.eo", "-gi", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/object_impl_ref.c", output_filepath, "c"));
|
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/object_impl_add.eo", "-gi", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/object_impl_add_ref.c", output_filepath, "c"));
|
2014-05-02 09:20:10 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-05-02 09:20:10 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_types_generation)
|
2014-07-24 01:55:08 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_typedef",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.h");
|
|
|
|
_remove_ref(output_filepath, "eo.stub.h");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/typedef.eo", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/typedef_ref.h", output_filepath, "eo.h"));
|
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/struct.eo", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/struct_ref.h", output_filepath, "eo.h"));
|
|
|
|
|
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/typedef.eo", "-gs", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/typedef_ref_stub.h", output_filepath, "eo.stub.h"));
|
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/struct.eo", "-gs", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/struct_ref_stub.h", output_filepath, "eo.stub.h"));
|
2014-07-24 01:55:08 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-07-24 01:55:08 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_default_values_generation)
|
2014-09-02 07:00:14 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_class_simple",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/class_simple.eo", "-gc", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/class_simple_ref.c", output_filepath, "eo.c"));
|
2014-09-02 07:00:14 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-09-02 07:00:14 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_override_generation)
|
2014-09-04 03:22:31 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_override",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/override.eo", "-gc", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/override_ref.c", output_filepath, "eo.c"));
|
2014-09-04 03:22:31 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-09-04 03:22:31 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_functions_descriptions)
|
2014-10-19 03:21:11 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_class_simple",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.h");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/class_simple.eo", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/class_simple_ref_eo.h", output_filepath, "eo.h"));
|
2014-10-19 03:21:11 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-10-19 03:21:11 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_import)
|
2015-05-20 00:34:58 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_import_types",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eot.h");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/import_types.eot", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/import_types_ref.h", output_filepath, "eot.h"));
|
2015-05-20 00:34:58 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-05-20 00:34:58 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_docs)
|
2015-07-07 09:19:13 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2016-10-07 04:13:27 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_docs",
|
2015-12-12 02:54:33 -08:00
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.h");
|
2019-05-06 07:46:50 -07:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/eo_docs.eo", "-gh", output_filepath));
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/docs_ref.h", output_filepath, "eo.h"));
|
2015-07-07 09:19:13 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-07-07 09:19:13 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eolian_function_pointers)
|
2017-04-07 09:54:55 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
// .eot
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2017-04-07 09:54:55 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_function_pointers",
|
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eot.h");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/function_types.eot", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/function_types_ref.h", output_filepath, "eot.h"));
|
2017-04-07 09:54:55 -07:00
|
|
|
|
|
|
|
// .eo.h
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.h");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/function_as_argument.eo", "-gh", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/function_as_argument_ref.h", output_filepath, "eo.h"));
|
2017-04-07 09:54:55 -07:00
|
|
|
|
|
|
|
// .eo.c
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/function_as_argument.eo", "-gc", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/function_as_argument_ref.c", output_filepath, "eo.c"));
|
2017-04-07 09:54:55 -07:00
|
|
|
|
|
|
|
// .eo.imp.c
|
|
|
|
_remove_ref(output_filepath, "c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/function_as_argument.eo", "-gi", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/function_as_argument_impl_ref.c", output_filepath, "c"));
|
2017-04-07 09:54:55 -07:00
|
|
|
/* Check that nothing is added */
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/function_as_argument.eo", "-gi", output_filepath));
|
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/function_as_argument_impl_ref.c", output_filepath, "c"));
|
2017-04-07 09:54:55 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2017-04-07 09:54:55 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(owning)
|
2017-09-22 13:56:31 -07:00
|
|
|
{
|
2018-11-07 07:07:55 -08:00
|
|
|
char output_filepath[PATH_MAX + 128] = "";
|
2017-09-22 13:56:31 -07:00
|
|
|
snprintf(output_filepath, PATH_MAX, "%s/eolian_owning",
|
|
|
|
eina_environment_tmp_get());
|
2017-11-10 10:42:43 -08:00
|
|
|
_remove_ref(output_filepath, "eo.c");
|
2017-12-21 11:31:39 -08:00
|
|
|
fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/owning.eo", "-gc", output_filepath));
|
2019-05-17 07:08:23 -07:00
|
|
|
fail_if(!_files_compare(TESTS_SRC_DIR"/data/owning_ref.c", output_filepath, "eo.c"));
|
2017-09-22 13:56:31 -07:00
|
|
|
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2017-09-22 13:56:31 -07:00
|
|
|
|
2014-05-02 09:20:10 -07:00
|
|
|
void eolian_generation_test(TCase *tc)
|
|
|
|
{
|
2014-07-24 01:55:08 -07:00
|
|
|
tcase_add_test(tc, eolian_types_generation);
|
2014-09-02 07:00:14 -07:00
|
|
|
tcase_add_test(tc, eolian_default_values_generation);
|
2014-09-04 03:22:31 -07:00
|
|
|
tcase_add_test(tc, eolian_override_generation);
|
2014-05-02 09:20:10 -07:00
|
|
|
tcase_add_test(tc, eolian_dev_impl_code);
|
2014-10-19 03:21:11 -07:00
|
|
|
tcase_add_test(tc, eolian_functions_descriptions);
|
2015-05-20 00:34:58 -07:00
|
|
|
tcase_add_test(tc, eolian_import);
|
2015-07-07 09:19:13 -07:00
|
|
|
tcase_add_test(tc, eolian_docs);
|
2017-04-07 09:54:55 -07:00
|
|
|
tcase_add_test(tc, eolian_function_pointers);
|
2017-09-22 13:56:31 -07:00
|
|
|
tcase_add_test(tc, owning);
|
2014-05-02 09:20:10 -07:00
|
|
|
}
|