1# 05basichandler.t -- ... 2# 3# $Id: 05basichandler.t,v 1.1 2004/09/14 08:40:31 hoehrmann Exp $ 4 5use strict; 6use warnings; 7use Test::More tests => 14; 8use Test::Exception; 9use File::Spec qw(); 10 11use constant NO_DOCTYPE => File::Spec->catfile('samples', 'no-doctype.xml'); 12use constant TEST_CATALOG => File::Spec->catfile('samples', 'test.soc'); 13 14BEGIN { use_ok('SGML::Parser::OpenSP') }; 15require_ok('SGML::Parser::OpenSP'); 16my $p = SGML::Parser::OpenSP->new; 17isa_ok($p, 'SGML::Parser::OpenSP'); 18 19######################################################### 20## Simple Event Handler 21######################################################### 22 23sub TestHandler1::new { bless{ok1=>0,ok2=>0,ok3=>0,ok4=>0,ok5=>0, 24 ok6=>0,ok7=>0,ok8=>0,ok9=>0,oka=>0},shift } 25sub TestHandler1::start_element { 26 my $s = shift; 27 my $e = shift; 28 29 return unless defined $s; 30 return unless defined $e; 31 32 $s->{ok1}++ if UNIVERSAL::isa($s, 'TestHandler1'); 33 34 # Name 35 $s->{ok2}++ if exists $e->{Name}; 36 $s->{ok3}++ if $e->{Name} =~ /no-doctype/i; 37 38 # Attributes 39 $s->{ok4}++ if exists $e->{Attributes}; 40 $s->{ok5}++ if UNIVERSAL::isa($e->{Attributes}, "HASH"); 41 $s->{ok6}++ if scalar(keys(%{$_[1]->{Attributes}})) == 0; 42 43 # Included 44 $s->{ok7}++ if exists $e->{Included}; 45 $s->{ok8}++ if $e->{Included} == 0; 46 47 # ContentType 48 $s->{ok9}++ if exists $e->{ContentType}; 49} 50 51my $h1 = TestHandler1->new; 52 53isa_ok($h1, 'TestHandler1'); 54 55$p->handler($h1); 56 57lives_ok { $p->parse(NO_DOCTYPE) } 58 'basic parser test'; 59 60ok($h1->{ok1}, 'self to handler'); 61ok($h1->{ok2}, 'has name'); 62ok($h1->{ok3}, 'proper name'); 63ok($h1->{ok4}, 'has attrs'); 64ok($h1->{ok5}, 'attrs hash ref'); 65ok($h1->{ok6}, 'proper attrs'); 66ok($h1->{ok7}, 'has included'); 67ok($h1->{ok8}, 'included == 0'); 68ok($h1->{ok9}, 'has content type'); 69 70