terminology/src/bin/tytest.c

143 lines
3.2 KiB
C
Raw Normal View History

#include "private.h"
#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>
#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
{
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 */
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)
{
MD5Update(&ctx, (unsigned char const*)ty->write_buffer.buf,
ty->write_buffer.len);
}
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-03-03 09:22:18 -08:00
int
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
2019-03-03 09:22:18 -08:00
{
eina_init();
_log_domain = eina_log_domain_register("tytest", NULL);
tytest_common_init();
tytest_common_main_loop();
_tytest_checksum(tytest_termpty_get());
tytest_common_shutdown();
eina_shutdown();
return 0;
}