# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl RPC-XML-Parser-XS.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 28; BEGIN { use_ok('RPC::XML::Parser::LibXML') }; use RPC::XML; use utf8; ######################### # bloody hack to shut up Test::Builder being passed Unicode strings sub _is_deeply { my($this, $that, $msg) = @_; utf8::encode($msg) if $msg; @_ = ($this, $that, $msg); goto &is_deeply; } # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new('foo.bar'), 'methodCall w/ no params'; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new('foo.bar'), 'methodCall w/ empty '; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new('foo.bar'), 'methodCall w/ empty '; _is_deeply parse_rpc_xml(qq{ foo.bar 3 6 }), RPC::XML::request->new( 'foo.bar', RPC::XML::int->new(3), RPC::XML::int->new(6), ), 'methodCall w/ [3::int, 6::int]'; _is_deeply parse_rpc_xml(qq{ foo.bar 1 0 1 }), RPC::XML::request->new( 'foo.bar', RPC::XML::boolean->new(1), RPC::XML::boolean->new(0), RPC::XML::boolean->new(1), ), 'methodCall w/ [1::boolean, ...]'; _is_deeply parse_rpc_xml(qq{ foo.bar はい }), RPC::XML::request->new( 'foo.bar', RPC::XML::string->new('る'), RPC::XML::string->new('はい'), RPC::XML::string->new(''), RPC::XML::string->new(''), ), 'methodCall w/ ["る"::string, ...]'; _is_deeply parse_rpc_xml(qq{ foo.bar -3.1415926536 }), RPC::XML::request->new( 'foo.bar', RPC::XML::double->new(-3.1415926536), ), 'methodCall w/ [-3.1415926536::double]'; _is_deeply parse_rpc_xml(qq{ foo.bar 20070501T120656+0900 }), RPC::XML::request->new( 'foo.bar', RPC::XML::datetime_iso8601->new('20070501T120656+0900'), ), 'methodCall w/ [20070501T120656+0900::dateTime.iso8601]'; _is_deeply parse_rpc_xml(qq{ foo.bar TnlhcmxhdGhvdGVw }), RPC::XML::request->new( 'foo.bar', RPC::XML::base64->new('Nyarlathotep'), ), 'methodCall w/ ["Nyarlathotep"::base64]'; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::struct->new({}), ), 'methodCall w/ '; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::struct->new({}), ), 'methodCall w/ '; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::struct->new({ 'い' => RPC::XML::string->new('ろ'), 'は' => RPC::XML::string->new('に'), })), 'methodCall w/ [struct]'; _is_deeply parse_rpc_xml(qq{ foo.bar foo bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::struct->new({ 'い' => RPC::XML::struct->new({ 'foo' => RPC::XML::string->new('bar'), }), 'は' => RPC::XML::string->new('に'), })), 'methodCall w/ [struct]'; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::array->new(), ), 'methodCall w/ '; _is_deeply parse_rpc_xml(qq{ foo.bar }), RPC::XML::request->new( 'foo.bar', RPC::XML::array->new(), ), 'methodCall w/ '; _is_deeply parse_rpc_xml(qq{ foo.bar はい }), RPC::XML::request->new( 'foo.bar', RPC::XML::array->new( RPC::XML::string->new('る'), RPC::XML::string->new('はい'), )), 'methodCall w/ ["る"::string, ...]'; _is_deeply parse_rpc_xml(qq{ }), RPC::XML::response->new( RPC::XML::string->new('る'), ), 'methodResponse w/ ["る"::string]'; _is_deeply parse_rpc_xml(qq{ faultCode 3 faultString }), RPC::XML::response->new( RPC::XML::fault->new(3, 'る'), ), 'methodResponse w/ [(3, "る")::fault]'; _is_deeply parse_rpc_xml(qq{ foo.bar foobar bar baz }), RPC::XML::request->new( 'foo.bar', RPC::XML::struct->new({ 'foo' => RPC::XML::string->new('bar'), 'bar' => RPC::XML::string->new('baz'), })), 'methodCall w/ [struct], no newlines'; _is_deeply parse_rpc_xml(qq{ metaWeblog.newPost 3 foo title testing excerpt description <p>testing xxx</p> dateCreated 20080403T22:11:33 }), RPC::XML::request->new( 'metaWeblog.newPost', RPC::XML::string->new('3'), RPC::XML::string->new('foo'), RPC::XML::struct->new({ title => RPC::XML::string->new('testing excerpt'), description => RPC::XML::string->new('

testing xxx

'), dateCreated => RPC::XML::datetime_iso8601->new('20080403T22:11:33'), }), ), 'Windows Live Write style newlines'; { my $r = eval { RPC::XML::Parser::LibXML::parse_rpc_xml(< metaWeblog.newPost testf USERNAMEPASSWORD titletyuyurdescription<a href="http://example.com/.a/6a00d83453919f69e200ddx53f5f4178833-pi"><img src = "http://tsdavis.typepad.com/.a/6a00d83453919f69e200e553f5f4178833-pi" align = "left" height="384" width="212" hspace = "20" /></a> 1 XML }; ok !$@; is $r->{name}, 'metaWeblog.newPost'; is @{ $r->{args} }, 5; } { my $r = eval { RPC::XML::Parser::LibXML::parse_rpc_xml(< metaWeblog.newPost foobar **ACCOUNTNAME** **PASSWORD** titletest descriptiondesc foo bar XML }; is $r->{args}->[0]->value, 'foobar'; is $r->{args}->[3]->{title}->value, 'test'; is $r->{args}->[3]->{description}->value, 'desc'; is_deeply $r->{args}->[4], [ map RPC::XML::string->new($_), qw( foo bar ) ]; }