summaryrefslogtreecommitdiff
path: root/source4/pidl/tests/ndr_string.pl
blob: e8e37be8c1cfdc43872ff78c1f30c06b18119185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
# String tests for pidl
# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
use strict;

use Test::More tests => 2 * 8;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use lib "$RealBin";
use Util qw(test_samba4_ndr);

test_samba4_ndr("string-pull-empty", 
' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
'
	uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
	DATA_BLOB b = { data, 4 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestString r;
	r.in.data = NULL;

	if (NT_STATUS_IS_ERR(ndr_pull_TestString(ndr, NDR_IN, &r))) 
		return 1;
	
	if (r.in.data == NULL)
		return 2;

	if (r.in.data[0] != 0)
		return 3;
');

test_samba4_ndr("string-ascii-pull", 
'
	[public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);
',
'
	uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 
					   \'f\', \'o\', \'o\', 0 };
	DATA_BLOB b = { data, 8 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestString r;
	r.in.data = NULL;

	if (NT_STATUS_IS_ERR(ndr_pull_TestString(ndr, NDR_IN, &r))) 
		return 1;
	
	if (r.in.data == NULL)
		return 2;

	if (strncmp(r.in.data, "foo", 3) != 0)
		return 3;

	if (r.in.data[4] != 0)
		return 4;
');