pidl/tests: Add tests for hang with nested struct.
authorNoel Power <noel.power@suse.com>
Mon, 25 Aug 2014 10:53:30 +0000 (11:53 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 5 Sep 2023 21:18:32 +0000 (21:18 +0000)
make sure hang test calls Parse::Pidl::Typelist::LoadIdl which triggers
part of the hang

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
pidl/tests/header.pl

index db5948444462818db62f4207d58acd9c5148e71f..dc8bbd7a2938ae3ab644df913344708fc52bcd62 100755 (executable)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 27;
+use Test::More tests => 30;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -23,6 +23,16 @@ sub parse_idl($)
        return Parse::Pidl::Samba4::Header::Parse($ndr);
 }
 
+sub load_and_parse_idl($)
+{
+       my $text = shift;
+       my $ndr;
+       my $idl = Parse::Pidl::IDL::parse_string($text, "nofile");
+       Parse::Pidl::Typelist::LoadIdl($idl, "noname");
+       $ndr = Parse::Pidl::NDR::Parse($idl);
+       return Parse::Pidl::Samba4::Header::Parse($ndr);
+}
+
 like(parse_idl(""), qr/\/\* header auto-generated by pidl \*\/\n/sm, "includes work");
 like(parse_idl("interface x {}"), qr/\/\* header auto-generated by pidl \*\/\n/sm,  "simple empty interface doesn't cause overhead");
 like(parse_idl("interface p { typedef struct { int y; } x; };"),
@@ -59,6 +69,15 @@ like(parse_idl("interface p { typedef struct x { int p; } x; };"),
 like(parse_idl("cpp_quote(\"some-foo\")"),
        qr/some-foo/sm, "cpp quote");
 
+like(load_and_parse_idl("interface hang {typedef [public] struct { wsp_cbasestoragevariant a[SINGLE]; } foo; typedef [public,nodiscriminant,switch_type(uint16)] union { [case(VT_I1)] int8 vt_i1; [case(VT_VARIANT)] foo b; } variant_types; typedef [public] struct { [switch_is(vtype)] variant_types vvalue; } bar;};"),
+     qr/struct foo.*{.*struct wsp_cbasestoragevariant \*a.*struct bar \{.*union variant_types vvalue.*;/sm,"test for hang with nested struct with union");
+
+like(load_and_parse_idl("interface hang { typedef struct { uint32 count; bar a[count];} foo ; typedef struct { foo b; } bar; };"),
+     qr/struct foo.*{.*struct bar \*a;/sm,"test for hang with nested struct");
+
+like(load_and_parse_idl("interface hang { typedef struct { bar a; } foo ; typedef struct { foo b; } bar; };"),
+     qr/struct foo.*{.*struct bar a;/sm,"test for hang with uncompilable nested struct");
+
 # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
 my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
 is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));