2020-05-03 04:19:01 -07:00
|
|
|
|
#include "private.h"
|
2020-05-22 15:57:52 -07:00
|
|
|
|
#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>
|
2019-02-05 14:25:20 -08:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
#include "private.h"
|
|
|
|
|
#include <Elementary.h>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "termpty.h"
|
|
|
|
|
#include "termptyops.h"
|
|
|
|
|
#include "termiointernals.h"
|
2020-05-23 02:44:47 -07:00
|
|
|
|
#include "tytest.h"
|
2020-05-23 15:05:29 -07:00
|
|
|
|
#include "unit_tests.h"
|
2020-05-22 15:57:52 -07:00
|
|
|
|
#include "tytest_common.h"
|
|
|
|
|
|
|
|
|
|
#include "md5/md5.h"
|
|
|
|
|
|
|
|
|
|
int _log_domain = -1;
|
2019-02-05 14:25:20 -08:00
|
|
|
|
|
2020-05-23 02:44:47 -07:00
|
|
|
|
/* {{{ Unit tests */
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
tytest_func func;
|
|
|
|
|
} _tytests[] = {
|
|
|
|
|
{ "dummy", tytest_dummy },
|
2020-05-23 15:05:29 -07:00
|
|
|
|
{ "sb", tytest_sb},
|
2020-05-23 02:44:47 -07:00
|
|
|
|
{ NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_run_this_tytest(const char *name, tytest_func func)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
fprintf(stderr, "\033[0m%s...", name);
|
|
|
|
|
res = func();
|
|
|
|
|
fprintf(stderr, " %s\n", res == 0 ? "\033[32m✔" : "\033[31;1m×");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static tytest_func
|
|
|
|
|
_find_tytest(const char *name)
|
|
|
|
|
{
|
|
|
|
|
int ntests = (sizeof(_tytests) / sizeof(_tytests[0])) - 1;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ntests; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(name, _tytests[i].name) == 0)
|
|
|
|
|
return _tytests[i].func;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_run_all_tytests(void)
|
|
|
|
|
{
|
|
|
|
|
int ntests = (sizeof(_tytests) / sizeof(_tytests[0])) - 1;
|
|
|
|
|
int i, res = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; res == 0 && i < ntests; i++)
|
|
|
|
|
res = _run_this_tytest(_tytests[i].name, _tytests[i].func);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_run_tytests(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int i, res = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 1; res == 0 && i < argc; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strncmp(argv[i], "all", strlen("all")) == 0)
|
|
|
|
|
res = _run_all_tytests();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tytest_func func = _find_tytest(argv[i]);
|
|
|
|
|
if (!func)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "can not find test named '%s'\n", argv[i]);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
res = _run_this_tytest(argv[i], func);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2019-02-05 14:25:20 -08:00
|
|
|
|
typedef struct _Termpty_Tests
|
|
|
|
|
{
|
|
|
|
|
size_t backsize, backpos;
|
|
|
|
|
Backlog_Beacon backlog_beacon;
|
|
|
|
|
Term_State termstate;
|
|
|
|
|
Term_Cursor cursor_state;
|
|
|
|
|
Term_Cursor cursor_save[2];
|
|
|
|
|
int w, h;
|
|
|
|
|
unsigned int altbuf : 1;
|
|
|
|
|
unsigned int mouse_mode : 3;
|
|
|
|
|
unsigned int mouse_ext : 2;
|
|
|
|
|
unsigned int bracketed_paste : 1;
|
|
|
|
|
} Termpty_Tests;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_termpty_to_termpty_tests(Termpty *ty, Termpty_Tests *tt)
|
|
|
|
|
{
|
|
|
|
|
memset(tt, '\0', sizeof(*tt));
|
|
|
|
|
tt->backsize = ty->backsize;
|
|
|
|
|
tt->backpos = ty->backpos;
|
|
|
|
|
tt->backlog_beacon = ty->backlog_beacon;
|
|
|
|
|
tt->termstate = ty->termstate;
|
|
|
|
|
tt->cursor_state = ty->cursor_state;
|
|
|
|
|
tt->cursor_save[0] = ty->cursor_save[0];
|
|
|
|
|
tt->cursor_save[1] = ty->cursor_save[1];
|
|
|
|
|
tt->w = ty->w;
|
|
|
|
|
tt->h = ty->h;
|
|
|
|
|
tt->altbuf = ty->altbuf;
|
|
|
|
|
tt->mouse_mode = ty->mouse_mode;
|
|
|
|
|
tt->mouse_ext = ty->mouse_ext;
|
|
|
|
|
tt->bracketed_paste = ty->bracketed_paste;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_tytest_checksum(Termpty *ty)
|
|
|
|
|
{
|
|
|
|
|
MD5_CTX ctx;
|
|
|
|
|
Termpty_Tests tests;
|
|
|
|
|
char md5out[(2 * MD5_HASHBYTES) + 1];
|
|
|
|
|
unsigned char hash[MD5_HASHBYTES];
|
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
_termpty_to_termpty_tests(ty, &tests);
|
|
|
|
|
|
|
|
|
|
MD5Init(&ctx);
|
|
|
|
|
/* Termpty */
|
|
|
|
|
MD5Update(&ctx,
|
|
|
|
|
(unsigned char const*)&tests,
|
|
|
|
|
sizeof(tests));
|
|
|
|
|
/* The screens */
|
|
|
|
|
MD5Update(&ctx,
|
|
|
|
|
(unsigned char const*)ty->screen,
|
|
|
|
|
sizeof(Termcell) * ty->w * ty->h);
|
|
|
|
|
MD5Update(&ctx,
|
|
|
|
|
(unsigned char const*)ty->screen2,
|
|
|
|
|
sizeof(Termcell) * ty->w * ty->h);
|
|
|
|
|
/* Icon/Title */
|
|
|
|
|
if (ty->prop.icon)
|
|
|
|
|
{
|
|
|
|
|
MD5Update(&ctx,
|
|
|
|
|
(unsigned char const*)ty->prop.icon,
|
|
|
|
|
strlen(ty->prop.icon));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MD5Update(&ctx, (unsigned char const*)"(NULL)", 6);
|
|
|
|
|
}
|
|
|
|
|
if (ty->prop.title)
|
|
|
|
|
{
|
|
|
|
|
MD5Update(&ctx,
|
|
|
|
|
(unsigned char const*)ty->prop.title,
|
|
|
|
|
strlen(ty->prop.title));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MD5Update(&ctx, (unsigned char const*)"(NULL)", 6);
|
|
|
|
|
}
|
|
|
|
|
/* Cursor shape */
|
2020-05-22 15:57:52 -07:00
|
|
|
|
const char *cursor_shape = tytest_cursor_shape_get();
|
|
|
|
|
MD5Update(&ctx, (unsigned char const*)cursor_shape,
|
|
|
|
|
strlen(cursor_shape));
|
2019-02-05 14:25:20 -08:00
|
|
|
|
/* Write buffer */
|
2019-07-07 09:06:29 -07:00
|
|
|
|
if (ty->write_buffer.buf)
|
|
|
|
|
{
|
|
|
|
|
MD5Update(&ctx, (unsigned char const*)ty->write_buffer.buf,
|
|
|
|
|
ty->write_buffer.len);
|
|
|
|
|
}
|
2019-02-05 14:25:20 -08:00
|
|
|
|
|
|
|
|
|
MD5Final(hash, &ctx);
|
|
|
|
|
|
|
|
|
|
for (n = 0; n < MD5_HASHBYTES; n++)
|
|
|
|
|
{
|
|
|
|
|
md5out[2 * n] = hex[hash[n] >> 4];
|
|
|
|
|
md5out[2 * n + 1] = hex[hash[n] & 0x0f];
|
|
|
|
|
}
|
|
|
|
|
md5out[2 * MD5_HASHBYTES] = '\0';
|
|
|
|
|
printf("%s", md5out);
|
|
|
|
|
}
|
2019-02-11 13:44:16 -08:00
|
|
|
|
|
2019-03-03 09:22:18 -08:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
int
|
2020-05-23 02:44:47 -07:00
|
|
|
|
main(int argc, char **argv)
|
2019-03-03 09:22:18 -08:00
|
|
|
|
{
|
2020-05-23 02:44:47 -07:00
|
|
|
|
if (argc > 1)
|
|
|
|
|
return _run_tytests(argc, argv);
|
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
eina_init();
|
2019-02-11 13:44:16 -08:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
_log_domain = eina_log_domain_register("tytest", NULL);
|
2019-02-11 13:44:16 -08:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
tytest_common_init();
|
2019-02-11 13:44:16 -08:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
tytest_common_main_loop();
|
2020-05-03 04:19:01 -07:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
_tytest_checksum(tytest_termpty_get());
|
2020-05-03 04:19:01 -07:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
tytest_common_shutdown();
|
2020-05-03 04:19:01 -07:00
|
|
|
|
|
2020-05-22 15:57:52 -07:00
|
|
|
|
eina_shutdown();
|
|
|
|
|
|
|
|
|
|
return 0;
|
2020-05-03 04:19:01 -07:00
|
|
|
|
}
|