1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-28 17:47:29 +03:00
Jelmer Vernooij 4e757aa64c r21457: Cope with anonymous nested types in the NDR layer. This doesn't handled
named nested types yet, as these have to be registered.
(This used to be commit 9b0416b5d06286c81c73477a24cb591fd4b23d18)
2007-10-10 14:48:38 -05:00

206 lines
3.7 KiB
Perl
Executable File

#!/usr/bin/perl
# (C) 2007 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
use strict;
use warnings;
use Test::More tests => 12;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement);
# Case 1
my $e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => {},
'POINTERS' => 0,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'STRUCT' },
'LINE' => 42 };
is_deeply(GetElementLevelTable($e), [
{
'IS_DEFERRED' => 0,
'LEVEL_INDEX' => 0,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
my $ne = ParseElement($e, undef);
is($ne->{ORIGINAL}, $e);
is($ne->{NAME}, "v");
is($ne->{ALIGN}, 1);
is($ne->{TYPE}, "uint8");
is_deeply($ne->{LEVELS}, [
{
'IS_DEFERRED' => 0,
'LEVEL_INDEX' => 0,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
# Case 2 : pointers
#
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => {"unique" => 1},
'POINTERS' => 1,
'PARENT' => { TYPE => 'STRUCT' },
'TYPE' => 'uint8',
'LINE' => 42 };
is_deeply(GetElementLevelTable($e), [
{
LEVEL_INDEX => 0,
IS_DEFERRED => 0,
TYPE => 'POINTER',
POINTER_TYPE => "unique",
POINTER_INDEX => 0,
LEVEL => 'EMBEDDED'
},
{
'IS_DEFERRED' => 1,
'LEVEL_INDEX' => 1,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
# Case 3 : double pointers
#
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => {"unique" => 1},
'POINTERS' => 2,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'STRUCT' },
'LINE' => 42 };
is_deeply(GetElementLevelTable($e), [
{
LEVEL_INDEX => 0,
IS_DEFERRED => 0,
TYPE => 'POINTER',
POINTER_TYPE => "unique",
POINTER_INDEX => 0,
LEVEL => 'EMBEDDED'
},
{
LEVEL_INDEX => 1,
IS_DEFERRED => 1,
TYPE => 'POINTER',
POINTER_TYPE => "unique",
POINTER_INDEX => 1,
LEVEL => 'EMBEDDED'
},
{
'IS_DEFERRED' => 1,
'LEVEL_INDEX' => 2,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
# Case 3 : ref pointers
#
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => {"ref" => 1},
'POINTERS' => 1,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'STRUCT' },
'LINE' => 42 };
is_deeply(GetElementLevelTable($e), [
{
LEVEL_INDEX => 0,
IS_DEFERRED => 0,
TYPE => 'POINTER',
POINTER_TYPE => "ref",
POINTER_INDEX => 0,
LEVEL => 'EMBEDDED'
},
{
'IS_DEFERRED' => 1,
'LEVEL_INDEX' => 1,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
# Case 4 : top-level ref pointers
#
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => {"ref" => 1},
'POINTERS' => 1,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'FUNCTION' },
'LINE' => 42 };
is_deeply(GetElementLevelTable($e), [
{
LEVEL_INDEX => 0,
IS_DEFERRED => 0,
TYPE => 'POINTER',
POINTER_TYPE => "ref",
POINTER_INDEX => 0,
LEVEL => 'TOP'
},
{
'IS_DEFERRED' => 0,
'LEVEL_INDEX' => 1,
'DATA_TYPE' => 'uint8',
'CONTAINS_DEFERRED' => 0,
'TYPE' => 'DATA',
'IS_SURROUNDING' => 0,
}
]);
# representation_type
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => { represent_as => "bar" },
'POINTERS' => 0,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'STRUCT' },
'LINE' => 42 };
$ne = ParseElement($e, undef);
is($ne->{REPRESENTATION_TYPE}, "bar");
# representation_type
$e = {
'FILE' => 'foo.idl',
'NAME' => 'v',
'PROPERTIES' => { },
'POINTERS' => 0,
'TYPE' => 'uint8',
'PARENT' => { TYPE => 'STRUCT' },
'LINE' => 42 };
$ne = ParseElement($e, undef);
is($ne->{REPRESENTATION_TYPE}, "uint8");