1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +03:00

r25166: Simplify can_contain_deferred and add tests for it.

This commit is contained in:
Jelmer Vernooij 2007-09-14 18:06:51 +00:00 committed by Gerald (Jerry) Carter
parent 5bb8613b86
commit 1afc7dd4d3
2 changed files with 28 additions and 19 deletions

View File

@ -35,7 +35,7 @@ use vars qw($VERSION);
$VERSION = '0.01';
@ISA = qw(Exporter);
@EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType);
@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred);
use strict;
use Parse::Pidl qw(warning fatal);
@ -264,7 +264,7 @@ sub GetElementLevelTable($)
TYPE => "DATA",
DATA_TYPE => $e->{TYPE},
IS_DEFERRED => $is_deferred,
CONTAINS_DEFERRED => can_contain_deferred($e),
CONTAINS_DEFERRED => can_contain_deferred($e->{TYPE}),
IS_SURROUNDING => 0 #FIXME
});
@ -279,29 +279,25 @@ sub GetElementLevelTable($)
sub can_contain_deferred($)
{
sub can_contain_deferred($);
my $e = shift;
my ($type) = @_;
return 0 if (Parse::Pidl::Typelist::is_scalar($e->{TYPE}));
return 1 unless (hasType($e->{TYPE})); # assume the worst
return 1 unless (hasType($type)); # assume the worst
my $type = getType($e->{TYPE});
$type = getType($type);
return 0 if (Parse::Pidl::Typelist::is_scalar($type));
return 1 if ($type->{TYPE} eq "DECLARE"); # assume the worst
if ($type->{TYPE} eq "TYPEDEF") {
return 0 unless defined($type->{DATA}->{ELEMENTS});
return can_contain_deferred($type->{DATA});
}
foreach my $x (@{$type->{DATA}->{ELEMENTS}}) {
return 1 if ($x->{POINTERS});
return 1 if (can_contain_deferred ($x));
}
} else {
return 0 unless defined($type->{ELEMENTS});
return 0 unless defined($type->{ELEMENTS});
foreach my $x (@{$type->{ELEMENTS}}) {
return 1 if ($x->{POINTERS});
return 1 if (can_contain_deferred ($x));
}
foreach my $x (@{$type->{ELEMENTS}}) {
return 1 if ($x->{POINTERS});
return 1 if (can_contain_deferred ($x));
}
return 0;

View File

@ -4,12 +4,12 @@
use strict;
use warnings;
use Test::More tests => 27;
use Test::More tests => 33;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType);
use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType can_contain_deferred);
# Case 1
@ -253,3 +253,16 @@ $t = {
}
};
is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t);
ok(not can_contain_deferred("uint32"));
ok(can_contain_deferred("some_unknown_type"));
ok(can_contain_deferred({ TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "uint32", POINTERS => 40 } ]}));
ok(can_contain_deferred({ TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "uint32", POINTERS => 40 } ]}}));
ok(not can_contain_deferred({ TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "uint32" } ]}));
ok(not can_contain_deferred({ TYPE => "TYPEDEF",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "uint32" } ]}}));