~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to pidl/tests/ndr_string.pl

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# String tests for pidl
 
3
# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
 
4
# Published under the GNU General Public License
 
5
use strict;
 
6
 
 
7
use Test::More tests => 3 * 8;
 
8
use FindBin qw($RealBin);
 
9
use lib "$RealBin";
 
10
use Util qw(test_samba4_ndr);
 
11
 
 
12
test_samba4_ndr("string-pull-empty", 
 
13
' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
 
14
'
 
15
        uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
 
16
        DATA_BLOB b = { data, 4 };
 
17
        struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, 
 
18
                smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
 
19
        struct TestString r;
 
20
        r.in.data = NULL;
 
21
 
 
22
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
 
23
                return 1;
 
24
        
 
25
        if (r.in.data == NULL)
 
26
                return 2;
 
27
 
 
28
        if (r.in.data[0] != 0)
 
29
                return 3;
 
30
');
 
31
 
 
32
test_samba4_ndr("string-ascii-pull", 
 
33
'
 
34
        [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);
 
35
',
 
36
'
 
37
        uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 
 
38
                                           \'f\', \'o\', \'o\', 0 };
 
39
        DATA_BLOB b = { data, 8 };
 
40
        struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
 
41
                smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
 
42
        struct TestString r;
 
43
        r.in.data = NULL;
 
44
 
 
45
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
 
46
                return 1;
 
47
        
 
48
        if (r.in.data == NULL)
 
49
                return 2;
 
50
 
 
51
        if (strncmp(r.in.data, "foo", 3) != 0)
 
52
                return 3;
 
53
 
 
54
        if (r.in.data[4] != 0)
 
55
                return 4;
 
56
');
 
57
 
 
58
SKIP: {
 
59
        skip "doesn't seem to work yet", 8;
 
60
 
 
61
test_samba4_ndr("string-out", 
 
62
'
 
63
        [public] void TestString([out,string,charset(UNIX)] uint8 **data);
 
64
',
 
65
'
 
66
        uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 
 
67
                                           \'f\', \'o\', \'o\', 0 };
 
68
        DATA_BLOB b = { data, 8 };
 
69
        struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
 
70
                smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
 
71
        struct TestString r;
 
72
        char *str = NULL;
 
73
        r.out.data = &str;
 
74
 
 
75
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
 
76
                return 1;
 
77
 
 
78
        if (r.out.data == NULL)
 
79
                return 2;
 
80
 
 
81
        if (*r.out.data == NULL)
 
82
                return 3;
 
83
 
 
84
        if (strncmp(r.out.data, "foo", 3) != 0)
 
85
                return 4;
 
86
 
 
87
        if (r.out.data[4] != 0)
 
88
                return 5;
 
89
');
 
90
}