about summary refs log blame commit diff stats
path: root/tests/functionaltests/test_roster.c
blob: 7a3f56569a7f2d01e2c9661853368af8800f4907 (plain) (tree)




































































                                                                                    

                                                                


























                                                                            
                                                                













                                                                                    
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>

#include <stabber.h>
#include <expect.h>

#include "proftest.h"

void
sends_new_item(void **state)
{
    prof_connect();

    stbbr_for_query("jabber:iq:roster",
        "<iq type=\"set\" from=\"stabber@localhost\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"bob@localhost\" subscription=\"none\" name=\"\"/>"
            "</query>"
        "</iq>"
    );

    prof_input("/roster add bob@localhost");

    assert_true(stbbr_received(
        "<iq type=\"set\" id=\"*\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"bob@localhost\" name=\"\"/>"
            "</query>"
        "</iq>"
    ));

    assert_true(prof_output_exact("Roster item added: bob@localhost"));
}

void
sends_new_item_nick(void **state)
{
    prof_connect();

    stbbr_for_query("jabber:iq:roster",
        "<iq type=\"set\" from=\"stabber@localhost\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"bob@localhost\" subscription=\"none\" name=\"Bobby\"/>"
            "</query>"
        "</iq>"
    );

    prof_input("/roster add bob@localhost Bobby");

    assert_true(stbbr_received(
        "<iq type=\"set\" id=\"*\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"bob@localhost\" name=\"Bobby\"/>"
            "</query>"
        "</iq>"
    ));

    assert_true(prof_output_exact("Roster item added: bob@localhost (Bobby)"));
}

void
sends_remove_item(void **state)
{
    prof_connect_with_roster(
        "<item jid=\"buddy1@localhost\" subscription=\"both\"/>"
        "<item jid=\"buddy2@localhost\" subscription=\"both\"/>"
    );

    stbbr_for_query("jabber:iq:roster",
        "<iq id=\"*\" type=\"set\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"buddy1@localhost\" subscription=\"remove\"/>"
            "</query>"
        "</iq>"
    );

    prof_input("/roster remove buddy1@localhost");

    assert_true(stbbr_received(
        "<iq type=\"set\" id=\"*\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"buddy1@localhost\" subscription=\"remove\"/>"
            "</query>"
        "</iq>"
    ));

    assert_true(prof_output_exact("Roster item removed: buddy1@localhost"));
}

void
sends_nick_change(void **state)
{
    prof_connect_with_roster(
        "<item jid=\"buddy1@localhost\" subscription=\"both\"/>"
    );

    prof_input("/roster nick buddy1@localhost Buddy1");

    assert_true(prof_output_exact("Nickname for buddy1@localhost set to: Buddy1."));

    assert_true(stbbr_received(
        "<iq type=\"set\" id=\"*\">"
            "<query xmlns=\"jabber:iq:roster\">"
                "<item jid=\"buddy1@localhost\" name=\"Buddy1\"/>"
            "</query>"
        "</iq>"
    ));
}
est_plan_bb(S,Limit,Plan,PlanCost), var(Plan), var(PlanCost), integer(Limit), Limit >= 0 => loop_best_plan_bb(S,Limit,Plan,PlanCost). best_plan_bb(_S,Limit,Plan,PlanCost) => throw_plan_arg_error(Limit,Plan,PlanCost,best_plan_bb). loop_best_plan_bb(S,Limit,Plan,PlanCost), (bp.global_get('_$picat_log',0, 1) -> printf("%% Searching with the bound %d\n",Limit); true), call_picat_plan(S,Limit) => get_table_map('_$planner').get($current_best_plan_cost(S)) = PlanCost1, loop_best_plan_bb(S,PlanCost1-1,Plan,PlanCost). loop_best_plan_bb(S,_Limit,Plan,PlanCost) => Map = get_table_map('_$planner'), Map.has_key($current_best_plan(S)), Map.get($current_best_plan(S)) = Plan, Map.get($current_best_plan_cost(S)) = PlanCost. call_picat_plan(S,Limit) => bp.global_set('_$planner_explored_depth',0,268435455), not not call_picat_plan_aux(S,Limit). % discard exception catchers created by picat_plan call_picat_plan_aux(S,Limit) => bp.picat_plan(S,Limit,Plan,PlanCost,FinS), Map = get_table_map('_$planner'), Map.put($current_best_plan(S), Plan), Map.put($current_best_plan_cost(S), PlanCost), Map.put($current_best_plan_fin_state(S), FinS). %%% best_plan_unbounded(S,Plan), var(Plan) => bp.picat_best_plan_unbounded(S,Plan,_). best_plan_unbounded(_S,Plan) => throw_plan_arg_error(1,Plan,_,best_plan_unbounded). best_plan_unbounded(S,Limit,Plan), var(Plan), integer(Limit), Limit >= 0 => bp.picat_best_plan_unbounded(S,Plan,PlanCost), PlanCost =< Limit. best_plan_unbounded(S,Plan,PlanCost), var(Plan), var(PlanCost) => bp.picat_best_plan_unbounded(S,Plan,PlanCost). best_plan_unbounded(_S,Limit,Plan) => throw_plan_arg_error(Limit,Plan,_,best_plan_unbounded). best_plan_unbounded(S,Limit,Plan,PlanCost), var(Plan), var(PlanCost), integer(Limit), Limit >= 0 => bp.picat_best_plan_unbounded(S,Plan,PlanCost), PlanCost =< Limit. best_plan_unbounded(_S,Limit,Plan,PlanCost) => throw_plan_arg_error(Limit,Plan,PlanCost,best_plan_unbounded). %%% is_tabled_state(S) => bp.b_IS_PLANNER_STATE_c(S). throw_plan_arg_error(_Limit,Plan,_PlanCost,Source), nonvar(Plan) => handle_exception($var_expected(Plan), Source). throw_plan_arg_error(_Limit,_Plan,PlanCost,Source), nonvar(PlanCost) => handle_exception($var_expected(PlanCost), Source). throw_plan_arg_error(Limit,_Plan,_PlanCost,Source), integer(Limit) => handle_exception($nonnegative_integer_expected(Limit), Source). throw_plan_arg_error(Limit,_Plan,_PlanCost,Source) => handle_exception($integer_expected(Limit), Source).