s4-drs: do not try to contact for replication servers that are not anymore in reps*
[Samba/gebeck_regimport.git] / pidl / tests / header.pl
blobdb5948444462818db62f4207d58acd9c5148e71f
1 #!/usr/bin/perl
2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
4 use strict;
5 use warnings;
7 use Test::More tests => 27;
8 use FindBin qw($RealBin);
9 use lib "$RealBin";
10 use Util;
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse::Pidl::Samba4::Header qw(
13 GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
14 EnvSubstituteValue);
15 use Parse::Pidl::IDL qw(parse_string);
16 use Parse::Pidl::NDR;
18 sub parse_idl($)
20 my $text = shift;
21 my $idl = Parse::Pidl::IDL::parse_string($text, "nofile");
22 my $ndr = Parse::Pidl::NDR::Parse($idl);
23 return Parse::Pidl::Samba4::Header::Parse($ndr);
26 like(parse_idl(""), qr/\/\* header auto-generated by pidl \*\/\n/sm, "includes work");
27 like(parse_idl("interface x {}"), qr/\/\* header auto-generated by pidl \*\/\n/sm, "simple empty interface doesn't cause overhead");
28 like(parse_idl("interface p { typedef struct { int y; } x; };"),
29 qr/.*#ifndef _HEADER_p\n#define _HEADER_p\n.+\n#endif \/\* _HEADER_p \*\/.*/ms, "ifdefs are created");
30 like(parse_idl("interface p { typedef struct { int y; } x; };"),
31 qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");
32 like(parse_idl("interface x { void foo (void); };"),
33 qr/struct foo.*{\s+int _dummy_element;\s+};/sm, "void fn contains dummy element");
34 like(parse_idl("interface x { void foo ([in] uint32 x); };"),
35 qr/struct foo.*{\s+struct\s+{\s+uint32_t x;\s+} in;\s+};/sm, "fn in arg works");
36 like(parse_idl("interface x { void foo ([out] uint32 x); };"),
37 qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn out arg works");
38 like(parse_idl("interface x { void foo ([in,out] uint32 x); };"),
39 qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn in,out arg works");
40 like(parse_idl("interface x { void foo (uint32 x); };"), qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn with no props implies in,out");
41 like(parse_idl("interface p { struct x { int y; }; };"),
42 qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");
44 like(parse_idl("interface p { struct x { struct y z; }; };"),
45 qr/struct x.*{.*struct y z;.*}.*;/sm, "tagged type struct member");
47 like(parse_idl("interface p { struct x { union y z; }; };"),
48 qr/struct x.*{.*union y z;.*}.*;/sm, "tagged type union member");
50 like(parse_idl("interface p { struct x { }; };"),
51 qr/struct x.*{.*char _empty_;.*}.*;/sm, "empty struct");
53 like(parse_idl("interface p { struct x; };"),
54 qr/struct x;/sm, "struct declaration");
56 like(parse_idl("interface p { typedef struct x { int p; } x; };"),
57 qr/struct x.*{.*int32_t p;.*};/sm, "double struct declaration");
59 like(parse_idl("cpp_quote(\"some-foo\")"),
60 qr/some-foo/sm, "cpp quote");
62 # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
63 my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
64 is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
66 $fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
67 is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
69 $fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
70 is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
72 $fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
73 is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
75 $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
76 is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn));
78 $fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
79 is_deeply({ }, GenerateFunctionInEnv($fn));
81 $fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
82 is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" },
83 GenerateStructEnv($fn, "r"));
85 $fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
86 is_deeply({ foo => "some->complex.variable->foo",
87 bar => "some->complex.variable->bar",
88 this => "some->complex.variable" },
89 GenerateStructEnv($fn, "some->complex.variable"));
91 $fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] };
93 my $env = GenerateStructEnv($fn, "r");
94 EnvSubstituteValue($env, $fn);
95 is_deeply($env, { foo => 3, this => "r" });
97 $fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] };
98 $env = GenerateStructEnv($fn, "r");
99 EnvSubstituteValue($env, $fn);
100 is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" });
102 $fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] };
104 $env = GenerateStructEnv($fn, "r");
105 EnvSubstituteValue($env, $fn);
106 is_deeply($env, { foo => 0, this => "r" });