Suite: support exu files comparison

master
Daniel Zaoui 4 years ago
parent 1f063e3715
commit 53a52a3419
  1. 138
      src/bin/exactness.c

@ -1,5 +1,6 @@
#include "config.h"
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Ecore_File.h>
#include <Ecore_Getopt.h>
#include <Emile.h>
@ -64,12 +65,15 @@ _run_command_prepare(const List_Entry *ent, char *buf)
Eina_Strbuf *sbuf;
const char *base_dir;
Eina_List *itr;
Eina_Bool is_exu;
EINA_LIST_FOREACH(_base_dirs, itr, base_dir)
{
is_exu = EINA_TRUE;
sprintf(scn_path, "%s/%s.exu", base_dir, ent->name);
if (ecore_file_exists(scn_path)) goto ok;
else
{
is_exu = EINA_FALSE;
sprintf(scn_path, "%s/%s.rec", base_dir, ent->name);
if (ecore_file_exists(scn_path)) goto ok;
}
@ -86,10 +90,20 @@ ok:
_scan_objs ? "--scan-objects " : "",
scn_path
);
if (_mode == RUN_PLAY)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, CURRENT_SUBDIR);
if (_mode == RUN_INIT)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, ORIG_SUBDIR);
if (is_exu)
{
if (_mode == RUN_PLAY)
eina_strbuf_append_printf(sbuf, "-o '%s/%s/%s.exu' -- ", _dest_dir, CURRENT_SUBDIR, ent->name);
if (_mode == RUN_INIT)
eina_strbuf_append_printf(sbuf, "-o '%s/%s.exu' -- ", _dest_dir, ent->name);
}
else
{
if (_mode == RUN_PLAY)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, CURRENT_SUBDIR);
if (_mode == RUN_INIT)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, ORIG_SUBDIR);
}
eina_strbuf_append(sbuf, ent->command);
strncpy(buf, eina_strbuf_string_get(sbuf), SCHEDULER_CMD_SIZE-1);
eina_strbuf_free(sbuf);
@ -258,39 +272,98 @@ _is_equal(const char *filename1, const char *filename2)
}
static void
_compare_list_cb(const char *name, const char *path EINA_UNUSED, void *data)
_file_compare(const char *orig_dir, const char *ent_name)
{
const char *prefix = data;
if (_check_prefix(prefix, name))
char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s", orig_dir, ent_name);
snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
if (!_is_equal(filename1, filename2))
{
char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, ORIG_SUBDIR, name);
snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, name);
if (!_is_equal(filename1, filename2))
char buf[EXACTNESS_PATH_MAX];
_compare_errors = eina_list_append(_compare_errors, strdup(ent_name));
/* FIXME: Clean up. */
snprintf(buf, EXACTNESS_PATH_MAX,
"compare '%s' '%s' '%s/%s/comp_%s'",
filename1, filename2,
_dest_dir,
CURRENT_SUBDIR, ent_name);
if (system(buf))
{
char buf[EXACTNESS_PATH_MAX];
_compare_errors = eina_list_append(_compare_errors, strdup(name));
/* FIXME: Clean up. */
snprintf(buf, EXACTNESS_PATH_MAX,
"compare '%s' '%s' '%s/%s/comp_%s'",
filename1, filename2,
_dest_dir,
CURRENT_SUBDIR, name);
if (system(buf))
{
fprintf(stderr, "Failed image comparing '%s'\n", name);
}
fprintf(stderr, "Failed image comparing '%s'\n", ent_name);
}
}
}
static void
_exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
{
Exactness_Unit *unit = exactness_unit_file_read(exu_path);
Exactness_Image *img;
Eina_List *itr;
Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
Eo *e = ecore_evas_get(ee);
int n = 1;
if (!unit) return;
EINA_LIST_FOREACH(unit->imgs, itr, img)
{
char filename[EXACTNESS_PATH_MAX];
Eo *o = evas_object_image_add(e);
snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png",
dir, ent_name, SHOT_DELIMITER, n++);
evas_object_image_size_set(o, img->w, img->h);
evas_object_image_data_set(o, img->pixels);
if (!evas_object_image_save(o, filename, NULL, NULL))
{
printf("Cannot save widget to <%s>\n", filename);
}
efl_del(o);
}
efl_del(e);
ecore_evas_free(ee);
}
static void
_run_test_compare(const List_Entry *ent)
{
char path[EXACTNESS_PATH_MAX];
char origdir[EXACTNESS_PATH_MAX];
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR);
eina_file_dir_list(origdir, 0, _compare_list_cb, ent->name);
const char *base_dir;
Eina_List *itr;
int n = 1;
EINA_LIST_FOREACH(_base_dirs, itr, base_dir)
{
sprintf(path, "%s/%s.exu", base_dir, ent->name);
if (ecore_file_exists(path))
{
char currentdir[EXACTNESS_PATH_MAX];
snprintf(currentdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, CURRENT_SUBDIR);
_exu_imgs_unpack(path, currentdir, ent->name);
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
mkdir(origdir, 0744);
_exu_imgs_unpack(path, origdir, ent->name);
goto found;
}
else
{
sprintf(path, "%s/%s.rec", base_dir, ent->name);
if (!ecore_file_exists(path)) return;
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR);
goto found;
}
}
found:
do
{
sprintf(path, "%s/%s%c%.3d.png", origdir, ent->name, SHOT_DELIMITER, n);
if (ecore_file_exists(path))
{
sprintf(path, "%s%c%.3d.png", ent->name, SHOT_DELIMITER, n);
_file_compare(origdir, path);
}
else break;
n++;
} while (EINA_TRUE);
}
static List_Entry *
@ -423,6 +496,8 @@ main(int argc, char *argv[])
};
ecore_init();
ecore_evas_init();
evas_init();
mode_play = mode_init = mode_simulation = EINA_FALSE;
want_quit = EINA_FALSE;
_dest_dir = "./";
@ -571,9 +646,16 @@ main(int argc, char *argv[])
printf("List of images that failed comparison:\n");
EINA_LIST_FREE(_compare_errors, test_name)
{
Eina_Bool is_from_exu;
char origpath[EXACTNESS_PATH_MAX];
snprintf(origpath, EXACTNESS_PATH_MAX, "%s/%s/orig/%s",
_dest_dir, CURRENT_SUBDIR, test_name);
is_from_exu = ecore_file_exists(origpath);
printf("\t* %s\n", test_name);
fprintf(report_file, "<li><h2>%s</h2> <img src='../orig/%s' alt='Original' /> <img src='%s' alt='Current' /> <img src='comp_%s' alt='Diff' /></li>", test_name, test_name, test_name, test_name);
fprintf(report_file, "<li><h2>%s</h2> <img src='%sorig/%s' alt='Original' /> <img src='%s' alt='Current' /> <img src='comp_%s' alt='Diff' /></li>",
test_name, is_from_exu ? "" : "../",
test_name, test_name, test_name);
free(test_name);
}
fprintf(report_file, "</ul>");
@ -592,6 +674,8 @@ main(int argc, char *argv[])
_list_file_free(test_list);
end:
evas_shutdown();
ecore_evas_shutdown();
ecore_shutdown();
return ret;

Loading…
Cancel
Save