~rcr/rirc

7fa5c456d5511fc19f7cb82f7fc45aa84235e38c — Richard Robbins 2 years ago be2378b
Fix handler parsing, cleanup testcases
M src/handlers/irc_ctcp.c => src/handlers/irc_ctcp.c +1 -1
@@ 49,7 49,7 @@ parse_ctcp(struct server *s, const char *from, char **args, const char **cmd)
		*p = toupper(*p);

	*cmd = command;
	*args = message;
	*args = saveptr;

	return 0;
}

M src/handlers/irc_send.c => src/handlers/irc_send.c +7 -7
@@ 44,10 44,10 @@ irc_send_command(struct server *s, struct channel *c, char *m)
		*p = toupper(*p);

	if ((send = send_handler_lookup(command, strlen(command))))
		return send->f(s, c, m);
		return send->f(s, c, saveptr);

	if (str_trim(&m))
		sendf(s, c, "%s %s", command, m);
	if (str_trim(&saveptr))
		sendf(s, c, "%s %s", command, saveptr);
	else
		sendf(s, c, "%s", command);
}


@@ 186,10 186,10 @@ send_notice(struct server *s, struct channel *c, char *m)
	if (!(targ = strtok_r(m, " ", &saveptr)))
		failf(c, "Usage: /notice <target> <message>");

	if (*m == 0)
	if (*saveptr == 0)
		failf(c, "Usage: /notice <target> <message>");

	sendf(s, c, "NOTICE %s :%s", targ, m);
	sendf(s, c, "NOTICE %s :%s", targ, saveptr);
}

static int


@@ 213,10 213,10 @@ send_privmsg(struct server *s, struct channel *c, char *m)
	if (!(targ = strtok_r(m, " ", &saveptr)))
		failf(c, "Usage: /privmsg <target> <message>");

	if (*m == 0)
	if (*saveptr == 0)
		failf(c, "Usage: /privmsg <target> <message>");

	sendf(s, c, "PRIVMSG %s :%s", targ, m);
	sendf(s, c, "PRIVMSG %s :%s", targ, saveptr);
}

static int

M test/draw.c => test/draw.c +4 -30
@@ 1,7 1,5 @@
#include "test/test.h"

/* FIXME: decouple draw.c and state.c, irc_send.c, irc_recv.c */

#include "src/components/buffer.c"
#include "src/components/channel.c"
#include "src/components/input.c"


@@ 12,34 10,10 @@
#include "src/state.c"
#include "src/utils/utils.c"

/* Mock rirc.c */
const char *default_username = "username";
const char *default_realname = "realname";

/* Mock io.c */
struct connection*
connection(const void *o, const char *h, const char *p)
{
	UNUSED(o);
	UNUSED(h);
	UNUSED(p);
	return NULL;
}
const char* io_err(int err) { UNUSED(err); return "err"; }
int io_cx(struct connection *c) { UNUSED(c); return 0; }
int io_dx(struct connection *c) { UNUSED(c); return 0; }
int io_sendf(struct connection *c, const char *f, ...) { UNUSED(c); UNUSED(f); return 0; }
unsigned io_tty_cols(void) { return 0; }
unsigned io_tty_rows(void) { return 0; }
void io_free(struct connection *c) { UNUSED(c); }
void io_term(void) { ; }

/* Mock handlers/irc_send.c */
int irc_send_command(struct server *s, struct channel *c, char *m) { UNUSED(s); UNUSED(c); UNUSED(m); return 0; }
int irc_send_privmsg(struct server *s, struct channel *c, char *m) { UNUSED(s); UNUSED(c); UNUSED(m); return 0; }

/* Mock handlers/irc_recv.c */
int irc_recv(struct server *s, struct irc_message *m) { UNUSED(s); UNUSED(m); return 0; }
#include "test/io.c.mock"
#include "test/rirc.c.mock"
#include "test/handlers/irc_recv.c.mock"
#include "test/handlers/irc_send.c.mock"

static void
test_STUB(void)

A test/draw.c.mock => test/draw.c.mock +17 -0
@@ 0,0 1,17 @@
void draw(union draw d) { UNUSED(d); }
void draw_bell(void) { ; }
void draw_term(void) { ; }
void
split_buffer_cols(
	struct buffer_line *l,
	unsigned int *h,
	unsigned int *t,
	unsigned int c,
	unsigned int p)
{
	UNUSED(l);
	UNUSED(h);
	UNUSED(t);
	UNUSED(c);
	UNUSED(p);
}

M test/handlers/irc_ctcp.c => test/handlers/irc_ctcp.c +1 -1
@@ 32,7 32,7 @@ static struct channel *c_chan;
static struct channel *c_priv;
static struct server *s;

/* Mock stat.c */
/* Mock state.c */
void
newlinef(struct channel *c, enum buffer_line_t t, const char *f, const char *fmt, ...)
{

A test/handlers/irc_recv.c.mock => test/handlers/irc_recv.c.mock +7 -0
@@ 0,0 1,7 @@
int
irc_recv(struct server *s, struct irc_message *m)
{
	UNUSED(s);
	UNUSED(m);
	return 0;
}

M test/handlers/irc_send.c => test/handlers/irc_send.c +6 -5
@@ 42,7 42,7 @@ static struct channel *c_priv;
static struct channel *c_serv;
static struct server *s;

/* Mock stat.c */
/* Mock state.c */
void
newlinef(struct channel *c, enum buffer_line_t t, const char *f, const char *fmt, ...)
{


@@ 184,6 184,7 @@ test_send_ctcp_ping(void)
	char m3[] = "ctcp-ping";
	char m4[] = "ctcp-ping targ";

	char *saveptr;
	char *p1;
	char *p2;



@@ 201,8 202,8 @@ test_send_ctcp_ping(void)
	*p1++ = 0;
	*p2++ = 0;

	assert_true((getarg(&p1, " ") != NULL));
	assert_true((getarg(&p1, " ") != NULL));
	assert_true((strtok_r(p1, " ", &saveptr)));
	assert_true((strtok_r(NULL, " ", &saveptr)));

	assert_strcmp(fail_buf, "");
	assert_strcmp(send_buf, "PRIVMSG priv :");


@@ 218,8 219,8 @@ test_send_ctcp_ping(void)
	*p1++ = 0;
	*p2++ = 0;

	assert_true((getarg(&p1, " ") != NULL));
	assert_true((getarg(&p1, " ") != NULL));
	assert_true((strtok_r(p1, " ", &saveptr)));
	assert_true((strtok_r(NULL, " ", &saveptr)));

	assert_strcmp(fail_buf, "");
	assert_strcmp(send_buf, "PRIVMSG targ :");

A test/handlers/irc_send.c.mock => test/handlers/irc_send.c.mock +17 -0
@@ 0,0 1,17 @@
int
irc_send_command(struct server *s, struct channel *c, char *m)
{
	UNUSED(s);
	UNUSED(c);
	UNUSED(m);
	return 0;
}

int
irc_send_privmsg(struct server *s, struct channel *c, char *m)
{
	UNUSED(s);
	UNUSED(c);
	UNUSED(m);
	return 0;
}

A test/io.c.mock => test/io.c.mock +16 -0
@@ 0,0 1,16 @@
struct connection*
connection(const void *o, const char *h, const char *p)
{
	UNUSED(o);
	UNUSED(h);
	UNUSED(p);
	return NULL;
}
const char* io_err(int err) { UNUSED(err); return "err"; }
int io_cx(struct connection *c) { UNUSED(c); return 0; }
int io_dx(struct connection *c) { UNUSED(c); return 0; }
int io_sendf(struct connection *c, const char *f, ...) { UNUSED(c); UNUSED(f); return 0; }
unsigned io_tty_cols(void) { return 0; }
unsigned io_tty_rows(void) { return 0; }
void io_free(struct connection *c) { UNUSED(c); }
void io_term(void) { ; }

M test/rirc.c => test/rirc.c +4 -45
@@ 1,7 1,5 @@
#include "test/test.h"

/* FIXME: decouple rirc.c and state.c, irc_send.c, irc_recv.c */

#include "src/components/buffer.c"
#include "src/components/channel.c"
#include "src/components/input.c"


@@ 12,49 10,10 @@
#include "src/state.c"
#include "src/utils/utils.c"

/* Mock draw.c */
void draw(union draw d) { UNUSED(d); }
void draw_bell(void) { ; }
void draw_term(void) { ; }
void
split_buffer_cols(
	struct buffer_line *l,
	unsigned int *h,
	unsigned int *t,
	unsigned int c,
	unsigned int p)
{
	UNUSED(l);
	UNUSED(h);
	UNUSED(t);
	UNUSED(c);
	UNUSED(p);
}

/* Mock io.c */
struct connection*
connection(const void *o, const char *h, const char *p)
{
	UNUSED(o);
	UNUSED(h);
	UNUSED(p);
	return NULL;
}
const char* io_err(int err) { UNUSED(err); return "err"; }
int io_cx(struct connection *c) { UNUSED(c); return 0; }
int io_dx(struct connection *c) { UNUSED(c); return 0; }
int io_sendf(struct connection *c, const char *f, ...) { UNUSED(c); UNUSED(f); return 0; }
unsigned io_tty_cols(void) { return 0; }
unsigned io_tty_rows(void) { return 0; }
void io_free(struct connection *c) { UNUSED(c); }
void io_term(void) { ; }

/* Mock handlers/irc_send.c */
int irc_send_command(struct server *s, struct channel *c, char *m) { UNUSED(s); UNUSED(c); UNUSED(m); return 0; }
int irc_send_privmsg(struct server *s, struct channel *c, char *m) { UNUSED(s); UNUSED(c); UNUSED(m); return 0; }

/* Mock handlers/irc_recv.c */
int irc_recv(struct server *s, struct irc_message *m) { UNUSED(s); UNUSED(m); return 0; }
#include "test/draw.c.mock"
#include "test/io.c.mock"
#include "test/handlers/irc_recv.c.mock"
#include "test/handlers/irc_send.c.mock"

static void
test_STUB(void)

A test/rirc.c.mock => test/rirc.c.mock +2 -0
@@ 0,0 1,2 @@
const char *default_username = "username";
const char *default_realname = "realname";

M test/state.c => test/state.c +4 -43
@@ 10,49 10,10 @@
#include "src/state.c"
#include "src/utils/utils.c"

/* Mock rirc.c */
const char *default_username = "username";
const char *default_realname = "realname";

/* Mock draw.c */
void draw(union draw d) { UNUSED(d); }
void draw_bell(void) { ; }
void draw_term(void) { ; }
void
split_buffer_cols(
	struct buffer_line *l,
	unsigned int *h,
	unsigned int *t,
	unsigned int c,
	unsigned int p)
{
	UNUSED(l);
	UNUSED(h);
	UNUSED(t);
	UNUSED(c);
	UNUSED(p);
}

/* Mock io.c */
struct connection*
connection(const void *o, const char *h, const char *p)
{
	UNUSED(o);
	UNUSED(h);
	UNUSED(p);
	return NULL;
}
const char* io_err(int err) { UNUSED(err); return "err"; }
int io_cx(struct connection *c) { UNUSED(c); return 0; }
int io_dx(struct connection *c) { UNUSED(c); return 0; }
int io_sendf(struct connection *c, const char *f, ...) { UNUSED(c); UNUSED(f); return 0; }
unsigned io_tty_cols(void) { return 0; }
unsigned io_tty_rows(void) { return 0; }
void io_free(struct connection *c) { UNUSED(c); }
void io_term(void) { ; }

/* Mock handlers/irc_recv.c */
int irc_recv(struct server *s, struct irc_message *m) { UNUSED(s); UNUSED(m); return 0; }
#include "test/draw.c.mock"
#include "test/io.c.mock"
#include "test/rirc.c.mock"
#include "test/handlers/irc_recv.c.mock"

#define INP_S(S) io_cb_read_inp((S), strlen(S))
#define INP_C(C) io_cb_read_inp((char[]){(C)}, 1)

M test/test.h => test/test.h +2 -2
@@ 122,13 122,13 @@ static void _print_testcase_name_(const char*);

#define assert_true(X) \
	do { \
		if ((X) == 0) \
		if (!(X)) \
			fail_test(#X " expected true"); \
	} while (0)

#define assert_false(X) \
	do { \
		if ((X) != 0) \
		if ((X)) \
			fail_test(#X " expected false"); \
	} while (0)