r21653: Add two more tdr tests.
[Samba/ekacnet.git] / source4 / torture / local / tdr.c
blob64d4ef84ebd0a4bc4181f977658e825d058922b3
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for basic tdr functions
5 Copyright (C) Jelmer Vernooij 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "lib/tdr/tdr.h"
26 static bool test_push_uint8(struct torture_context *tctx)
28 uint8_t v = 4;
29 struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push);
31 torture_assert_ntstatus_ok(tctx, tdr_push_uint8(tdr, &v), "push failed");
32 torture_assert_int_equal(tctx, tdr->data.length, 1, "length incorrect");
33 torture_assert_int_equal(tctx, tdr->data.data[0], 4, "data incorrect");
34 return true;
37 static bool test_pull_uint8(struct torture_context *tctx)
39 uint8_t d = 2;
40 uint8_t l;
41 struct tdr_pull tdr;
42 tdr.data.data = &d;
43 tdr.data.length = 1;
44 tdr.offset = 0;
45 tdr.flags = 0;
46 torture_assert_ntstatus_ok(tctx, tdr_pull_uint8(&tdr, tctx, &l),
47 "pull failed");
48 torture_assert_int_equal(tctx, 1, tdr.offset,
49 "offset invalid");
50 return true;
53 static bool test_push_uint16(struct torture_context *tctx)
55 uint16_t v = 0xF32;
56 struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push);
58 torture_assert_ntstatus_ok(tctx, tdr_push_uint16(tdr, &v), "push failed");
59 torture_assert_int_equal(tctx, tdr->data.length, 2, "length incorrect");
60 torture_assert_int_equal(tctx, tdr->data.data[0], 0x32, "data incorrect");
61 torture_assert_int_equal(tctx, tdr->data.data[1], 0x0F, "data incorrect");
62 return true;
65 static bool test_pull_uint16(struct torture_context *tctx)
67 uint16_t d = 782;
68 uint16_t l;
69 struct tdr_pull tdr;
70 tdr.data.data = (uint8_t *)&d;
71 tdr.data.length = 2;
72 tdr.offset = 0;
73 tdr.flags = 0;
74 torture_assert_ntstatus_ok(tctx, tdr_pull_uint16(&tdr, tctx, &l),
75 "pull failed");
76 torture_assert_int_equal(tctx, 2, tdr.offset,
77 "offset invalid");
78 torture_assert_int_equal(tctx, 782, l, "right int read");
79 return true;
82 struct torture_suite *torture_local_tdr(TALLOC_CTX *mem_ctx)
84 struct torture_suite *suite = torture_suite_create(mem_ctx, "TDR");
86 torture_suite_add_simple_test(suite, "pull_uint8", test_pull_uint8);
87 torture_suite_add_simple_test(suite, "push_uint8", test_push_uint8);
89 torture_suite_add_simple_test(suite, "pull_uint16", test_pull_uint16);
90 torture_suite_add_simple_test(suite, "push_uint16", test_push_uint16);
92 return suite;