1
0
Fork 0

Fix tests, move glob creation

This commit is contained in:
James Booth 2018-01-27 23:51:03 +00:00
parent 2e414797a4
commit e571ccd8ea
10 changed files with 67 additions and 43 deletions

View File

@ -595,7 +595,7 @@ cmd_ac_init(void)
rooms_ac = autocomplete_new();
autocomplete_add(rooms_ac, "service");
autocomplete_add(rooms_ac, "match");
autocomplete_add(rooms_ac, "filter");
affiliation_ac = autocomplete_new();
autocomplete_add(affiliation_ac, "owner");

View File

@ -795,20 +795,21 @@ static struct cmd_t command_defs[] =
CMD_TAG_GROUPCHAT)
CMD_SYN(
"/rooms",
"/rooms match <glob>",
"/rooms filter <glob>",
"/rooms service <service>",
"/rooms service <service> match <glob>")
"/rooms service <service> filter <glob>")
CMD_DESC(
"List the chat rooms available at the specified conference service. "
"If no argument is supplied, the account preference 'muc.service' is used, 'conference.<domain-part>' by default. "
"The match argument accepts a glob and returns only room names that match.")
"The filter argument accepts a glob (including * and ?) and filters the results.")
CMD_ARGS(
{ "service <service>", "The conference service to query." },
{ "match <glob>", "The string to match before displaying results."})
{ "filter <glob>", "The glob to filter results by."})
CMD_EXAMPLES(
"/rooms",
"/rooms match *development*",
"/rooms service conference.jabber.org")
"/rooms filter *development*",
"/rooms service conference.jabber.org",
"/rooms service conference.jabber.org filter *xsf*")
},
{ "/bookmark",

View File

@ -4393,8 +4393,8 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
char *service = NULL;
char *match = NULL;
gchar *service = NULL;
gchar *filter = NULL;
if (args[0] != NULL) {
if (g_strcmp0(args[0], "service") == 0) {
if (args[1] == NULL) {
@ -4403,13 +4403,13 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
service = g_strdup(args[1]);
} else if (g_strcmp0(args[0], "match") == 0) {
} else if (g_strcmp0(args[0], "filter") == 0) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
cons_show("");
return TRUE;
}
match = g_strdup(args[1]);
filter = g_strdup(args[1]);
} else {
cons_bad_cmd_usage(command);
cons_show("");
@ -4422,21 +4422,21 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
cons_bad_cmd_usage(command);
cons_show("");
g_free(service);
g_free(match);
g_free(filter);
return TRUE;
}
g_free(service);
service = g_strdup(args[3]);
} else if (g_strcmp0(args[2], "match") == 0) {
} else if (g_strcmp0(args[2], "filter") == 0) {
if (args[3] == NULL) {
cons_bad_cmd_usage(command);
cons_show("");
g_free(service);
g_free(match);
g_free(filter);
return TRUE;
}
g_free(match);
match = g_strdup(args[3]);
g_free(filter);
filter = g_strdup(args[3]);
} else {
cons_bad_cmd_usage(command);
cons_show("");
@ -4444,12 +4444,6 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
}
}
GPatternSpec *glob = NULL;
if (match != NULL) {
glob = g_pattern_spec_new(match);
g_free(match);
}
if (service == NULL) {
ProfAccount *account = accounts_get_account(session_get_account_name());
if (account->muc_service) {
@ -4459,12 +4453,12 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
cons_show("Account MUC service property not found.");
account_free(account);
g_free(service);
g_free(match);
g_free(filter);
return TRUE;
}
}
iq_room_list_request(service, glob);
iq_room_list_request(service, filter);
g_free(service);

View File

@ -297,13 +297,13 @@ iq_set_autoping(const int seconds)
}
void
iq_room_list_request(gchar *conferencejid, GPatternSpec *glob)
iq_room_list_request(gchar *conferencejid, gchar *filter)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("confreq");
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, id, conferencejid);
iq_id_handler_add(id, _room_list_id_handler, (ProfIdFreeCallback)g_pattern_spec_free, glob);
iq_id_handler_add(id, _room_list_id_handler, NULL, filter);
iq_send_stanza(iq);
xmpp_stanza_release(iq);
@ -912,15 +912,18 @@ _room_list_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
}
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
if (child == NULL) {
return 0;
}
GPatternSpec *glob = (GPatternSpec*)userdata;
if (child == NULL) {
cons_show("No rooms found for service: %s", from);
return 0;
}
GPatternSpec *glob = NULL;
gchar *filter = (gchar*)userdata;
if (filter != NULL) {
glob = g_pattern_spec_new(filter);
g_free(filter);
}
gboolean matched = FALSE;
cons_show("Chat rooms at: %s", from);
while (child) {
@ -952,6 +955,8 @@ _room_list_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
cons_show(" No rooms found matching pattern.");
}
g_pattern_spec_free(glob);
return 0;
}

View File

@ -161,7 +161,7 @@ gboolean presence_sub_request_exists(const char *const bare_jid);
void iq_enable_carbons(void);
void iq_disable_carbons(void);
void iq_send_software_version(const char *const fulljid);
void iq_room_list_request(gchar *conferencejid, GPatternSpec *glob);
void iq_room_list_request(gchar *conferencejid, gchar *filter);
void iq_disco_info_request(gchar *jid);
void iq_disco_items_request(gchar *jid);
void iq_last_activity_request(gchar *jid);

View File

@ -14,8 +14,8 @@
void
rooms_query(void **state)
{
stbbr_for_id("confreq",
"<iq id='confreq' type='result' to='stabber@localhost/profanity' from='conference.localhost'>"
stbbr_for_id("prof_confreq_4",
"<iq id='prof_confreq_4' type='result' to='stabber@localhost/profanity' from='conference.localhost'>"
"<query xmlns='http://jabber.org/protocol/disco#items'>"
"<item jid='chatroom@conference.localhost' name='A chat room'/>"
"<item jid='hangout@conference.localhost' name='Another chat room'/>"
@ -25,13 +25,13 @@ rooms_query(void **state)
prof_connect();
prof_input("/rooms conference.localhost");
prof_input("/rooms service conference.localhost");
assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)"));
assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)"));
assert_true(prof_output_exact("chatroom@conference.localhost (A chat room)"));
assert_true(prof_output_exact("hangout@conference.localhost (Another chat room)"));
assert_true(stbbr_last_received(
"<iq id='confreq' to='conference.localhost' type='get'>"
"<iq id='prof_confreq_4' to='conference.localhost' type='get'>"
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
"</iq>"
));

View File

@ -54,18 +54,39 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
will_return(accounts_get_account, account);
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
expect_any(iq_room_list_request, filter);
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);
}
void cmd_rooms_arg_used_when_passed(void **state)
void cmd_rooms_service_arg_used_when_passed(void **state)
{
gchar *args[] = { "conf_server_arg" };
gchar *args[] = { "service", "conf_server_arg", NULL };
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
expect_any(iq_room_list_request, filter);
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);
}
void cmd_rooms_filter_arg_used_when_passed(void **state)
{
gchar *args[] = { "filter", "text", NULL };
ProfAccount *account = account_new("testaccount", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL,
0, 0, 0, 0, 0, strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
will_return(connection_get_status, JABBER_CONNECTED);
will_return(session_get_account_name, "account_name");
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
expect_any(iq_room_list_request, conferencejid);
expect_string(iq_room_list_request, filter, "text");
gboolean result = cmd_rooms(NULL, CMD_ROOMS, args);
assert_true(result);

View File

@ -3,4 +3,5 @@ void cmd_rooms_shows_message_when_disconnecting(void **state);
void cmd_rooms_shows_message_when_connecting(void **state);
void cmd_rooms_shows_message_when_undefined(void **state);
void cmd_rooms_uses_account_default_when_no_arg(void **state);
void cmd_rooms_arg_used_when_passed(void **state);
void cmd_rooms_service_arg_used_when_passed(void **state);
void cmd_rooms_filter_arg_used_when_passed(void **state);

View File

@ -313,7 +313,8 @@ int main(int argc, char* argv[]) {
unit_test(cmd_rooms_shows_message_when_disconnecting),
unit_test(cmd_rooms_shows_message_when_connecting),
unit_test(cmd_rooms_uses_account_default_when_no_arg),
unit_test(cmd_rooms_arg_used_when_passed),
unit_test(cmd_rooms_service_arg_used_when_passed),
unit_test(cmd_rooms_filter_arg_used_when_passed),
unit_test(cmd_account_shows_usage_when_not_connected_and_no_args),
unit_test(cmd_account_shows_account_when_connected_and_no_args),

View File

@ -172,9 +172,10 @@ void iq_disable_carbons() {};
void iq_enable_carbons() {};
void iq_send_software_version(const char * const fulljid) {}
void iq_room_list_request(gchar *conferencejid)
void iq_room_list_request(gchar *conferencejid, gchar *filter)
{
check_expected(conferencejid);
check_expected(filter);
}
void iq_disco_info_request(gchar *jid) {}