about summary refs log tree commit diff stats
path: root/tangle/makefile
blob: caf1396548ace555038d09294a4b3fb8ebf4d559 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
tangle: makefile type_list function_list file_list test_file_list test_list
	c++ -g -O3 -Wall -Wextra -fno-strict-aliasing boot.cc -o tangle

type_list: boot.cc [0-9]*.cc
	@# assumes struct decl has space before '{'
	@grep -h "^struct .* {" [0-9]*.cc |perl -pwe 's/(struct *[^ ]*).*/$$1;/' > type_list
	@grep -h typedef [0-9]*.cc >> type_list

function_list: boot.cc [0-9]*.cc
	@# assumes function decl has space before '{'
	@grep -h "^[^ #].*) {" [0-9]*.cc |perl -pwe 's/ {.*/;/' > function_list

file_list: boot.cc [0-9]*.cc
	@ls [0-9]*.cc |grep -v "\.test\.cc$$" |perl -pwe 's/.*/#include "$$&"/' > file_list

test_file_list: [0-9]*.test.cc
	@ls [0-9]*.test.cc |perl -pwe 's/.*/#include "$$&"/' > test_file_list

test_list: [0-9]*.cc
	@grep -h "^[[:space:]]*void test_" [0-9]*.cc |perl -pwe 's/^\s*void (.*)\(\) {$$/$$1,/' > test_list

clean:
	-rm tangle *_list
f0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#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
connect_jid(void **state)
{
    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(prof_output("Connecting as stabber@localhost"));
    assert_true(prof_output("stabber@localhost logged in successfully"));
}

void
connect_jid_requests_roster(void **state)
{
    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(stbbr_received(
        "<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>"
    ));
}

void
connect_jid_sends_presence_after_receiving_roster(void **state)
{
    stbbr_for("roster",
        "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
            "<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
                "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
                "<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
            "</query>"
        "</iq>"
    );

    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(stbbr_received(
        "<presence id=\"*\">"
            "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
        "</presence>"
    ));
}

void
connect_jid_requests_bookmarks(void **state)
{
    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(stbbr_received(
        "<iq id=\"*\" type=\"get\">"
            "<query xmlns=\"jabber:iq:private\">"
                "<storage xmlns=\"storage:bookmarks\"/>"
            "</query>"
        "</iq>"
    ));
}

void
connect_bad_password(void **state)
{
    prof_input("/connect stabber@localhost port 5230");
    prof_input("badpassword");

    assert_true(prof_output("Login failed."));
}

void
show_presence_updates(void **state)
{
    stbbr_for("roster",
        "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
            "<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
                "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
                "<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
            "</query>"
        "</iq>"
    );

    stbbr_for("prof_presence_1",
        "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
            "<show>dnd</show>"
            "<status>busy!</status>"
        "</presence>"
        "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\">"
            "<show>chat</show>"
            "<status>Talk to me!</status>"
        "</presence>"
        "<presence to=\"stabber@localhost\" from=\"buddy2@localhost/work\">"
            "<show>away</show>"
            "<status>Out of office</status>"
        "</presence>"
    );

    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(prof_output("Buddy1 (mobile) is dnd"));
    assert_true(prof_output("Buddy1 (laptop) is chat"));
    assert_true(prof_output("Buddy2 (work) is away"));

    stbbr_send(
        "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
            "<show>xa</show>"
            "<status>Gone :(</status>"
        "</presence>"
    );

    assert_true(prof_output("Buddy1 (mobile) is xa"));
}

void
sends_rooms_iq(void **state)
{
    stbbr_for("confreq",
        "<iq id=\"confreq\" 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\"/>"
            "</query>"
        "</iq>"
    );

    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");
    prof_input("/rooms");

    assert_true(stbbr_last_received(
        "<iq id=\"confreq\" to=\"conference.localhost\" type=\"get\">"
            "<query xmlns=\"http://jabber.org/protocol/disco#items\"/>"
        "</iq>"
    ));
}

void
multiple_pings(void **state)
{
    stbbr_for("prof_ping_1",
        "<iq id=\"prof_ping_1\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
    );
    stbbr_for("prof_ping_2",
        "<iq id=\"prof_ping_2\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
    );

    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    prof_input("/ping");
    assert_true(stbbr_received(
        "<iq id=\"prof_ping_1\" type=\"get\">"
            "<ping xmlns=\"urn:xmpp:ping\"/>"
        "</iq>"
    ));
    assert_true(prof_output("Ping response from server"));

    prof_input("/ping");
    assert_true(stbbr_received(
        "<iq id=\"prof_ping_2\" type=\"get\">"
            "<ping xmlns=\"urn:xmpp:ping\"/>"
        "</iq>"
    ));
    assert_true(prof_output("Ping response from server"));
}

void
responds_to_ping(void **state)
{
    prof_input("/connect stabber@localhost port 5230");
    prof_input("password");

    assert_true(prof_output("stabber@localhost logged in successfully"));

    stbbr_send(
        "<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
            "<ping xmlns=\"urn:xmpp:ping\"/>"
        "</iq>"
    );

    assert_true(stbbr_received(
        "<iq id=\"pingtest1\" type=\"result\" from=\"stabber@localhost/profanity\" to=\"localhost\"/>"
    ));
}