diff options
Diffstat (limited to 'test/DOMTSHandler.pm')
-rw-r--r-- | test/DOMTSHandler.pm | 121 |
1 files changed, 105 insertions, 16 deletions
diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm index df2b028..fec9bcb 100644 --- a/test/DOMTSHandler.pm +++ b/test/DOMTSHandler.pm @@ -42,6 +42,13 @@ our %special_type = ( HTMLFormElement => "dom_html_form_element *", CharacterData => "dom_characterdata *", CDATASection => "dom_cdata_section *", + HTMLAnchorElement => "dom_html_anchor_element *", + HTMLElement => "dom_html_element *", + HTMLTableCaptionElement => "dom_html_table_caption_element *", + HTMLTableSectionElement => "dom_html_table_section_element *", + HTMLTableElement => "dom_html_table_element *", + HTMLTableRowElement => "dom_html_table_row_element *", + HTMLOptionsCollection => "dom_html_options_collection *", ); our %special_prefix = ( DOMString => "dom_string", @@ -53,6 +60,23 @@ our %special_prefix = ( CharacterData => "dom_characterdata", CDATASection => "dom_cdata_section *", HTMLHRElement => "dom_html_hr_element", + HTMLBRElement => "dom_html_br_element", + HTMLLIElement => "dom_html_li_element", + HTMLTableCaptionElement => "dom_html_table_caption_element", + HTMLTableSectionElement => "dom_html_table_section_element", + HTMLIsIndexElement => "dom_html_isindex_element", + HTMLIFrameElement => "dom_html_iframe_element", + caption => "dom_html_table_caption_element *", + section => "dom_html_table_section_element *", + createCaption => "dom_html_element *", + createTHead => "dom_html_element *", + createTFoot => "dom_html_element *", + deleteCaption => "dom_html_element *", + deleteTHead => "dom_html_element *", + deleteTFoot => "dom_html_element *", + insertRow => "dom_html_element *", + deleteRow => "dom_html_element *", + form => "dom_html_form_element *", ); our %unref_prefix = ( @@ -60,6 +84,7 @@ our %unref_prefix = ( NamedNodeMap => "dom_namednodemap", NodeList => "dom_nodelist", HTMLCollection => "dom_html_collection", + HTMLDocument => "dom_html_document", ); our %special_method = ( @@ -67,6 +92,7 @@ our %special_method = ( our %special_attribute = ( namespaceURI => "namespace", + URL => "url", ); our %no_unref = ( @@ -160,10 +186,14 @@ sub new { # The name of the current List/Collection list_name => "", # The number of items of the current List/Collection + list_last_name => [], + # The number of items of the current List/Collection list_num => 0, # Whether List/Collection has members list_hasmem => 0, # The type of the current List/Collection + member_list_declared => 0, + # The type of the current List/Collection list_type => "", # Whether we are in exception assertion exception => 0, @@ -385,6 +415,7 @@ int main(int argc, char **argv) perror("chdir (\\"$self->{chdir})\\""); return 1; } + int list_temp[100], count = -1; __EOF__ } @@ -438,7 +469,6 @@ sub generate_list { # Yes, we are in List/Collection declaration # Firstly, enclose the Array declaration print "};\n"; - # Now, we should create the list * for the List/Collection # Note, we should deal with "int" or "string" type with different params. if ($self->{"list_type"} eq "char *") { @@ -446,18 +476,37 @@ sub generate_list { } if ($self->{"list_type"} eq "int *") { print $self->{"list_name"}." = list_new(INT);\n"; + while(defined ($x = pop @{$self->{"list_last_name"}})) { + print $x." = list_new(INT);\n"; + } + } + while(defined($x = pop(@{$self->{"list_last_name"}}))) { + print $x." = list_new(DOM_STRING);\n"; } + $self->{"member_list_declared"} = 1; if ($self->{"list_type"} eq "") { die "A List/Collection has children member but no type is impossible!"; } - for (my $i = 0; $i < $self->{"list_num"}; $i++) { - # Use *(char **) to convert char *[] to char * - print "list_add(".$self->{"list_name"}.", *(char **)(".$self->{"list_name"}."Array + $i));\n"; + if ($self->{"list_type"} eq "int *") { + + for (my $i = 0; $i < $self->{"list_num"}; $i++) { + # Use *(char **) to convert char *[] to char * + print "list_add(".$self->{"list_name"}.", (int *)(".$self->{"list_name"}."Array) + $i);\n"; + } + } else { + for (my $i = 0; $i < $self->{"list_num"}; $i++) { + # Use *(char **) to convert char *[] to char * + print "list_add(".$self->{"list_name"}.", *(char **)(".$self->{"list_name"}."Array + $i));\n"; + } } } else { if ($self->{"list_name"} ne "") { #TODO: generally, we set the list type as dom_string, but it may be dom_node - print $self->{"list_name"}." = list_new(DOM_STRING);\n"; + if( $self->{"member_list_declared"} eq 1) { + print $self->{"list_name"}." = list_new(DOM_STRING);\n"; + } else { + push(@{$self->{"list_last_name"}}, $self->{"list_name"}); + } $self->{"list_type"} = "DOMString"; } } @@ -476,21 +525,29 @@ sub generate_load { my ($self, $a) = @_; my %ats = %$a; my $doc = $ats{"var"}; - $test_index ++; + my $var = $self->{"var"}; # define the test file path, use HTML if there is, otherwise using XML # Attention: I intend to copy the test files to the program excuting dir print "\tconst char *test$test_index = \"$ats{'href'}.html\";\n\n"; - print "\t$doc = load_html(test$test_index, $ats{'willBeModified'});"; + if ($var->{$doc} eq "Node") { + print "\t$doc = (dom_node*) load_html(test$test_index, $ats{'willBeModified'});"; + } else { + print "\t$doc = load_html(test$test_index, $ats{'willBeModified'});"; + } print "\tif ($doc == NULL) {\n"; $test_index ++; print "\t\tconst char *test$test_index = \"$ats{'href'}.xml\";\n\n"; - print "\t\t$doc = load_xml(test$test_index, $ats{'willBeModified'});\n"; + if ($var->{$doc} eq "Node") { + print "\t\t$doc = (dom_node *) load_xml(test$test_index, $ats{'willBeModified'});\n"; + } else { + print "\t\t$doc = load_xml(test$test_index, $ats{'willBeModified'});\n"; + } print "\t\tif ($doc == NULL)\n"; print "\t\t\treturn 1;\n"; print "\t\t}\n"; print << "__EOF__"; - exp = dom_document_get_implementation($doc, &doc_impl); + exp = dom_document_get_implementation((dom_document *) $doc, &doc_impl); if (exp != DOM_NO_ERR) return exp; __EOF__ @@ -541,14 +598,19 @@ sub generate_framework_statement { if (exists $ats->{"obj"}) { $obj = $ats->{"obj"}; } else { - $obj = $ats->{"item"} + $obj = $ats->{"item"}; } - + if (not $self->{"var"}->{$col} =~ /^(List|Collection)/) { die "Append data to some non-list type!"; } - - print "list_add($col, $obj);\n"; + $type = $self->{"var"}->{$obj}; + if ($type eq "int") { + print "\nlist_temp[++count] =$obj;\n"; + print "list_add($col, &list_temp[count]);\n\n"; + } else { + print "list_add($col, $obj);\n"; + } } case [qw(plus subtract mult divide)] { @@ -669,6 +731,8 @@ sub generate_method { $method = to_cmethod($ats{'interface'}, $en); my $cast = to_attribute_cast($ats{'interface'}); + my $get_attribute = $node->getAttribute("name"); + my $cast_get_attribute = to_get_attribute_cast($get_attribute, $ats{'interface'}); my $ns = $dd->find("parameters/param", $node); my $params = "${cast}$ats{'obj'}"; for ($count = 1; $count <= $ns->size; $count++) { @@ -734,7 +798,7 @@ sub generate_method { # Indicate that we have created a temp node $temp_node = 1; } else { - $params = $params.", (void *) \&$ats{'var'}"; + $params = $params.", $cast_get_attribute\&$ats{'var'}"; $unref = $self->param_unref($ats{'var'}); } } @@ -796,6 +860,8 @@ sub generate_attribute_fetcher { my $fetcher = to_attribute_fetcher($ats{'interface'}, "$en"); my $cast = to_attribute_cast($ats{'interface'}); + my $get_attribute = $node->getAttribute("name"); + my $cast_get_attribute = to_get_attribute_cast($get_attribute, $ats{'interface'}); my $unref = 0; my $temp_node = 0; # Deal with the situation like @@ -821,7 +887,7 @@ sub generate_attribute_fetcher { $temp_node = 1; } else { $unref = $self->param_unref($ats{'var'}); - print "\texp = $fetcher(${cast}$ats{'obj'}, \&$ats{'var'});\n"; + print "\texp = $fetcher(${cast}$ats{'obj'}, ${cast_get_attribute}\&$ats{'var'});\n"; } @@ -1146,7 +1212,7 @@ sub generate_assertion { $fragment = $ats->{fragment}; } if (exists $ats->{isAbsolute}) { - $isAbsolute = $ats->{isAbsolute}; + $isAbsolute = "\"$ats->{isAbsolute}\""; } print "is_uri_equals($scheme, $path, $host, $file, $name, $query, $fragment, $isAbsolute, $actual)" @@ -1412,7 +1478,30 @@ sub get_prefix { } return $prefix; } +sub to_get_attribute_cast { + my $type = shift; + my $interface = shift; + my $ret = get_get_attribute_prefix($type, $interface); + if($ret eq "") { + return $ret; + } + $ret =~ s/h_t_m_l/html/; + return "(${ret} *)"; +} + +sub get_get_attribute_prefix { + my $type = shift; + my $interface = shift; + if ($type eq "length") { + $prefix = "uint32_t "; + } elsif (exists $special_prefix{$type}) { + $prefix = $special_prefix{$type}; + } else { + $prefix = ""; + } + return $prefix; +} # This function remain unsed sub get_suffix { my $type = shift; |