예제 #1
0
void find_five_times_finds_fifth(void **state)
{
    roster_create();
    roster_add("Jama", NULL, NULL, NULL, FALSE);
    roster_add("Jamb", NULL, NULL, NULL, FALSE);
    roster_add("Mike", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    roster_add("Jamm", NULL, NULL, NULL, FALSE);
    roster_add("Jamn", NULL, NULL, NULL, FALSE);
    roster_add("Matt", NULL, NULL, NULL, FALSE);
    roster_add("Jamo", NULL, NULL, NULL, FALSE);
    roster_add("Jamy", NULL, NULL, NULL, FALSE);
    roster_add("Jamz", NULL, NULL, NULL, FALSE);

    char *result1 = roster_contact_autocomplete("Jam");
    char *result2 = roster_contact_autocomplete(result1);
    char *result3 = roster_contact_autocomplete(result2);
    char *result4 = roster_contact_autocomplete(result3);
    char *result5 = roster_contact_autocomplete(result4);
    assert_string_equal("Jamo", result5);
    free(result1);
    free(result2);
    free(result3);
    free(result4);
    free(result5);
    roster_destroy();
}
예제 #2
0
void find_on_empty_returns_null(void **state)
{
    roster_create();
    char *result = roster_contact_autocomplete("James");
    assert_null(result);
    roster_destroy();
}
예제 #3
0
void add_contact_with_three_groups(void **state)
{
    roster_create();

    GSList *groups = NULL;
    groups = g_slist_append(groups, strdup("friends"));
    groups = g_slist_append(groups, strdup("work"));
    groups = g_slist_append(groups, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups, NULL, FALSE);

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 3);

    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
    assert_true(found != NULL);
    assert_string_equal(found->data, "friends");
    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
    assert_true(found != NULL);
    assert_string_equal(found->data, "work");
    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
    assert_true(found != NULL);
    assert_string_equal(found->data, "stuff");

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
예제 #4
0
void add_contact_with_three_groups_update_two_new(void **state)
{
    roster_create();

    GSList *groups1 = NULL;
    groups1 = g_slist_append(groups1, strdup("friends"));
    groups1 = g_slist_append(groups1, strdup("work"));
    groups1 = g_slist_append(groups1, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups1, NULL, FALSE);

    GSList *groups2 = NULL;
    groups2 = g_slist_append(groups2, strdup("newfriends"));
    groups2 = g_slist_append(groups2, strdup("somepeople"));
    roster_update("*****@*****.**", NULL, groups2, NULL, FALSE);

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 2);

    GSList *found = g_slist_find_custom(groups_res, "newfriends", g_strcmp0);
    assert_true(found != NULL);
    found = g_slist_find_custom(groups_res, "somepeople", g_strcmp0);
    assert_true(found != NULL);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
예제 #5
0
void empty_list_when_none_added(void **state)
{
    roster_create();
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
    assert_null(list);
    roster_destroy();
}
예제 #6
0
void remove_contact_with_remaining_in_group(void **state)
{
    roster_create();

    GSList *groups1 = NULL;
    groups1 = g_slist_append(groups1, strdup("friends"));
    groups1 = g_slist_append(groups1, strdup("work"));
    groups1 = g_slist_append(groups1, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups1, NULL, FALSE);

    GSList *groups2 = NULL;
    groups2 = g_slist_append(groups2, strdup("friends"));
    groups2 = g_slist_append(groups2, strdup("work"));
    groups2 = g_slist_append(groups2, strdup("different"));
    roster_add("*****@*****.**", NULL, groups2, NULL, FALSE);

    roster_remove("*****@*****.**", "*****@*****.**");

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 3);

    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
    assert_true(found != NULL);
    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
    assert_true(found != NULL);
    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
    assert_true(found != NULL);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
예제 #7
0
void
sv_ev_lost_connection(void)
{
    cons_show_error("Lost connection.");

#ifdef HAVE_LIBOTR
    GSList *recipients = wins_get_chat_recipients();
    GSList *curr = recipients;
    while (curr) {
        char *barejid = curr->data;
        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin && otr_is_secure(barejid)) {
            chatwin_otr_unsecured(chatwin);
            otr_end_session(barejid);
        }
        curr = g_slist_next(curr);
    }
    if (recipients) {
        g_slist_free(recipients);
    }
#endif

    muc_invites_clear();
    chat_sessions_clear();
    ui_disconnected();
    roster_destroy();
#ifdef HAVE_LIBGPGME
    p_gpg_on_disconnect();
#endif
}
예제 #8
0
void contains_one_element(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
    assert_int_equal(1, g_slist_length(list));
    roster_destroy();
}
예제 #9
0
void first_element_correct(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
    PContact james = list->data;

    assert_string_equal("James", p_contact_barejid(james));
    roster_destroy();
}
예제 #10
0
void find_returns_null(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    roster_add("Bob", NULL, NULL, NULL, FALSE);

    char *result = roster_contact_autocomplete("Mike");
    assert_null(result);
    roster_destroy();
}
예제 #11
0
void add_contact_with_no_group(void **state)
{
    roster_create();
    roster_add("*****@*****.**", NULL, NULL, NULL, FALSE);

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 0);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
예제 #12
0
void find_third_exists(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    roster_add("Bob", NULL, NULL, NULL, FALSE);

    char *result = roster_contact_autocomplete("Ja");
    assert_string_equal("James", result);
    free(result);
    roster_destroy();
}
예제 #13
0
void first_and_second_elements_correct(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);

    PContact first = list->data;
    PContact second = (g_slist_next(list))->data;

    assert_string_equal("Dave", p_contact_barejid(first));
    assert_string_equal("James", p_contact_barejid(second));
    roster_destroy();
}
예제 #14
0
void find_twice_returns_second_when_two_match(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("Jamie", NULL, NULL, NULL, FALSE);
    roster_add("Bob", NULL, NULL, NULL, FALSE);

    char *result1 = roster_contact_autocomplete("Jam");
    char *result2 = roster_contact_autocomplete(result1);
    assert_string_equal("Jamie", result2);
    free(result1);
    free(result2);
    roster_destroy();
}
예제 #15
0
void first_three_elements_correct(void **state)
{
    roster_create();
    roster_add("Bob", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    roster_add("James", NULL, NULL, NULL, FALSE);
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
    PContact bob = list->data;
    PContact dave = (g_slist_next(list))->data;
    PContact james = (g_slist_next(g_slist_next(list)))->data;

    assert_string_equal("James", p_contact_barejid(james));
    assert_string_equal("Dave", p_contact_barejid(dave));
    assert_string_equal("Bob", p_contact_barejid(bob));
    roster_destroy();
}
예제 #16
0
void
cl_ev_disconnect(void)
{
    const char *jid = jabber_get_fulljid();
    cons_show("%s logged out successfully.", jid);

    ui_disconnected();
    ui_close_all_wins();
    jabber_disconnect();
    roster_destroy();
    muc_invites_clear();
    chat_sessions_clear();
    tlscerts_clear_current();
#ifdef HAVE_LIBGPGME
    p_gpg_on_disconnect();
#endif
}
예제 #17
0
void console_shows_dnd_presence_when_set_all(void **state)
{
    prefs_set_string(PREF_STATUSES_CONSOLE, "all");
    plugins_init();
    roster_create();
    char *barejid = "test1@server";
    roster_add(barejid, "bob", NULL, "both", FALSE);
    Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);

    expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
    expect_memory(ui_contact_online, resource, resource, sizeof(resource));
    expect_value(ui_contact_online, last_activity, NULL);

    sv_ev_contact_online(barejid, resource, NULL, NULL);

    roster_destroy();
    plugins_shutdown();
}
예제 #18
0
void add_twice_at_beginning_adds_once(void **state)
{
    roster_create();
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("James", NULL, NULL, NULL, FALSE);
    roster_add("Dave", NULL, NULL, NULL, FALSE);
    roster_add("Bob", NULL, NULL, NULL, FALSE);
    GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
    PContact first = list->data;
    PContact second = (g_slist_next(list))->data;
    PContact third = (g_slist_next(g_slist_next(list)))->data;

    assert_int_equal(3, g_slist_length(list));
    assert_string_equal("Bob", p_contact_barejid(first));
    assert_string_equal("Dave", p_contact_barejid(second));
    assert_string_equal("James", p_contact_barejid(third));
    roster_destroy();
}
예제 #19
0
void add_remove_contact_groups(void **state)
{
    roster_create();

    GSList *groups1 = NULL;
    groups1 = g_slist_append(groups1, strdup("friends"));
    groups1 = g_slist_append(groups1, strdup("work"));
    groups1 = g_slist_append(groups1, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups1, NULL, FALSE);

    roster_remove("*****@*****.**", "*****@*****.**");

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 0);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
예제 #20
0
void
cl_ev_disconnect(void)
{
    const char *jid = connection_get_fulljid();
    Jid *jidp = jid_create(jid);
    cons_show("%s logged out successfully.", jidp->barejid);
    jid_destroy(jidp);

    ui_disconnected();
    ui_close_all_wins();
    session_disconnect();
    roster_destroy();
    muc_invites_clear();
    muc_confserver_clear();
    chat_sessions_clear();
    tlscerts_clear_current();
#ifdef HAVE_LIBGPGME
    p_gpg_on_disconnect();
#endif
}
예제 #21
0
void handle_offline_removes_chat_session(void **state)
{
    plugins_init();
    roster_create();
    chat_sessions_init();
    char *barejid = "*****@*****.**";
    char *resource = "home";
    roster_add(barejid, "bob", NULL, "both", FALSE);
    Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
    roster_update_presence(barejid, resourcep, NULL);
    chat_session_recipient_active(barejid, resource, FALSE);
    ProfConsoleWin *console = malloc(sizeof(ProfConsoleWin));
    will_return(win_create_console, &console->window);
    wins_init();
    sv_ev_contact_offline(barejid, resource, NULL);
    ChatSession *session = chat_session_get(barejid);

    assert_null(session);

    roster_destroy();
    chat_sessions_clear();
    plugins_shutdown();
}