Moved test plugins to folder, removed connect plugin

This commit is contained in:
James Booth
2014-06-11 21:42:19 +01:00
parent 2cf98ce8c4
commit 751c59e8b3
7 changed files with 0 additions and 10 deletions

116
tests/RubyTest.rb Normal file
View File

@@ -0,0 +1,116 @@
module RubyTest
def self.prof_init(version, status)
Prof::cons_show("RubyTest: init, " + version + ", " + status)
Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby)
Prof::register_command("/lower", 0, 1, "/lower", "Lowercase input string", "Lowercase input string", cmd_lower)
Prof::register_timed(timer_test, 10)
end
def self.prof_on_start()
Prof::cons_show("RubyTest: on_start")
Prof::log_debug("RubyTest: logged debug");
Prof::log_info("RubyTest: logged info");
Prof::log_warning("RubyTest: logged warning");
Prof::log_error("RubyTest: logged error");
end
def self.prof_on_connect(account_name, fulljid)
Prof::cons_show("RubyTest: on_connect, " + account_name + ", " + fulljid)
end
def self.prof_on_disconnect(account_name, fulljid)
Prof::cons_show("RubyTest: on_disconnect, " + account_name + ", " + fulljid)
Prof::log_info("RubyTest: on_disconnect, " + account_name + ", " + fulljid)
end
def self.prof_on_message_received(jid, message)
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_room_message_received(room, nick, message)
Prof::cons_show("RubyTest: on_room_message_received, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_private_message_received(room, nick, message)
Prof::cons_show("RubyTest: on_private_message_received, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_message_send(jid, message)
Prof::cons_show("RubyTest: on_message_send, " + jid + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_private_message_send(room, nick, message)
Prof::cons_show("RubyTest: on_private_message_send, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_room_message_send(room, message)
Prof::cons_show("RubyTest: on_room_message_send, " + room + ", " + message)
Prof::cons_alert
return message + "[RUBY]"
end
def self.prof_on_shutdown()
Prof::log_info("RubyTest: on_shutdown");
end
def self.cmd_ruby()
return Proc.new { | msg |
if msg
Prof::cons_show("RubyTest: /ruby command called, arg = " + msg)
else
Prof::cons_show("RubyTest: /ruby command called with no arg")
end
Prof::cons_alert
Prof::notify("RubyTest: notify", 2000, "Plugins")
Prof::send_line("/help")
Prof::cons_show("RubyTest: sent \"/help\" command")
}
end
def self.timer_test()
return Proc.new {
Prof::cons_show("RubyTest: timer fired.")
recipient = Prof::get_current_recipient
if recipient
Prof::cons_show(" current recipient = " + recipient)
end
Prof::cons_alert
}
end
def self.cmd_lower()
return Proc.new { | line |
win_tag = "Lower echo"
if (Prof::win_exists(win_tag) == false)
Prof::win_create(win_tag, handle_lower)
end
Prof::win_focus(win_tag)
if (line)
handle_lower.call(win_tag, line)
end
}
end
def self.handle_lower()
return Proc.new { | win, line |
Prof::win_show(win, line.downcase)
Prof::win_show_red(win, "Red")
Prof::win_show_yellow(win, "Yellow")
Prof::win_show_green(win, "Green")
Prof::win_show_cyan(win, "Cyan")
}
end
end

109
tests/luatest.lua Normal file
View File

@@ -0,0 +1,109 @@
local luatest = {}
local function cmd_lua(msg)
if msg then
prof_cons_show("luatest: /lua command called, arg = " .. msg)
else
prof_cons_show("luatest: /lua command called with no arg")
end
prof_cons_alert()
prof_notify("luatest: notify", 8000, "Plugins")
prof_send_line("/account list")
prof_cons_show("luatest: sent \"/account list\" command")
end
local function timer_test()
prof_cons_show("luatest: timer fired.")
recipient = prof_get_current_recipient()
if recipient then
prof_cons_show(" current recipient = " .. recipient)
end
prof_cons_alert()
end
local function handle_bracket(win, line)
prof_win_show(win, "(" .. line .. ")")
prof_win_show_red(win, "Red")
prof_win_show_yellow(win, "Yellow")
prof_win_show_green(win, "Green")
prof_win_show_cyan(win, "Cyan")
end
local function cmd_bracket(line)
win_tag = "Parenthesise echo";
if prof_win_exists(win_tag) == false then
prof_win_create(win_tag, handle_bracket);
end
prof_win_focus(win_tag);
if line then
handle_bracket(win_tag, line)
end
end
function luatest.prof_init(version, status)
prof_cons_show("luatest: init, " .. version .. ", " .. status)
prof_register_command("/lua", 0, 1, "/lua", "luatest", "luatest", cmd_lua)
prof_register_command("/bracket", 0, 1, "/bracket", "Parenthesise input string", "Parenthesise input string", cmd_bracket);
prof_register_timed(timer_test, 10)
end
function luatest.prof_on_start()
prof_cons_show("luatest: on_start")
prof_log_debug("luatest: logged debug");
prof_log_info("luatest: logged info");
prof_log_warning("luatest: logged warning");
prof_log_error("luatest: logged error");
end
function luatest.prof_on_connect(account_name, fulljid)
prof_cons_show("luatest: on_connect, " .. account_name .. ", " .. fulljid)
end
function luatest.prof_on_disconnect(account_name, fulljid)
prof_cons_show("luatest: on_disconnect, " .. account_name .. ", " .. fulljid)
prof_log_info("luatest: on_disconnect, " .. account_name .. ", " .. fulljid)
end
function luatest.prof_on_message_received(jid, message)
prof_cons_show("luatest: on_message_received, " .. jid .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_room_message_received(room, nick, message)
prof_cons_show("luatest: on_room_message_received, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_private_message_received(room, nick, message)
prof_cons_show("luatest: on_private_message_received, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_message_send(jid, message)
prof_cons_show("luatest: on_message_send, " .. jid .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_private_message_send(room, nick, message)
prof_cons_show("luatest: on_private_message_send, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_room_message_send(room, message)
prof_cons_show("luatest: on_room_message_send, " .. room .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_shutdown()
prof_log_info("luatest: on_shutdown")
end
return luatest

90
tests/python-test.py Normal file
View File

@@ -0,0 +1,90 @@
import prof
_win_tag = "Upper echo";
def _cmd_python(msg):
if msg:
prof.cons_show("python-test: /python command called, arg = " + msg)
else:
prof.cons_show("python-test: /python command called with no arg")
prof.cons_alert()
prof.notify("python-test: notify", 2000, "Plugins")
prof.send_line("/vercheck")
prof.cons_show("python-test: sent \"/vercheck\" command")
def _timer_test():
prof.cons_show("python-test: timer fired.")
recipient = prof.get_current_recipient()
if recipient:
prof.cons_show(" current recipient = " + recipient)
prof.cons_alert()
def _cmd_upper(line):
global _win_tag;
if prof.win_exists(_win_tag) == False:
prof.win_create(_win_tag, _handle_upper)
prof.win_focus(_win_tag)
if line:
_handle_upper(_win_tag, line)
def _handle_upper(win, line):
prof.win_show(win, line.upper())
prof.win_show_red(win, "Red")
prof.win_show_yellow(win, "Yellow")
prof.win_show_green(win, "Green")
prof.win_show_cyan(win, "Cyan")
def prof_init(version, status):
prof.cons_show("python-test: init, " + version + ", " + status)
prof.register_command("/python", 0, 1, "/python", "python-test", "python-test", _cmd_python)
prof.register_command("/upper", 0, 1, "/upper", "Uppercase input string", "Uppercase input string", _cmd_upper)
prof.register_timed(_timer_test, 10)
def prof_on_start():
prof.cons_show("python-test: on_start")
prof.log_debug("python-test: logged debug")
prof.log_info("python-test: logged info")
prof.log_warning("python-test: logged warning")
prof.log_error("python-test: logged error")
def prof_on_connect(account_name, fulljid):
prof.cons_show("python-test: on_connect, " + account_name + ", " + fulljid)
def prof_on_disconnect(account_name, fulljid):
prof.cons_show("python-test: on_disconnect, " + account_name + ", " + fulljid)
prof.log_info("python-test: on_disconnect, " + account_name + ", " + fulljid)
def prof_on_message_received(jid, message):
prof.cons_show("python-test: on_message_received, " + jid + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_room_message_received(room, nick, message):
prof.cons_show("python-test: on_room_message_received, " + room + ", " + nick + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_private_message_received(room, nick, message):
prof.cons_show("python-test: on_private_message_received, " + room + ", " + nick + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_message_send(jid, message):
prof.cons_show("python-test: on_message_send, " + jid + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_private_message_send(room, nick, message):
prof.cons_show("python-test: on_private_message_send, " + room + ", " + nick + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_room_message_send(room, message):
prof.cons_show("python-test: on_room_message_send, " + room + ", " + message)
prof.cons_alert()
return message + "[PYTHON]"
def prof_on_shutdown():
prof.log_info("python-test: on_shutdown")

21
tests/python-thread.py Normal file
View File

@@ -0,0 +1,21 @@
import prof
import threading
import time
import sys
counter = 0
def _inc_counter():
global counter
while True:
time.sleep(1)
counter = counter + 1
def _cmd_count():
prof.cons_show("Counter: " + str(counter))
def prof_init(version, status):
t = threading.Thread(target=_inc_counter)
t.daemon = True
t.start()
prof.register_command("/count", 0, 0, "/count", "Threaded example", "Threaded example", _cmd_count)

View File

@@ -0,0 +1,18 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINK_FLAGS := -fno-common -flat_namespace -bundle -undefined suppress
else
LINK_FLAGS := -shared -fpic
endif
all: test-c-plugin.so
%.so:%.o
$(CC) $(LINK_FLAGS) -lprofanity -o $@ $^
%.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \
-Wall -Wextra -pedantic -c -o $@ $<
clean:
$(RM) test-c-plugin.so

View File

@@ -0,0 +1,205 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <profapi.h>
static PROF_WIN_TAG echo_win = "Reverse Echo";
void
cmd_c(char **args)
{
if (args[0] != NULL) {
char *start = "c-test: /c command called, arg = ";
char buf[strlen(start) + strlen(args[0]) + 1];
sprintf(buf, "%s%s", start, args[0]);
prof_cons_show(buf);
} else {
prof_cons_show("c-test: /c command called with no arg");
}
prof_cons_alert();
prof_notify("c-test: notify", 2000, "Plugins");
prof_send_line("/about");
prof_cons_show("c-test: sent \"/about\" command");
}
void
timer_test(void)
{
prof_cons_show("c-test: timer fired.");
char *recipient = prof_get_current_recipient();
if (recipient != NULL) {
char *start = " current recipient = ";
char buf[strlen(start) + strlen(recipient) + 1];
sprintf(buf, "%s%s", start, recipient);
prof_cons_show(buf);
}
prof_cons_alert();
}
void
handle_reverse(PROF_WIN_TAG win, char *line)
{
int len = strlen(line);
char buf[len];
int i = len;
int pos = 0;
for (i = len-1; i >= 0; i--) {
buf[pos] = line[i];
pos++;
}
buf[pos] = '\0';
prof_win_show(win, buf);
prof_win_show_red(win, "Red");
prof_win_show_yellow(win, "Yellow");
prof_win_show_green(win, "Green");
prof_win_show_cyan(win, "Cyan");
}
void
cmd_reverse(char **args)
{
if (!prof_win_exists(echo_win)) {
prof_win_create(echo_win, handle_reverse);
}
prof_win_focus(echo_win);
if (args[0] != NULL) {
handle_reverse(echo_win, args[0]);
}
}
void
prof_init(const char * const version, const char * const status)
{
char *start = "c-test: init. ";
char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1];
sprintf(buf, "%s%s, %s", start, version, status);
prof_cons_show(buf);
prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c);
prof_register_command("/reverse", 0, 1, "/reverse", "Reverse input string", "Reverse input string", cmd_reverse);
prof_register_timed(timer_test, 10);
}
void
prof_on_start(void)
{
prof_cons_show("c-test: on_start");
prof_log_debug("c-test: logged debug");
prof_log_info("c-test: logged info");
prof_log_warning("c-test: logged warning");
prof_log_error("c-test: logged error");
}
void
prof_on_connect(const char * const account_name, const char * const fulljid)
{
char *start = "c-test: on_connect, ";
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
sprintf(buf, "%s%s, %s", start, account_name, fulljid);
prof_cons_show(buf);
}
void
prof_on_disconnect(const char * const account_name, const char * const fulljid)
{
char *start = "c-test: on_disconnect, ";
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
sprintf(buf, "%s%s, %s", start, account_name, fulljid);
prof_cons_show(buf);
prof_log_info(buf);
}
char *
prof_on_message_received(const char * const jid, const char *message)
{
char *start = "c-test: on_message_received, ";
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, jid, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
char *
prof_on_room_message_received(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_room_message_received, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
char *
prof_on_private_message_received(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_private_message_received, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
char *
prof_on_message_send(const char * const jid, const char *message)
{
char *start = "c-test: on_message_send, ";
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, jid, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
char *
prof_on_private_message_send(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_private_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
char *
prof_on_room_message_send(const char * const room, const char *message)
{
char *start = "c-test: on_room_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, room, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result;
}
void
prof_on_shutdown(void)
{
prof_log_info("c-test: on_shutdown");
}