Merge branch 'master' of ssh://git.samba.org/data/git/samba
[ira/wip.git] / pidl / tests / ndr_represent.pl
1 #!/usr/bin/perl
2 # NDR represent_as() / transmit_as() tests
3 # (C) 2006 Jelmer Vernooij. Published under the GNU GPL
4 use strict;
5
6 use Test::More tests => 2 * 8;
7 use FindBin qw($RealBin);
8 use lib "$RealBin";
9 use Util qw(test_samba4_ndr);
10
11 test_samba4_ndr('represent_as-simple', 
12 '
13         void bla([in,represent_as(uint32)] uint8 x);
14 ',
15 '
16         uint8_t expected[] = { 0x0D };
17         DATA_BLOB in_blob = { expected, 1 };
18         struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL, NULL);
19         struct bla r;
20
21         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
22                 return 1;
23
24         if (r.in.x != 13)
25                 return 2;
26 ',
27 '
28 enum ndr_err_code ndr_uint8_to_uint32(uint8_t from, uint32_t *to)
29 {
30         *to = from;
31         return NDR_ERR_SUCCESS;
32 }
33
34 enum ndr_err_code ndr_uint32_to_uint8(uint32_t from, uint8_t *to)
35 {
36         *to = from;
37         return NDR_ERR_SUCCESS;
38 }
39 '
40 );
41
42 test_samba4_ndr('transmit_as-simple', 
43 '
44         void bla([in,transmit_as(uint32)] uint8 x);
45 ',
46 '
47         uint8_t expected[] = { 0x0D };
48         DATA_BLOB in_blob = { expected, 1 };
49         struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL, NULL);
50         struct bla r;
51
52         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
53                 return 1;
54
55         if (r.in.x != 13)
56                 return 2;
57 ',
58 '
59 enum ndr_err_code ndr_uint8_to_uint32(uint8_t from, uint32_t *to)
60 {
61         *to = from;
62         return NDR_ERR_SUCCESS;
63 }
64
65 enum ndr_err_code ndr_uint32_to_uint8(uint32_t from, uint8_t *to)
66 {
67         *to = from;
68         return NDR_ERR_SUCCESS;
69 }
70 '
71 );