Translate incoming typing notifications from libpurple into chatstates.
[thrasher.git] / perl / tests / xmpp_stream_out.pl
blob043b8d8985b0ea633e5edf84e74ba9a45d0cb29f
1 #!/usr/bin/perl
3 # Test that Thrasher::XMPPStreamOut works as expected.
4 use Test::More 'no_plan';
5 use Test::Deep;
7 use strict;
8 use warnings;
10 use Data::Dumper;
12 BEGIN {
13 use_ok 'Thrasher::XMPPStreamOut';
14 use_ok 'Thrasher::Constants', qw(:all);
17 # We deliberately store this as a list so we can examine that
18 # the chunks are correct.
19 my @accum;
20 my $output = sub {
21 push @accum, @_;
24 sub clear {
25 @accum = ();
28 BASIC_TESTING: {
29 my $out = new Thrasher::XMPPStreamOut($output);
30 my $initial_stream = [[$NS_STREAM, 'stream'],
31 {'{}version' => '1.0',
32 "{$NS_CLIENT}to" => 'example.com',
33 '{fleem}moo' => 'floo',
34 '{}moo' => 'test'},
35 []];
37 $out->output_tag_and_children($initial_stream, 1);
39 cmp_deeply(\@accum, ["<stream:stream moo='test' ns1:moo='floo' "
40 ."to='example.com' version='1.0' "
41 ."xmlns='jabber:client' "
42 ."xmlns:ns1='fleem' "
43 ."xmlns:stream='http://etherx.jabber.org/streams'>"],
44 "basic stream output works.");
46 cmp_deeply($out->{prefixes_to_namespace},
47 {'' => [$NS_CLIENT],
48 'ns1' => ['fleem'],
49 'stream' => [$NS_STREAM]},
50 'correctly remembers the root-level namespaces');
52 clear;
54 my $ugly_sample = [[$NS_CLIENT, 'hello'],
55 {'{}from' => 'test',
56 '{}to' => 'test2',
57 '{jabber:fake}to' => 'test'},
59 [[$NS_CLIENT, 'moo'],
60 {'{}aimlessly' => 'true',
61 '{jabber:fake}oo' => 'oo'},
62 ["Hi!\x00"]]
63 ]];
64 $out->output($ugly_sample);
65 cmp_deeply(\@accum, ["<hello from='test' ns2:to='test' to='test2' xmlns:ns2='jabber:fake'>",
66 "<moo aimlessly='true' ns2:oo='oo'>",
67 "Hi!",
68 "</moo>",
69 "</hello>"]);
71 cmp_deeply($out->{prefixes_to_namespace},
72 {'' => [$NS_CLIENT],
73 'ns1' => ['fleem'],
74 'stream' => [$NS_STREAM]},
75 'correctly forgets the tag-specific namespaces');
77 clear;
79 $out->output([[$NS_CLIENT, 'test'], {}, []]);
80 cmp_deeply(\@accum, ['<test/>'], 'self-closed tags work');
82 clear;
84 my $test_string = 'I choose <p>to</p> disregard you.';
85 $out->output(\$test_string);
86 cmp_deeply(\@accum, [$test_string], 'scalar refs work');
87 clear;
89 $test_string = "\x1fI have\x00 illegal\x08ness.";
90 $out->output(\$test_string);
91 cmp_deeply(\@accum, ["I have illegalness."],
92 'sending out scalar strings still strips PCDATA-'
93 .'illegal strings out.');
96 ENCODING: {
97 my $test = "\xf3";
98 is(Thrasher::XMPPStreamOut::pcdata_process($test),
99 "?", "pcdata_process paranoia-ly strips out bad characters");