3 # Test that Thrasher::XMPPStreamOut works as expected.
4 use Test
::More
'no_plan';
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.
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',
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' "
43 ."xmlns:stream='http://etherx.jabber.org/streams'>"],
44 "basic stream output works.");
46 cmp_deeply
($out->{prefixes_to_namespace
},
49 'stream' => [$NS_STREAM]},
50 'correctly remembers the root-level namespaces');
54 my $ugly_sample = [[$NS_CLIENT, 'hello'],
57 '{jabber:fake}to' => 'test'},
60 {'{}aimlessly' => 'true',
61 '{jabber:fake}oo' => 'oo'},
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'>",
71 cmp_deeply
($out->{prefixes_to_namespace
},
74 'stream' => [$NS_STREAM]},
75 'correctly forgets the tag-specific namespaces');
79 $out->output([[$NS_CLIENT, 'test'], {}, []]);
80 cmp_deeply
(\
@accum, ['<test/>'], 'self-closed tags work');
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');
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.');
98 is
(Thrasher
::XMPPStreamOut
::pcdata_process
($test),
99 "?", "pcdata_process paranoia-ly strips out bad characters");