about summary refs log tree commit diff stats
path: root/COPYING
blob: c643d83660cddbc48aaf83067a5b064ba01ec4d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
Discordian Public License (DPL)

All Rights Reversed Ⓚ 3187 Nova li Gensokyo <novaburst@kalli.st>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
='#n207'>207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
#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_room_join(void **state)
{
    prof_connect();

    prof_input("/join testroom@conference.localhost");

    assert_true(stbbr_last_received(
        "<presence id='*' to='testroom@conference.localhost/stabber'>"
            "<x xmlns='http://jabber.org/protocol/muc'/>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
        "</presence>"
    ));
}

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

    prof_input("/join testroom");

    assert_true(stbbr_last_received(
        "<presence id='*' to='testroom@conference.localhost/stabber'>"
            "<x xmlns='http://jabber.org/protocol/muc'/>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
        "</presence>"
    ));
}

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

    prof_input("/join testroom@conference.localhost nick testnick");

    assert_true(stbbr_last_received(
        "<presence id='*' to='testroom@conference.localhost/testnick'>"
            "<x xmlns='http://jabber.org/protocol/muc'/>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
        "</presence>"
    ));
}

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

    prof_input("/join testroom@conference.localhost password testpassword");

    assert_true(stbbr_last_received(
        "<presence id='*' to='testroom@conference.localhost/stabber'>"
            "<x xmlns='http://jabber.org/protocol/muc'>"
                "<password>testpassword</password>"
            "</x>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
        "</presence>"
    ));
}

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

    prof_input("/join testroom@conference.localhost nick testnick password testpassword");

    assert_true(stbbr_last_received(
        "<presence id='*' to='testroom@conference.localhost/testnick'>"
            "<x xmlns='http://jabber.org/protocol/muc'>"
                "<password>testpassword</password>"
            "</x>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
        "</presence>"
    ));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");

    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost'>"
            "<subject>Test room subject</subject>"
            "<body>anothernick has set the subject to: Test room subject</body>"
        "</message>"
    );

    assert_true(prof_output_regex("Room subject: .+Test room subject"));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<body>an old message</body>"
            "<delay xmlns='urn:xmpp:delay' stamp='2015-12-19T23:55:25Z' from='testroom@conference.localhost'/>"
            "<x xmlns='jabber:x:delay' stamp='20151219T23:55:25'/>"
        "</message>"
    );

    assert_true(prof_output_regex("testoccupant: an old message"));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    stbbr_send(
        "<presence to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='someuser@someserver.org/work' affiliation='none'/>"
            "</x>"
        "</presence>"
    );

    assert_true(prof_output_exact("-> testoccupant has joined the room, role: participant, affiliation: none"));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<body>a new message</body>"
        "</message>"
    );

    assert_true(prof_output_regex("testoccupant: .+a new message"));
}

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

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    prof_input("/win 1");
    assert_true(prof_output_exact("Profanity. Type /help for help information."));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<body>a new message</body>"
        "</message>"
    );

    assert_true(prof_output_exact("<< room message: testoccupant in testroom@conference.localhost (win 2)"));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/anotheroccupant'>"
            "<body>some other message</body>"
        "</message>"
    );

    assert_true(prof_output_exact("<< room message: anotheroccupant in testroom@conference.localhost (win 2)"));
}

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

    prof_input("/console muc first");
    assert_true(prof_output_exact("Console MUC messages set: first"));

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    prof_input("/win 1");
    assert_true(prof_output_exact("Profanity. Type /help for help information."));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<body>a new message</body>"
        "</message>"
    );

    assert_true(prof_output_exact("<< room message: testroom@conference.localhost (win 2)"));
    prof_input("/clear");
    prof_input("/about");
    assert_true(prof_output_exact("Type '/help' to show complete help."));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/anotheroccupant'>"
            "<body>some other message</body>"
        "</message>"
    );

    prof_timeout(2);
    assert_false(prof_output_exact("<< room message: testroom@conference.localhost (win 2)"));
    prof_timeout_reset();
}

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

    prof_input("/console muc none");
    assert_true(prof_output_exact("Console MUC messages set: none"));

    stbbr_for_id("prof_join_2",
        "<presence id='prof_join_2' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
            "<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='*'/>"
            "<x xmlns='http://jabber.org/protocol/muc#user'>"
                "<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
            "</x>"
            "<status code='110'/>"
        "</presence>"
    );

    prof_input("/join testroom@conference.localhost");
    assert_true(prof_output_exact("-> You have joined the room as stabber, role: participant, affiliation: none"));

    prof_input("/win 1");
    assert_true(prof_output_exact("Profanity. Type /help for help information."));

    stbbr_send(
        "<message type='groupchat' to='stabber@localhost/profanity' from='testroom@conference.localhost/testoccupant'>"
            "<body>a new message</body>"
        "</message>"
    );

    prof_timeout(2);
    assert_false(prof_output_exact("testroom@conference.localhost (win 2)"));
    prof_timeout_reset();
}