diff --git a/tests/python-test.py b/tests/python-test.py index 72850a0..fb7eba5 100644 --- a/tests/python-test.py +++ b/tests/python-test.py @@ -293,7 +293,7 @@ def _string_list(op, group, key, value): prof.settings_string_list_add(group, key, value) prof.win_focus(plugin_win) prof.win_show(plugin_win, "Added '" + value + "' to [" + group + "]" + " " + key) - + return if op == "remove": if group == None or key == None or value == None: @@ -302,17 +302,22 @@ def _string_list(op, group, key, value): res = prof.settings_string_list_remove(group, key, value) prof.win_focus(plugin_win) if res: - prof.win_show(plugin_win, "Removed '" + value + "' to [" + group + "]" + " " + key) + prof.win_show(plugin_win, "Removed '" + value + "' from [" + group + "]" + " " + key) else: prof.win_show(plugin_win, "Error removing string item from list") + return; if op == "remove_all": if group == None or key == None: prof.cons_bad_cmd_usage("/python-test") return - prof.settings_string_list_remove_all(group, key) + res = prof.settings_string_list_remove_all(group, key) prof.win_focus(plugin_win) - prof.win_show(plugin_win, "Removed all items from [" + group + "]" + " " + key) + if res: + prof.win_show(plugin_win, "Removed all items from [" + group + "]" + " " + key) + else: + prof.win_show(plugin_win, "Error removing list") + return def _int(op, group, key, value): diff --git a/tests/test-c-plugin/test-c-plugin.c b/tests/test-c-plugin/test-c-plugin.c index 4cdaa03..ec13e19 100644 --- a/tests/test-c-plugin/test-c-plugin.c +++ b/tests/test-c-plugin/test-c-plugin.c @@ -383,6 +383,87 @@ stringsetting(char *op, char *group, char *key, char *value) } } +void +stringlistsetting(char *op, char *group, char *key, char *value) +{ + if ((strcmp(op, "get") != 0) && (strcmp(op, "add") != 0) && (strcmp(op, "remove") != 0) && (strcmp(op, "remove_all") != 0)) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + + if (strcmp(op, "get") == 0) { + if (group == NULL || key == NULL) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + char** res = prof_settings_get_string_list(group, key); + prof_win_focus(plugin_win); + if (res == NULL) { + prof_win_show(plugin_win, "No list found"); + return; + } + prof_win_show(plugin_win, "String list:"); + int i = 0; + while (res[i] != NULL) { + char buf[2 + strlen(res[i]) + 1]; + sprintf(buf, " %s", res[i]); + prof_win_show(plugin_win, buf); + i++; + } + return; + } + + if (strcmp(op, "add") == 0) { + if (group == NULL || key == NULL || value == NULL) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + prof_settings_string_list_add(group, key, value); + prof_win_focus(plugin_win); + char buf[7 + strlen(value) + 6 + strlen(group) + 2 + strlen(key) + 1]; + sprintf(buf, "Added '%s' to [%s] %s", value, group, key); + prof_win_show(plugin_win, buf); + return; + } + + if (strcmp(op, "remove") == 0) { + if (group == NULL || key == NULL || value == NULL) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + int res = prof_settings_string_list_remove(group, key, value); + prof_win_focus(plugin_win); + if (res) { + char buf[9 + strlen(value) + 8 + strlen(group) + 2 + strlen(key) + 1]; + sprintf(buf, "Removed '%s' from [%s] %s", value, group, key); + prof_win_show(plugin_win, buf); + } else { + prof_win_show(plugin_win, "Error removing string item from list"); + } + return; + } + + if (strcmp(op, "remove_all") == 0) { + if (group == NULL || key == NULL) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + int res = prof_settings_string_list_remove_all(group, key); + prof_win_focus(plugin_win); + if (res) { + char buf[24 + strlen(group) + 2 + strlen(key) + 1]; + sprintf(buf, "Removed all items from [%s] %s", group, key); + prof_win_show(plugin_win, buf); + } else { + prof_win_show(plugin_win, "Error removing list"); + } + return; + } + + return; +} + + void intsetting(char *op, char *group, char *key, char *value) { @@ -468,6 +549,7 @@ cmd_ctest(char **args) 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 if (strcmp(args[0], "string") == 0) stringsetting(args[1], args[2], args[3], args[4]); + else if (strcmp(args[0], "string_list") == 0) stringlistsetting(args[1], args[2], args[3], args[4]); else if (strcmp(args[0], "int") == 0) intsetting(args[1], args[2], args[3], args[4]); else if (strcmp(args[0], "incoming") == 0) incomingmsg(args[1], args[2], args[3]); else if (strcmp(args[0], "completer") == 0) completer(args[1], args[2]); @@ -515,6 +597,10 @@ prof_init(const char * const version, const char * const status, const char *con "/c-test boolean set ", "/c-test string get ", "/c-test string set ", + "/c-test-test string_list get ", + "/c-test string_list add ", + "/c-test string_list remove ", + "/c-test string_list remove_all ", "/c-test int get ", "/c-test int set ", "/c-test incoming ", @@ -542,6 +628,10 @@ prof_init(const char * const version, const char * const status, const char *con { "boolean set ", "Set a boolean setting" }, { "string get ", "Get a string setting" }, { "string set ", "Set a string setting" }, + { "string_list get ", "Get a string list setting" }, + { "string_list add ", "Add a string to a string list setting" }, + { "string_list remove ", "Remove a string from a string list setting" }, + { "string_list remove_all ", "Remove all strings from a string list setting" }, { "int get ", "Get a integer setting" }, { "int set ", "Set a integer setting" }, { "incoming ", "Show an incoming message." }, @@ -576,6 +666,7 @@ prof_init(const char * const version, const char * const status, const char *con "ping", "boolean", "string", + "string_list", "int", "incoming", "completer", @@ -595,6 +686,9 @@ prof_init(const char * const version, const char * const status, const char *con char *string_ac[] = { "get", "set", NULL }; prof_completer_add("/c-test string", string_ac); + char *stringlist_ac[] = { "get", "add", "remove", "remove_all", NULL }; + prof_completer_add("/c-test string_list", stringlist_ac); + char *int_ac[] = { "get", "set", NULL }; prof_completer_add("/c-test int", int_ac);