summaryrefslogtreecommitdiff
path: root/source4/pidl/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-22 16:39:56 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-01-22 16:39:56 +0100
commit4075a2ba982ea56ff925e0a33839f0760fd71911 (patch)
tree87d87734257f814b7960a843e54455c447f34a9e /source4/pidl/tests
parent24da29746998de1001d18871dcbe8d37643667d5 (diff)
parent35c68316442808a135aafa864d19592108a4d879 (diff)
downloadsamba-4075a2ba982ea56ff925e0a33839f0760fd71911.tar.gz
samba-4075a2ba982ea56ff925e0a33839f0760fd71911.tar.bz2
samba-4075a2ba982ea56ff925e0a33839f0760fd71911.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-python
(This used to be commit 2f57e25f8f692889d9e057e13256f8a24c5ec10c)
Diffstat (limited to 'source4/pidl/tests')
-rwxr-xr-xsource4/pidl/tests/cutil.pl21
-rwxr-xr-xsource4/pidl/tests/header.pl54
-rwxr-xr-xsource4/pidl/tests/ndr.pl17
-rwxr-xr-xsource4/pidl/tests/parse_idl.pl34
-rwxr-xr-xsource4/pidl/tests/samba-ejs.pl13
-rwxr-xr-xsource4/pidl/tests/samba-ndr.pl51
-rwxr-xr-xsource4/pidl/tests/samba3-cli.pl71
-rw-r--r--source4/pidl/tests/samba3-srv.pl18
-rwxr-xr-xsource4/pidl/tests/typelist.pl8
9 files changed, 193 insertions, 94 deletions
diff --git a/source4/pidl/tests/cutil.pl b/source4/pidl/tests/cutil.pl
new file mode 100755
index 0000000000..78c8bce45e
--- /dev/null
+++ b/source4/pidl/tests/cutil.pl
@@ -0,0 +1,21 @@
+#!/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 => 7;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper);
+use Parse::Pidl::CUtil qw(get_pointer_to get_value_of);
+
+is("&foo", get_pointer_to("foo"));
+is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
+is("*foo", get_pointer_to("**foo"));
+is("foo", get_pointer_to("*foo"));
+
+is("foo", get_value_of("&foo"));
+is("*foo", get_value_of("foo"));
+is("**foo", get_value_of("*foo"));
diff --git a/source4/pidl/tests/header.pl b/source4/pidl/tests/header.pl
index 8d0dccf507..db59484444 100755
--- a/source4/pidl/tests/header.pl
+++ b/source4/pidl/tests/header.pl
@@ -4,12 +4,14 @@
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 27;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::Samba4::Header;
+use Parse::Pidl::Samba4::Header qw(
+ GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
+ EnvSubstituteValue);
use Parse::Pidl::IDL qw(parse_string);
use Parse::Pidl::NDR;
@@ -56,3 +58,51 @@ like(parse_idl("interface p { typedef struct x { int p; } x; };"),
like(parse_idl("cpp_quote(\"some-foo\")"),
qr/some-foo/sm, "cpp quote");
+
+# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
+my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
+is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" },
+ GenerateStructEnv($fn, "r"));
+
+$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
+is_deeply({ foo => "some->complex.variable->foo",
+ bar => "some->complex.variable->bar",
+ this => "some->complex.variable" },
+ GenerateStructEnv($fn, "some->complex.variable"));
+
+$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] };
+
+my $env = GenerateStructEnv($fn, "r");
+EnvSubstituteValue($env, $fn);
+is_deeply($env, { foo => 3, this => "r" });
+
+$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
+$env = GenerateStructEnv($fn, "r");
+EnvSubstituteValue($env, $fn);
+is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" });
+
+$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] };
+
+$env = GenerateStructEnv($fn, "r");
+EnvSubstituteValue($env, $fn);
+is_deeply($env, { foo => 0, this => "r" });
+
+
diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl
index 1512f19d52..7fcc7ef40e 100755
--- a/source4/pidl/tests/ndr.pl
+++ b/source4/pidl/tests/ndr.pl
@@ -4,7 +4,7 @@
use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 40;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@@ -212,9 +212,16 @@ is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
ELEMENTS => [ { TYPE => "uint16" } ] }), 4);
is(align_type({ TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "hyper" } ] }), 8);
-is(align_type({ TYPE => "DECLARE", DATA => {
+is(align_type({ TYPE => "TYPEDEF", DATA => {
TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "hyper" } ] }}), 8);
+# typedef of struct without body
+is(align_type({ TYPE => "TYPEDEF", DATA => {
+ TYPE => "STRUCT", ELEMENTS => undef }}), 4);
+# struct without body
+is(align_type({ TYPE => "STRUCT", ELEMENTS => undef }), 4);
+# empty struct
+is(align_type({ TYPE => "STRUCT", ELEMENTS => [] }), 1);
is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
ELEMENTS => [ { TYPE => "uint8" } ] }), 4);
@@ -268,3 +275,9 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF",
ELEMENTS => [ { TYPE => "uint32" } ]}}));
ok(can_contain_deferred({ TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "someunknowntype" } ]}));
+# Make sure the elements for a enum without body aren't filled in
+ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS}));
+# Make sure the elements for a bitmap without body aren't filled in
+ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS}));
+# Make sure the elements for a union without body aren't filled in
+ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref")->{ELEMENTS}));
diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl
index 96c7b2adc8..9d43ddccc7 100755
--- a/source4/pidl/tests/parse_idl.pl
+++ b/source4/pidl/tests/parse_idl.pl
@@ -4,7 +4,7 @@
# Published under the GNU General Public License
use strict;
-use Test::More tests => 65 * 2 + 3;
+use Test::More tests => 65 * 2 + 7;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util qw(test_errors);
@@ -129,4 +129,36 @@ is_deeply($x,
[ { 'FILE' => '<quote>', 'DATA' => '"foobar"',
'TYPE' => 'CPP_QUOTE', 'LINE' => 0 } ]);
+# A typedef of a struct without body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct x y; }", "<foo>");
+is_deeply($x,
+ [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
+ { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => {
+ TYPE => 'STRUCT', NAME => 'x' } } ],
+ 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);
+
+# A typedef of a struct with empty body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct {} y; }", "<foo>");
+
+is_deeply($x,
+ [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
+ { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'STRUCT', ELEMENTS => [] } } ],
+ 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);
+
+# A typedef of a bitmap with no body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef bitmap x y; }", "<foo>");
+
+is_deeply($x,
+ [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
+ { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'BITMAP', NAME => 'x' } } ],
+ 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);
+
+
+# A typedef of a union with no body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef union x y; }", "<foo>");
+
+is_deeply($x,
+ [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [
+ { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'UNION', NAME => 'x' } } ],
+ 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);
diff --git a/source4/pidl/tests/samba-ejs.pl b/source4/pidl/tests/samba-ejs.pl
index adc00e224f..094d37a103 100755
--- a/source4/pidl/tests/samba-ejs.pl
+++ b/source4/pidl/tests/samba-ejs.pl
@@ -4,23 +4,14 @@
use strict;
use warnings;
-use Test::More tests => 17;
+use Test::More tests => 10;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer
+use Parse::Pidl::Samba4::EJS qw(check_null_pointer
fn_declare TypeFunctionName);
-is("&foo", get_pointer_to("foo"));
-is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
-is("*foo", get_pointer_to("**foo"));
-is("foo", get_pointer_to("*foo"));
-
-is("foo", get_value_of("&foo"));
-is("*foo", get_value_of("foo"));
-is("**foo", get_value_of("*foo"));
-
my $ejs = new Parse::Pidl::Samba4::EJS();
$ejs->check_null_pointer("bla");
diff --git a/source4/pidl/tests/samba-ndr.pl b/source4/pidl/tests/samba-ndr.pl
index 05c3c1c0df..a14111961f 100755
--- a/source4/pidl/tests/samba-ndr.pl
+++ b/source4/pidl/tests/samba-ndr.pl
@@ -4,15 +4,14 @@
use strict;
use warnings;
-use Test::More tests => 41;
+use Test::More tests => 30;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use strict;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
- GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
- EnvSubstituteValue NeededFunction NeededElement NeededType
+ NeededFunction NeededElement NeededType
NeededInterface TypeFunctionName ParseElementPrint);
my $output;
@@ -138,52 +137,6 @@ test_warnings("nofile:2: unknown dereferenced expression `r->in.bla'\n",
is($output, "if (r->in.bla == NULL) return;");
-# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
-$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
-is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
-
-$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
-is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
-
-$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
-is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
-
-$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
-is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
-
-$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
-is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn));
-
-$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
-is_deeply({ }, GenerateFunctionInEnv($fn));
-
-$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
-is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" },
- GenerateStructEnv($fn, "r"));
-
-$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
-is_deeply({ foo => "some->complex.variable->foo",
- bar => "some->complex.variable->bar",
- this => "some->complex.variable" },
- GenerateStructEnv($fn, "some->complex.variable"));
-
-$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] };
-
-my $env = GenerateStructEnv($fn, "r");
-EnvSubstituteValue($env, $fn);
-is_deeply($env, { foo => 3, this => "r" });
-
-$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
-$env = GenerateStructEnv($fn, "r");
-EnvSubstituteValue($env, $fn);
-is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" });
-
-$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] };
-
-$env = GenerateStructEnv($fn, "r");
-EnvSubstituteValue($env, $fn);
-is_deeply($env, { foo => 0, this => "r" });
-
my $needed = {};
NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed);
is_deeply($needed, { ndr_pull_foo => 1 });
diff --git a/source4/pidl/tests/samba3-cli.pl b/source4/pidl/tests/samba3-cli.pl
index 5086300e46..f5b51b7d34 100755
--- a/source4/pidl/tests/samba3-cli.pl
+++ b/source4/pidl/tests/samba3-cli.pl
@@ -10,7 +10,7 @@ use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba3::ClientNDR qw(ParseFunction);
-use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv GenerateFunctionOutEnv);
+use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv);
# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
@@ -29,31 +29,40 @@ my $x = new Parse::Pidl::Samba3::ClientNDR();
$fn = { NAME => "bar", ELEMENTS => [ ] };
$x->ParseFunction("foo", $fn);
-is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx)
+is($x->{res},
+"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx)
{
\tstruct bar r;
\tNTSTATUS status;
-\t
+
\t/* In parameters */
-\t
-\tif (DEBUGLEVEL >= 10)
+
+\tif (DEBUGLEVEL >= 10) {
\t\tNDR_PRINT_IN_DEBUG(bar, &r);
-\t
-\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r);
-\t
+\t}
+
+ status = cli_do_rpc_ndr(cli,
+ mem_ctx,
+ PI_FOO,
+ &ndr_table_foo,
+ NDR_BAR,
+ &r);
+
\tif (!NT_STATUS_IS_OK(status)) {
\t\treturn status;
\t}
-\t
-\tif (DEBUGLEVEL >= 10)
+
+\tif (DEBUGLEVEL >= 10) {
\t\tNDR_PRINT_OUT_DEBUG(bar, &r);
-\t
+\t}
+
\tif (NT_STATUS_IS_ERR(status)) {
\t\treturn status;
\t}
-\t
+
\t/* Return variables */
-\t
+
\t/* Return result */
\treturn NT_STATUS_OK;
}
@@ -64,36 +73,46 @@ $x = new Parse::Pidl::Samba3::ClientNDR();
$fn = { NAME => "bar", ELEMENTS => [ ], RETURN_TYPE => "WERROR" };
$x->ParseFunction("foo", $fn);
-is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, WERROR *werror)
+is($x->{res},
+"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx,
+ WERROR *werror)
{
\tstruct bar r;
\tNTSTATUS status;
-\t
+
\t/* In parameters */
-\t
-\tif (DEBUGLEVEL >= 10)
+
+\tif (DEBUGLEVEL >= 10) {
\t\tNDR_PRINT_IN_DEBUG(bar, &r);
-\t
-\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r);
-\t
+\t}
+
+ status = cli_do_rpc_ndr(cli,
+ mem_ctx,
+ PI_FOO,
+ &ndr_table_foo,
+ NDR_BAR,
+ &r);
+
\tif (!NT_STATUS_IS_OK(status)) {
\t\treturn status;
\t}
-\t
-\tif (DEBUGLEVEL >= 10)
+
+\tif (DEBUGLEVEL >= 10) {
\t\tNDR_PRINT_OUT_DEBUG(bar, &r);
-\t
+\t}
+
\tif (NT_STATUS_IS_ERR(status)) {
\t\treturn status;
\t}
-\t
+
\t/* Return variables */
-\t
+
\t/* Return result */
\tif (werror) {
\t\t*werror = r.out.result;
\t}
-\t
+
\treturn werror_to_ntstatus(r.out.result);
}
diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl
new file mode 100644
index 0000000000..d1e2bc9545
--- /dev/null
+++ b/source4/pidl/tests/samba3-srv.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+# (C) 2008 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU General Public License
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper has_property);
+use Parse::Pidl::Samba3::ServerNDR qw(DeclLevel);
+
+my $l = { TYPE => "DATA", DATA_TYPE => "uint32" };
+my $e = { FILE => "foo", LINE => 0, PROPERTIES => { }, TYPE => "uint32",
+ LEVELS => [ $l ] };
+
+is("uint32_t", DeclLevel($e, 0));
diff --git a/source4/pidl/tests/typelist.pl b/source4/pidl/tests/typelist.pl
index c5c409a525..54f4d34586 100755
--- a/source4/pidl/tests/typelist.pl
+++ b/source4/pidl/tests/typelist.pl
@@ -4,11 +4,11 @@
use strict;
use warnings;
-use Test::More tests => 53;
+use Test::More tests => 54;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
-use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias
+use Parse::Pidl::Typelist qw(hasType typeHasBody getType mapTypeName expandAlias
mapScalarType addType typeIs is_scalar scalar_is_reference
enum_type_fn bitmap_type_fn mapType);
@@ -56,7 +56,6 @@ is(1, is_scalar({TYPE => "ENUM"}));
is(0, is_scalar({TYPE => "STRUCT"}));
is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }}));
is(1, is_scalar("mytypedef"));
-is(1, is_scalar({TYPE => "DECLARE", DATA => {TYPE => "ENUM" }}));
is(1, scalar_is_reference("string"));
is(0, scalar_is_reference("uint32"));
@@ -81,3 +80,6 @@ is("uint32_t", mapType({TYPE => "TYPEDEF", DATA => {TYPE => "SCALAR"}}, "uint32"
is("void", mapTypeName(undef));
is("uint32_t", mapTypeName("uint32"));
is("int32_t", mapTypeName("int"));
+
+ok(not typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT" }}));
+ok(typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [] }}));