billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=392bfdb4a7d265bc24f3a467ec4701af95e7eb73

commit 392bfdb4a7d265bc24f3a467ec4701af95e7eb73
Author: Boris Faure <bill...@gmail.com>
Date:   Sat May 23 00:57:52 2020 +0200

    tests: rework tytest.c/tyfuzz.c to no longer #include one in the other
---
 src/bin/meson.build                   |   3 +-
 src/bin/termiointernals.c             |   2 +
 src/bin/termptyext.c                  |  21 ++
 src/bin/tyfuzz.c                      | 373 +---------------------------------
 src/bin/tytest.c                      | 137 +++----------
 src/bin/tytest.h                      |   8 +-
 src/bin/{tyfuzz.c => tytest_common.c} | 170 ++++++++++------
 src/bin/tytest_common.h               |  21 ++
 8 files changed, 203 insertions(+), 532 deletions(-)

diff --git a/src/bin/meson.build b/src/bin/meson.build
index faf75e6..192066a 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -38,7 +38,6 @@ terminology_sources = ['private.h',
                        'extns.c', 'extns.h',
                        'gravatar.c', 'gravatar.h',
                        'tty_keys.h',
-                       'tytest.c', 'tytest.h',
                        'sb.c', 'sb.h']
 
 tybg_sources = ['tycommon.c', 'tycommon.h', 'tybg.c']
@@ -62,6 +61,7 @@ tyfuzz_sources = ['termptyesc.c', 'termptyesc.h',
                   'sb.c', 'sb.h',
                   'utf8.c', 'utf8.h',
                   'utils.c', 'utils.h',
+                  'tytest_common.c', 'tytest_common.h',
                   'tyfuzz.c']
 tytest_sources = ['termptyesc.c', 'termptyesc.h',
                   'backlog.c', 'backlog.h',
@@ -78,6 +78,7 @@ tytest_sources = ['termptyesc.c', 'termptyesc.h',
                   'utf8.c', 'utf8.h',
                   'utils.c', 'utils.h',
                   'md5/md5.c', 'md5/md5.h',
+                  'tytest_common.c', 'tytest_common.h',
                   'tytest.c', 'tytest.h']
 
 executable('terminology',
diff --git a/src/bin/termiointernals.c b/src/bin/termiointernals.c
index deb379a..f4a6e2e 100644
--- a/src/bin/termiointernals.c
+++ b/src/bin/termiointernals.c
@@ -10,7 +10,9 @@
 #include "termptyops.h"
 #include "termiointernals.h"
 #include "utf8.h"
+#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI)
 #include "tytest.h"
+#endif
 
 /* {{{ Selection */
 
diff --git a/src/bin/termptyext.c b/src/bin/termptyext.c
index e6d1e2d..bea10f9 100644
--- a/src/bin/termptyext.c
+++ b/src/bin/termptyext.c
@@ -5,7 +5,9 @@
 #include "termpty.h"
 #include "termptyops.h"
 #include "termiointernals.h"
+#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI)
 #include "tytest.h"
+#endif
 #include <assert.h>
 
 #undef CRITICAL
@@ -32,6 +34,25 @@
 
 #if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI)
 
+static int _mx;
+static int _my;
+
+void
+test_set_mouse_pointer(int mx, int my)
+{
+   _mx = mx;
+   _my = my;
+}
+
+void
+test_pointer_canvas_xy_get(int *mx, int *my)
+{
+   if (mx)
+     *mx = _mx;
+   if (my)
+     *my = _my;
+}
+
 static int
 _tytest_arg_get(const Eina_Unicode *buf, int *value)
 {
diff --git a/src/bin/tyfuzz.c b/src/bin/tyfuzz.c
index 21cd895..28c948c 100644
--- a/src/bin/tyfuzz.c
+++ b/src/bin/tyfuzz.c
@@ -5,388 +5,35 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <assert.h>
+
 #include "private.h"
 #include <Elementary.h>
+#include "config.h"
 #include "termpty.h"
 #include "termptyops.h"
 #include "termiointernals.h"
-#include <assert.h>
-
-#ifdef TYTEST
-#include "col.h"
-#include "tytest.h"
-#include "md5/md5.h"
-
-static void
-_tytest_checksum(Termpty *ty);
-#endif
-
-#define TY_H 24
-#define TY_W 80
-#define TY_CH_H 15
-#define TY_CH_W  7
-#define TY_OFFSET_X 1
-#define TY_OFFSET_Y 1
-#define TY_BACKSIZE 50
-
+#include "tytest_common.h"
 
-/* {{{ stub */
 int _log_domain = -1;
 
-static Config *_config = NULL;
-static Termpty _ty;
-static Termio _sd = {
-     .font = {
-          .name = "",
-          .size = 10,
-          .chw = TY_CH_W,
-          .chh = TY_CH_H,
-     },
-     .grid = {
-          .w = TY_W,
-          .h = TY_H,
-     },
-     .sel = {},
-     .cursor = {
-          .obj = NULL,
-          .x = 0,
-          .y = 0,
-          .shape = CURSOR_SHAPE_BLOCK,
-     },
-     .mouse = {},
-     .link = {},
-     .pty = &_ty,
-     .config = NULL,
-};
-
-void
-main_config_sync(const Config *config EINA_UNUSED)
-{
-}
-
-
-Termio *
-termio_get_from_obj(Evas_Object *obj EINA_UNUSED)
-{
-   return &_sd;
-}
-
-Config *
-termio_config_get(const Evas_Object *obj EINA_UNUSED)
-{
-   return _config;
-}
-
-void
-termio_take_selection_text(Termio *sd EINA_UNUSED,
-                           Elm_Sel_Type type EINA_UNUSED,
-                           const char *text EINA_UNUSED)
-{
-}
-
-void
-termio_paste_selection(Evas_Object *obj EINA_UNUSED,
-                       Elm_Sel_Type type EINA_UNUSED)
-{
-}
-
-void
-termio_smart_update_queue(Termio *sd EINA_UNUSED)
-{
-}
-
-void
-termio_handle_right_click(Evas_Event_Mouse_Down *ev EINA_UNUSED,
-                          Termio *sd EINA_UNUSED,
-                          int cx EINA_UNUSED, int cy EINA_UNUSED)
-{
-}
-
-void
-termio_smart_cb_mouse_move_job(void *data EINA_UNUSED)
-{
-}
-
-void
-miniview_position_offset(const Evas_Object *obj EINA_UNUSED,
-                         int by EINA_UNUSED,
-                         Eina_Bool sanitize EINA_UNUSED)
-{
-}
-
-Evas_Object *
-term_miniview_get(const Term *term EINA_UNUSED)
-{
-   return NULL;
-}
-
 int
-termio_scroll_get(const Evas_Object *obj EINA_UNUSED)
-{
-   return _sd.scroll;
-}
-
-void
-termio_size_get(const Evas_Object *obj EINA_UNUSED,
-                int *w, int *h)
-{
-   if (w) *w = _sd.grid.w;
-   if (h) *h = _sd.grid.h;
-}
-
-Termpty *
-termio_pty_get(const Evas_Object *obj EINA_UNUSED)
-{
-   return &_ty;
-}
-
-Eina_Bool
-termio_cwd_get(const Evas_Object *obj EINA_UNUSED,
-               char *buf,
-               size_t size)
-{
-   assert (size >= 2);
-
-   buf[0] = '\0';
-   buf[1] = '\0';
-
-   return EINA_TRUE;
-}
-
-void
-termio_sel_set(Termio *sd, Eina_Bool enable)
-{
-   sd->pty->selection.is_active = enable;
-   if (!enable)
-     {
-        sd->pty->selection.by_word = EINA_FALSE;
-        sd->pty->selection.by_line = EINA_FALSE;
-        free(sd->pty->selection.codepoints);
-        sd->pty->selection.codepoints = NULL;
-     }
-}
-void
-termio_object_geometry_get(Termio *sd,
-                           Evas_Coord *x, Evas_Coord *y,
-                           Evas_Coord *w, Evas_Coord *h)
-{
-     if (x)
-       *x = TY_OFFSET_X;
-     if (y)
-       *y = TY_OFFSET_Y;
-     if (w)
-       *w = TY_OFFSET_X + sd->font.chw * sd->grid.w;
-     if (h)
-       *h = TY_OFFSET_Y + sd->font.chh * sd->grid.h;
-}
-
-void
-termio_font_size_set(Evas_Object *obj EINA_UNUSED,
-                     int size)
-{
-   _sd.font.size = size;
-}
-
-const char *
-term_preedit_str_get(Term *term EINA_UNUSED)
-{
-   return NULL;
-}
-
-void
-termio_block_activate(Evas_Object *obj EINA_UNUSED,
-                      Termblock *blk EINA_UNUSED)
-{
-}
-
-Eina_Bool
-termio_take_selection(Evas_Object *obj,
-                      Elm_Sel_Type type EINA_UNUSED)
-{
-   Termio *sd;
-   const char *s;
-   size_t len;
-
-   sd = termio_get_from_obj(obj);
-   s = termio_internal_get_selection(sd, &len);
-   if (s)
-     {
-        eina_stringshare_del(s);
-        return EINA_TRUE;
-     }
-   return EINA_FALSE;
-}
-
-void
-termio_remove_links(Termio *sd)
-{
-   sd->link.string = NULL;
-   sd->link.x1 = -1;
-   sd->link.y1 = -1;
-   sd->link.x2 = -1;
-   sd->link.y2 = -1;
-   sd->link.suspend = EINA_FALSE;
-   sd->link.id = 0;
-   sd->link.objs = 0;
-}
-
-#ifndef TYTEST
-void
-termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
-                        Cursor_Shape shape EINA_UNUSED)
-{
-}
-#endif
-
-int
-termpty_color_class_get(Termpty *ty EINA_UNUSED, const char *key,
-                        int *r, int *g, int *b, int *a)
-{
-   if (strncmp(key, "BG", strlen("BG")) == 0)
-     {
-        if (r)
-          *r = 131;
-        if (g)
-          *g = 132;
-        if (b)
-          *b = 133;
-        if (a)
-          *a = 134;
-        return 0;
-     }
-   return -1;
-}
-/* }}} */
-
-
-
-static void
-_termpty_init(Termpty *ty, Config *config)
-{
-   memset(ty, '\0', sizeof(*ty));
-   ty->config = config;
-   ty->w = TY_W;
-   ty->h = TY_H;
-   ty->backsize = TY_BACKSIZE;
-   termpty_resize_tabs(ty, 0, ty->w);
-   termpty_reset_state(ty);
-   ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
-   ty->screen2 = calloc(1, sizeof(Termcell) * ty->w * ty->h);
-   assert(ty->screen);
-   assert(ty->screen2);
-   ty->circular_offset = 0;
-   ty->fd = STDIN_FILENO;
-   ty->hl.bitmap = calloc(1, HL_LINKS_MAX / 8); /* bit map for 1 << 16 
elements */
-   assert(ty->hl.bitmap);
-   /* Mark id 0 as set */
-   ty->hl.bitmap[0] = 1;
-   ty->backlog_beacon.backlog_y = 0;
-   ty->backlog_beacon.screen_y = 0;
-}
-
-int
-main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
+main(int argc, char **argv)
 {
    eina_init();
 
-#ifdef TYTEST
-   tytest_init();
-#endif
-
-
-   _log_domain = eina_log_domain_register(
-#ifdef TYTEST
-       "tytest",
-#else
-       "tyfuzz",
-#endif
-       NULL);
-
-   _config = config_new();
-   _sd.config = _config;
+   _log_domain = eina_log_domain_register("tyfuzz", NULL);
 
-   _termpty_init(&_ty, _config);
+   tytest_common_init();
 
    if (argc > 1)
      {
-       _ty.fd = open(argv[1], O_RDONLY);
-       assert(_ty.fd >= 0);
+       tytest_common_set_fd(open(argv[1], O_RDONLY));
      }
 
-   do
-     {
-        char buf[4097];
-        Eina_Unicode codepoint[4097];
-        int i, j;
-        char *rbuf = buf;
-        int len = sizeof(buf) - 1;
-
-        for (i = 0; i < (int)sizeof(_ty.oldbuf) && _ty.oldbuf[i] & 0x80; i++)
-          {
-             *rbuf = _ty.oldbuf[i];
-             rbuf++;
-             len--;
-          }
-        len = read(_ty.fd, rbuf, len);
-        if (len < 0 && errno != EAGAIN)
-          {
-             ERR("error while reading from tty slave fd");
-             break;
-          }
-        if (len <= 0) break;
-
-        for (i = 0; i < (int)sizeof(_ty.oldbuf); i++)
-          _ty.oldbuf[i] = 0;
-
-        len += rbuf - buf;
-
-        buf[len] = 0;
-        // convert UTF8 to codepoint integers
-        j = 0;
-        for (i = 0; i < len;)
-          {
-             int g = 0, prev_i = i;
-
-             if (buf[i])
-               {
-                  g = eina_unicode_utf8_next_get(buf, &i);
-                  if ((0xdc80 <= g) && (g <= 0xdcff) &&
-                      (len - prev_i) <= (int)sizeof(_ty.oldbuf))
-                    {
-                       int k;
-                       for (k = 0;
-                            (k < (int)sizeof(_ty.oldbuf)) &&
-                            (k < (len - prev_i));
-                            k++)
-                         {
-                            _ty.oldbuf[k] = buf[prev_i+k];
-                         }
-                       DBG("failure at %d/%d/%d", prev_i, i, len);
-                       break;
-                    }
-               }
-             else
-               {
-                  g = 0;
-                  i++;
-               }
-             codepoint[j] = g;
-             j++;
-          }
-        codepoint[j] = 0;
-        termpty_handle_buf(&_ty, codepoint, j);
-     }
-   while (1);
-
-#ifdef TYTEST
-   _tytest_checksum(&_ty);
-#endif
-
-#ifdef TYTEST
-   tytest_shutdown();
-#endif
+   tytest_common_main_loop();
 
-   config_del(_config);
+   tytest_common_shutdown();
    eina_shutdown();
 
    return 0;
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 07dcaf4..b28d132 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -1,10 +1,24 @@
 #include "private.h"
-#if defined(ENABLE_TESTS)
-#define TYTEST 1
-#include "tyfuzz.c"
+#include <stdio.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <assert.h>
 
-static const char *_cursor_shape = "undefined";
-static Evas_Textgrid_Cell *_cells;
+#include "private.h"
+#include <Elementary.h>
+#include "config.h"
+#include "termpty.h"
+#include "termptyops.h"
+#include "termiointernals.h"
+#include "tytest_common.h"
+
+#include "md5/md5.h"
+
+int _log_domain = -1;
 
 typedef struct _Termpty_Tests
 {
@@ -20,59 +34,6 @@ typedef struct _Termpty_Tests
    unsigned int bracketed_paste : 1;
 } Termpty_Tests;
 
-Evas_Object *
-termio_textgrid_get(const Evas_Object *obj EINA_UNUSED)
-{
-   return NULL;
-}
-
-void
-test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED,
-                          Evas_Textgrid_Palette pal,
-                          int idx,
-                          int *r,
-                          int *g,
-                          int *b,
-                          int *a)
-{
-   if (pal == EVAS_TEXTGRID_PALETTE_EXTENDED)
-     {
-        colors_256_get(idx,
-                       (unsigned char *)r,
-                       (unsigned char *)g,
-                       (unsigned char *)b,
-                       (unsigned char *)a);
-     }
-   else
-     {
-        int set = idx / 12;
-        int col = idx % 12;
-        colors_standard_get(set, col,
-                            (unsigned char*)r,
-                            (unsigned char*)g,
-                            (unsigned char*)b,
-                            (unsigned char*)a);
-     }
-}
-
-void
-termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
-                        Cursor_Shape shape EINA_UNUSED)
-{
-   switch (shape)
-     {
-      case CURSOR_SHAPE_UNDERLINE:
-         _cursor_shape = "underline";
-         break;
-      case CURSOR_SHAPE_BAR:
-         _cursor_shape = "bar";
-         break;
-      default:
-      case CURSOR_SHAPE_BLOCK:
-         _cursor_shape = "block";
-     }
-}
-
 static void
 _termpty_to_termpty_tests(Termpty *ty, Termpty_Tests *tt)
 {
@@ -138,8 +99,9 @@ _tytest_checksum(Termpty *ty)
         MD5Update(&ctx, (unsigned char const*)"(NULL)", 6);
      }
    /* Cursor shape */
-   MD5Update(&ctx, (unsigned char const*)_cursor_shape,
-             strlen(_cursor_shape));
+   const char *cursor_shape = tytest_cursor_shape_get();
+   MD5Update(&ctx, (unsigned char const*)cursor_shape,
+             strlen(cursor_shape));
    /* Write buffer */
    if (ty->write_buffer.buf)
      {
@@ -158,56 +120,23 @@ _tytest_checksum(Termpty *ty)
    printf("%s", md5out);
 }
 
-Evas_Textgrid_Cell *
-test_textgrid_cellrow_get(Evas_Object *obj EINA_UNUSED, int y)
-{
-   assert (y >= 0 && y < _sd.pty->h);
-   return &_cells[y * _sd.pty->w];
-}
 
-void
-tytest_termio_resize(int w, int h)
+int
+main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
 {
-   Evas_Textgrid_Cell *cells = realloc(_cells,
-                                       w * h * sizeof(Evas_Textgrid_Cell));
-   assert (cells);
-   _sd.grid.w = w;
-   _sd.grid.h = h;
-   _cells = cells;
-}
+   eina_init();
 
+   _log_domain = eina_log_domain_register("tytest", NULL);
 
-void
-tytest_init(void)
-{
-   _cells = calloc(TY_H * TY_W, sizeof(Evas_Textgrid_Cell));
-   assert(_cells != NULL);
-}
+   tytest_common_init();
 
-void
-tytest_shutdown(void)
-{
-   free(_cells);
-}
-#endif
+   tytest_common_main_loop();
 
-#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI)
-static int _mx;
-static int _my;
+   _tytest_checksum(tytest_termpty_get());
 
-void
-test_set_mouse_pointer(int mx, int my)
-{
-   _mx = mx;
-   _my = my;
-}
+   tytest_common_shutdown();
 
-void
-test_pointer_canvas_xy_get(int *mx, int *my)
-{
-   if (mx)
-     *mx = _mx;
-   if (my)
-     *my = _my;
+   eina_shutdown();
+
+   return 0;
 }
-#endif
diff --git a/src/bin/tytest.h b/src/bin/tytest.h
index d6b3ca8..1c41cfe 100644
--- a/src/bin/tytest.h
+++ b/src/bin/tytest.h
@@ -12,16 +12,12 @@ test_textgrid_palette_get(const Evas_Object *obj,
                           int *b,
                           int *a);
 
-#define evas_object_textgrid_cellrow_get  test_textgrid_cellrow_get
+#define evas_object_textgrid_cellrow_get  tytest_textgrid_cellrow_get
 Evas_Textgrid_Cell *
-test_textgrid_cellrow_get(Evas_Object *obj, int y);
-
+tytest_textgrid_cellrow_get(Evas_Object *obj, int y);
 
 void
 tytest_termio_resize(int w, int h);
-
-void tytest_init(void);
-void tytest_shutdown(void);
 #endif
 
 #if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI)
diff --git a/src/bin/tyfuzz.c b/src/bin/tytest_common.c
similarity index 75%
copy from src/bin/tyfuzz.c
copy to src/bin/tytest_common.c
index 21cd895..149aa88 100644
--- a/src/bin/tyfuzz.c
+++ b/src/bin/tytest_common.c
@@ -1,3 +1,4 @@
+#include "private.h"
 #include <stdio.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -10,28 +11,12 @@
 #include "termpty.h"
 #include "termptyops.h"
 #include "termiointernals.h"
-#include <assert.h>
-
-#ifdef TYTEST
+#include "tytest_common.h"
+#if defined(ENABLE_TESTS)
 #include "col.h"
 #include "tytest.h"
-#include "md5/md5.h"
-
-static void
-_tytest_checksum(Termpty *ty);
 #endif
-
-#define TY_H 24
-#define TY_W 80
-#define TY_CH_H 15
-#define TY_CH_W  7
-#define TY_OFFSET_X 1
-#define TY_OFFSET_Y 1
-#define TY_BACKSIZE 50
-
-
-/* {{{ stub */
-int _log_domain = -1;
+#include <assert.h>
 
 static Config *_config = NULL;
 static Termpty _ty;
@@ -58,6 +43,41 @@ static Termio _sd = {
      .pty = &_ty,
      .config = NULL,
 };
+static const char *_cursor_shape = "undefined";
+#if defined(ENABLE_TESTS)
+static Evas_Textgrid_Cell *_cells;
+
+const char *
+tytest_cursor_shape_get(void)
+{
+   return _cursor_shape;
+}
+
+Evas_Textgrid_Cell *
+tytest_textgrid_cellrow_get(Evas_Object *obj EINA_UNUSED, int y)
+{
+   assert (y >= 0 && y < _sd.pty->h);
+   return &_cells[y * _sd.pty->w];
+}
+
+void
+tytest_termio_resize(int w, int h)
+{
+   Evas_Textgrid_Cell *cells = realloc(_cells,
+                                       w * h * sizeof(Evas_Textgrid_Cell));
+   assert (cells);
+   _sd.grid.w = w;
+   _sd.grid.h = h;
+   _cells = cells;
+}
+
+Termpty *
+tytest_termpty_get(void)
+{
+   return &_ty;
+}
+#endif
+
 
 void
 main_config_sync(const Config *config EINA_UNUSED)
@@ -230,13 +250,24 @@ termio_remove_links(Termio *sd)
    sd->link.objs = 0;
 }
 
-#ifndef TYTEST
 void
 termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
                         Cursor_Shape shape EINA_UNUSED)
 {
+   switch (shape)
+     {
+      case CURSOR_SHAPE_UNDERLINE:
+         _cursor_shape = "underline";
+         break;
+      case CURSOR_SHAPE_BAR:
+         _cursor_shape = "bar";
+         break;
+      default:
+      case CURSOR_SHAPE_BLOCK:
+         _cursor_shape = "block";
+     }
 }
-#endif
+
 
 int
 termpty_color_class_get(Termpty *ty EINA_UNUSED, const char *key,
@@ -256,9 +287,43 @@ termpty_color_class_get(Termpty *ty EINA_UNUSED, const 
char *key,
      }
    return -1;
 }
-/* }}} */
 
+Evas_Object *
+termio_textgrid_get(const Evas_Object *obj EINA_UNUSED)
+{
+   return NULL;
+}
 
+#if defined(ENABLE_TESTS)
+void
+test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED,
+                          Evas_Textgrid_Palette pal,
+                          int idx,
+                          int *r,
+                          int *g,
+                          int *b,
+                          int *a)
+{
+   if (pal == EVAS_TEXTGRID_PALETTE_EXTENDED)
+     {
+        colors_256_get(idx,
+                       (unsigned char *)r,
+                       (unsigned char *)g,
+                       (unsigned char *)b,
+                       (unsigned char *)a);
+     }
+   else
+     {
+        int set = idx / 12;
+        int col = idx % 12;
+        colors_standard_get(set, col,
+                            (unsigned char*)r,
+                            (unsigned char*)g,
+                            (unsigned char*)b,
+                            (unsigned char*)a);
+     }
+}
+#endif
 
 static void
 _termpty_init(Termpty *ty, Config *config)
@@ -284,35 +349,9 @@ _termpty_init(Termpty *ty, Config *config)
    ty->backlog_beacon.screen_y = 0;
 }
 
-int
-main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
+void
+tytest_common_main_loop(void)
 {
-   eina_init();
-
-#ifdef TYTEST
-   tytest_init();
-#endif
-
-
-   _log_domain = eina_log_domain_register(
-#ifdef TYTEST
-       "tytest",
-#else
-       "tyfuzz",
-#endif
-       NULL);
-
-   _config = config_new();
-   _sd.config = _config;
-
-   _termpty_init(&_ty, _config);
-
-   if (argc > 1)
-     {
-       _ty.fd = open(argv[1], O_RDONLY);
-       assert(_ty.fd >= 0);
-     }
-
    do
      {
         char buf[4097];
@@ -377,17 +416,32 @@ main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
         termpty_handle_buf(&_ty, codepoint, j);
      }
    while (1);
+}
 
-#ifdef TYTEST
-   _tytest_checksum(&_ty);
-#endif
-
-#ifdef TYTEST
-   tytest_shutdown();
+void
+tytest_common_init(void)
+{
+   _config = config_new();
+   _sd.config = _config;
+   _termpty_init(&_ty, _config);
+#if defined(ENABLE_TESTS)
+   _cells = calloc(TY_H * TY_W, sizeof(Evas_Textgrid_Cell));
+   assert(_cells != NULL);
 #endif
+}
 
+void
+tytest_common_shutdown(void)
+{
    config_del(_config);
-   eina_shutdown();
+#if defined(ENABLE_TESTS)
+   free(_cells);
+#endif
+}
 
-   return 0;
+void
+tytest_common_set_fd(int fd)
+{
+   _ty.fd = fd;
+   assert(_ty.fd >= 0);
 }
diff --git a/src/bin/tytest_common.h b/src/bin/tytest_common.h
new file mode 100644
index 0000000..a19b74a
--- /dev/null
+++ b/src/bin/tytest_common.h
@@ -0,0 +1,21 @@
+#ifndef _TYTEST_COMMON_H__
+#define _TYTEST_COMMON_H__ 1
+
+#define TY_H 24
+#define TY_W 80
+#define TY_CH_H 15
+#define TY_CH_W  7
+#define TY_OFFSET_X 1
+#define TY_OFFSET_Y 1
+#define TY_BACKSIZE 50
+
+void tytest_common_main_loop(void);
+void tytest_common_init(void);
+void tytest_common_shutdown(void);
+void tytest_common_set_fd(int fd);
+#if defined(ENABLE_TESTS)
+const char *tytest_cursor_shape_get(void);
+Termpty *tytest_termpty_get(void);
+#endif
+
+#endif

-- 


Reply via email to