Tidy C test plugin

This commit is contained in:
James Booth
2016-03-26 01:04:46 +00:00
parent 0503ca12cf
commit 26957ffa03
2 changed files with 296 additions and 242 deletions

View File

@@ -44,7 +44,10 @@ def _consshow_t(group, key, dflt, msg):
_create_win() _create_win()
prof.win_focus(plugin_win) prof.win_focus(plugin_win)
prof.cons_show_themed(group, key, dflt, msg) groupval = None if group == "none" else group
keyval = None if key == "none" else key
dfltval = None if dflt == "none" else dflt
prof.cons_show_themed(groupval, keyval, dfltval, msg)
prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg) prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg)
def _constest(): def _constest():
@@ -73,7 +76,10 @@ def _winshow_t(group, key, dflt, msg):
_create_win() _create_win()
prof.win_focus(plugin_win) prof.win_focus(plugin_win)
prof.win_show_themed(plugin_win, group, key, dflt, msg) groupval = None if group == "none" else group
keyval = None if key == "none" else key
dfltval = None if dflt == "none" else dflt
prof.win_show_themed(plugin_win, groupval, keyval, dfltval, msg)
prof.win_show(plugin_win, "called -> prof_win_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg) prof.win_show(plugin_win, "called -> prof_win_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg)
def _sendline(line): def _sendline(line):

View File

@@ -40,42 +40,52 @@ create_win(void)
} }
void void
cmd_ctest(char **args) consalert(void)
{ {
if (strcmp(args[0], "consalert") == 0) {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_cons_alert(); prof_cons_alert();
prof_win_show(plugin_win, "called -> prof_cons_alert"); prof_win_show(plugin_win, "called -> prof_cons_alert");
} else if (strcmp(args[0], "consshow") == 0) { }
if (args[1]) {
void
consshow(char *msg)
{
if (msg == NULL) {
prof_cons_bad_cmd_usage("/c-test");
return;
}
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_cons_show(args[1]); prof_cons_show(msg);
char *str = "called -> prof_cons_show: "; char *str = "called -> prof_cons_show: ";
char buf[strlen(str) + strlen(args[1])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[1]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else { }
void
consshow_t(char *group, char *key, char *def, char *msg)
{
if (group == NULL || key == NULL || def == NULL || msg == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "consshow_t") == 0) {
if (args[1] == NULL || args[2] == NULL || args[3] == NULL || args[4] == NULL) {
prof_cons_bad_cmd_usage("/c-test");
} else {
char *group = strcmp(args[1], "none") == 0 ? NULL : args[1];
char *key = strcmp(args[2], "none") == 0 ? NULL : args[2];
char *def = strcmp(args[3], "none") == 0 ? NULL : args[3];
char *message = args[4];
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_cons_show_themed(group, key, def, message); char *groupval = strcmp(group, "none") == 0 ? NULL : group;
char *keyval = strcmp(key, "none") == 0 ? NULL : key;
char *defval = strcmp(def, "none") == 0 ? NULL : def;
prof_cons_show_themed(groupval, keyval, defval, msg);
char *str = "called -> prof_cons_show_themed: "; char *str = "called -> prof_cons_show_themed: ";
char buf[strlen(str) + strlen(args[1]) + 2 + strlen(args[2]) + 2 + strlen(args[3]) + 2 + strlen(args[4])]; char buf[strlen(str) + strlen(group) + 2 + strlen(key) + 2 + strlen(def) + 2 + strlen(msg)];
sprintf(buf, "%s%s, %s, %s, %s", str, args[1], args[2], args[3], args[4]); sprintf(buf, "%s%s, %s, %s, %s", str, group, key, def, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
} else if (strcmp(args[0], "constest") == 0) {
void
constest(void)
{
int res = prof_current_win_is_console(); int res = prof_current_win_is_console();
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
@@ -84,62 +94,84 @@ cmd_ctest(char **args)
} else { } else {
prof_win_show(plugin_win, "called -> prof_current_win_is_console: false"); prof_win_show(plugin_win, "called -> prof_current_win_is_console: false");
} }
} else if (strcmp(args[0], "winshow") == 0) { }
if (args[1]) {
void
winshow(char *msg)
{
if (msg == NULL) {
prof_cons_bad_cmd_usage("/c-test");
return;
}
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_win_show(plugin_win, args[1]); prof_win_show(plugin_win, msg);
char *str = "called -> prof_win_show: "; char *str = "called -> prof_win_show: ";
char buf[strlen(str) + strlen(args[1])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[1]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else { }
void
winshow_t(char *group, char *key, char *def, char *msg)
{
if (group == NULL || key == NULL || def == NULL || msg == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "winshow_t") == 0) {
if (args[1] == NULL || args[2] == NULL || args[3] == NULL || args[4] == NULL) {
prof_cons_bad_cmd_usage("/c-test");
} else {
char *group = strcmp(args[1], "none") == 0 ? NULL : args[1];
char *key = strcmp(args[2], "none") == 0 ? NULL : args[2];
char *def = strcmp(args[3], "none") == 0 ? NULL : args[3];
char *message = args[4];
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_win_show_themed(plugin_win, group, key, def, message); char *groupval = strcmp(group, "none") == 0 ? NULL : group;
char *keyval = strcmp(key, "none") == 0 ? NULL : key;
char *defval = strcmp(def, "none") == 0 ? NULL : def;
prof_win_show_themed(plugin_win, groupval, keyval, defval, msg);
char *str = "called -> prof_win_show_themed: "; char *str = "called -> prof_win_show_themed: ";
char buf[strlen(str) + strlen(args[1]) + 2 + strlen(args[2]) + 2 + strlen(args[3]) + 2 + strlen(args[4])]; char buf[strlen(str) + strlen(group) + 2 + strlen(key) + 2 + strlen(def) + 2 + strlen(msg)];
sprintf(buf, "%s%s, %s, %s, %s", str, args[1], args[2], args[3], args[4]); sprintf(buf, "%s%s, %s, %s, %s", str, group, key, def, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
}
void
sendline(char *line)
{
if (line == NULL) {
prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "sendline") == 0) {
if (args[1]) {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_send_line(args[1]); prof_send_line(line);
char *str = "called -> prof_send_line: "; char *str = "called -> prof_send_line: ";
char buf[strlen(str) + strlen(args[1])]; char buf[strlen(str) + strlen(line)];
sprintf(buf, "%s%s", str, args[1]); sprintf(buf, "%s%s", str, line);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else { }
void
donotify(char *msg)
{
if (msg == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "notify") == 0) {
if (args[1]) {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_notify(args[1], 5000, "c-test plugin"); prof_notify(msg, 5000, "c-test plugin");
char *str = "called -> prof_notify: "; char *str = "called -> prof_notify: ";
char buf[strlen(str) + strlen(args[1])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[1]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else { }
void
getsubject(char *subject)
{
if (subject == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "get") == 0) {
if (!args[1]) { if (strcmp(subject, "recipient") == 0) {
prof_cons_bad_cmd_usage("/c-test");
} else if (strcmp(args[1], "recipient") == 0) {
create_win(); create_win();
char *recipient = prof_get_current_recipient(); char *recipient = prof_get_current_recipient();
if (recipient) { if (recipient) {
@@ -152,7 +184,7 @@ cmd_ctest(char **args)
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_win_show(plugin_win, "called -> prof_get_current_recipient: <none>"); prof_win_show(plugin_win, "called -> prof_get_current_recipient: <none>");
} }
} else if (strcmp(args[1], "room") == 0) { } else if (strcmp(subject, "room") == 0) {
create_win(); create_win();
char *room = prof_get_current_muc(); char *room = prof_get_current_muc();
if (room) { if (room) {
@@ -168,70 +200,70 @@ cmd_ctest(char **args)
} else { } else {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} }
} else if (strcmp(args[0], "log") == 0) { }
if (!args[1]) {
void
logmsg(char *level, char *msg)
{
if (level == NULL || msg == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} else if (strcmp(args[1], "debug") == 0) { return;
if (!args[2]) { }
prof_cons_bad_cmd_usage("/c-test");
} else { if (strcmp(level, "debug") == 0) {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_log_debug(args[2]); prof_log_debug(msg);
char *str = "called -> prof_log_debug: "; char *str = "called -> prof_log_debug: ";
char buf[strlen(str) + strlen(args[2])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[2]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} } else if (strcmp(level, "info") == 0) {
} else if (strcmp(args[1], "info") == 0) {
if (!args[2]) {
prof_cons_bad_cmd_usage("/c-test");
} else {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_log_info(args[2]); prof_log_info(msg);
char *str = "called -> prof_log_info: "; char *str = "called -> prof_log_info: ";
char buf[strlen(str) + strlen(args[2])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[2]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} } else if (strcmp(level, "warning") == 0) {
} else if (strcmp(args[1], "warning") == 0) {
if (!args[2]) {
prof_cons_bad_cmd_usage("/c-test");
} else {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_log_warning(args[2]); prof_log_warning(msg);
char *str = "called -> prof_log_warning: "; char *str = "called -> prof_log_warning: ";
char buf[strlen(str) + strlen(args[2])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[2]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} } else if (strcmp(level, "error") == 0) {
} else if (strcmp(args[1], "error") == 0) {
if (!args[2]) {
prof_cons_bad_cmd_usage("/c-test");
} else {
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_log_error(args[2]); prof_log_error(msg);
char *str = "called -> prof_log_error: "; char *str = "called -> prof_log_error: ";
char buf[strlen(str) + strlen(args[2])]; char buf[strlen(str) + strlen(msg)];
sprintf(buf, "%s%s", str, args[2]); sprintf(buf, "%s%s", str, msg);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
}
} else { } else {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} }
} else if (strcmp(args[0], "count") == 0) { }
void
docount(void)
{
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
char buf[100]; char buf[100];
sprintf(buf, "Count: %d", count); sprintf(buf, "Count: %d", count);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else if (strcmp(args[0], "ping") == 0) { }
if (args[1] == NULL) {
void
doping(char *jid)
{
if (jid == NULL) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} else { return;
}
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
char *strstart = "<iq to='"; char *strstart = "<iq to='";
@@ -239,8 +271,8 @@ cmd_ctest(char **args)
char *idstart = "' id='cplugin-"; char *idstart = "' id='cplugin-";
char idbuf[strlen(idstart) + 10]; char idbuf[strlen(idstart) + 10];
sprintf(idbuf, "%s%d", idstart, ping_id); sprintf(idbuf, "%s%d", idstart, ping_id);
char buf[strlen(strstart) + strlen(args[1]) + strlen(idbuf) + strlen(strend)]; char buf[strlen(strstart) + strlen(jid) + strlen(idbuf) + strlen(strend)];
sprintf(buf, "%s%s%s%s", strstart, args[1], idbuf, strend); sprintf(buf, "%s%s%s%s", strstart, jid, idbuf, strend);
int res = prof_send_stanza(buf); int res = prof_send_stanza(buf);
ping_id++; ping_id++;
if (res) { if (res) {
@@ -248,16 +280,27 @@ cmd_ctest(char **args)
} else { } else {
prof_win_show(plugin_win, "Error sending ping"); prof_win_show(plugin_win, "Error sending ping");
} }
}
void
booleansetting(char *op, char *group, char *key, char *value_str)
{
if (op == NULL || group == NULL || key == NULL) {
prof_cons_bad_cmd_usage("/c-test");
return;
} }
} else if (strcmp(args[0], "boolean") == 0) {
if (args[1] == NULL) { if ((strcmp(op, "get") != 0) && (strcmp(op, "set") != 0)) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} else if (strcmp(args[1], "get") == 0) { return;
if (args[2] == NULL || args[3] == NULL) { }
if ((strcmp(op, "set") == 0) && (strcmp(value_str, "true") != 0) && (strcmp(value_str, "false") != 0)) {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} else { return;
char *group = args[2]; }
char *key = args[3];
if (strcmp(op, "get") == 0) {
int dflt = 0; int dflt = 0;
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
@@ -267,36 +310,41 @@ cmd_ctest(char **args)
} else { } else {
prof_win_show(plugin_win, "Boolean setting: FALSE"); prof_win_show(plugin_win, "Boolean setting: FALSE");
} }
} } else if (strcmp(op, "set") == 0) {
} else if (strcmp(args[1], "set") == 0) {
if (args[2] == NULL || args[3] == NULL || args[4] == NULL) {
prof_cons_bad_cmd_usage("/c-test");
} else {
char *group = args[2];
char *key = args[3];
if ((strcmp(args[4], "true") != 0) && (strcmp(args[4], "false") != 0)) {
prof_cons_bad_cmd_usage("/c-test");
} else {
int value = 0; int value = 0;
if (strcmp(args[4], "true") == 0) { if (strcmp(value_str, "true") == 0) {
value = 1; value = 1;
} }
create_win(); create_win();
prof_win_focus(plugin_win); prof_win_focus(plugin_win);
prof_settings_set_boolean(group, key, value); prof_settings_set_boolean(group, key, value);
char buf[5 + strlen(group) + 2 + strlen(key) + 4 + strlen(args[4])]; char buf[5 + strlen(group) + 2 + strlen(key) + 4 + strlen(value_str)];
sprintf(buf, "Set [%s] %s to %s", group, key, args[4]); sprintf(buf, "Set [%s] %s to %s", group, key, value_str);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
}
}
} else {
prof_cons_bad_cmd_usage("/c-test");
}
} else { } else {
prof_cons_bad_cmd_usage("/c-test"); prof_cons_bad_cmd_usage("/c-test");
} }
} }
void
cmd_ctest(char **args)
{
if (strcmp(args[0], "consalert") == 0) consalert();
else if (strcmp(args[0], "consshow") == 0) consshow(args[1]);
else if (strcmp(args[0], "consshow_t") == 0) consshow_t(args[1], args[2], args[3], args[4]);
else if (strcmp(args[0], "constest") == 0) constest();
else if (strcmp(args[0], "winshow") == 0) winshow(args[1]);
else if (strcmp(args[0], "winshow_t") == 0) winshow_t(args[1], args[2], args[3], args[4]);
else if (strcmp(args[0], "sendline") == 0) sendline(args[1]);
else if (strcmp(args[0], "notify") == 0) donotify(args[1]);
else if (strcmp(args[0], "get") == 0) getsubject(args[1]);
else if (strcmp(args[0], "log") == 0) logmsg(args[1], args[2]);
else if (strcmp(args[0], "count") == 0) docount();
else if (strcmp(args[0], "ping") == 0) doping(args[1]);
else if (strcmp(args[0], "boolean") == 0) booleansetting(args[1], args[2], args[3], args[4]);
else prof_cons_bad_cmd_usage("/c-test");
}
void void
timed_callback(void) timed_callback(void)
{ {