r22456: Merge wireshark and ejs test improvements.
[samba.git] / source4 / pidl / tests / samba-ejs.pl
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;
6
7 use Test::More tests => 17;
8 use FindBin qw($RealBin);
9 use lib "$RealBin";
10 use Util;
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer
13         fn_declare TypeFunctionName);
14
15 is("&foo", get_pointer_to("foo"));
16 is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
17 is("*foo", get_pointer_to("**foo"));
18 is("foo", get_pointer_to("*foo"));
19
20 is("foo", get_value_of("&foo"));
21 is("*foo", get_value_of("foo"));
22 is("**foo", get_value_of("*foo"));
23
24 my $ejs = new Parse::Pidl::Samba4::EJS();
25
26 $ejs->check_null_pointer("bla");
27 is($ejs->{res}, "");
28
29 $ejs = new Parse::Pidl::Samba4::EJS();
30 $ejs->check_null_pointer("*bla");
31 is($ejs->{res}, "if (bla == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;\n");
32
33 $ejs = new Parse::Pidl::Samba4::EJS();
34 $ejs->fn_declare({ PROPERTIES => { public => 1 } }, "myproto(int x)");
35 is($ejs->{res}, "_PUBLIC_ myproto(int x)\n");
36 is($ejs->{res_hdr}, "myproto(int x);\n");
37
38 $ejs = new Parse::Pidl::Samba4::EJS();
39 $ejs->fn_declare({ PROPERTIES => {} }, "mybla(int foo)");
40 is($ejs->{res}, "static mybla(int foo)\n");
41 is($ejs->{res_hdr}, "");
42
43 is(TypeFunctionName("ejs_pull", "uint32"), "ejs_pull_uint32");
44 is(TypeFunctionName("ejs_pull", {TYPE => "ENUM", NAME => "bar"}), "ejs_pull_ENUM_bar");
45 is(TypeFunctionName("ejs_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef}), "ejs_pull_bar");
46 is(TypeFunctionName("ejs_push", {TYPE => "STRUCT", NAME => "bar"}), "ejs_push_STRUCT_bar");