s4-torture: add clusapi torture test.
[metze/samba/wip.git] / source4 / torture / rpc / clusapi.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for clusapi rpc operations
4
5    Copyright (C) Günther Deschner 2015
6
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 3 of the License, or
10    (at your option) any later version.
11
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.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "librpc/gen_ndr/ndr_clusapi_c.h"
23 #include "torture/rpc/torture_rpc.h"
24 #include "param/param.h"
25
26 static bool test_OpenCluster_int(struct torture_context *tctx,
27                                  struct dcerpc_pipe *p,
28                                  struct policy_handle *Cluster)
29 {
30         struct dcerpc_binding_handle *b = p->binding_handle;
31         struct clusapi_OpenCluster r;
32         uint32_t Status;
33
34         r.out.Status = &Status;
35         r.out.Cluster = Cluster;
36
37         torture_assert_ntstatus_ok(tctx,
38                 dcerpc_clusapi_OpenCluster_r(b, tctx, &r),
39                 "OpenCluster failed");
40         torture_assert_werr_ok(tctx,
41                 W_ERROR(*r.out.Status),
42                 "OpenCluster failed");
43
44         return true;
45 }
46
47 static bool test_CloseCluster_int(struct torture_context *tctx,
48                                   struct dcerpc_pipe *p,
49                                   struct policy_handle *Cluster)
50 {
51         struct dcerpc_binding_handle *b = p->binding_handle;
52         struct clusapi_CloseCluster r;
53
54         r.in.Cluster = Cluster;
55         r.out.Cluster = Cluster;
56
57         torture_assert_ntstatus_ok(tctx,
58                 dcerpc_clusapi_CloseCluster_r(b, tctx, &r),
59                 "CloseCluster failed");
60         torture_assert_werr_ok(tctx,
61                 W_ERROR(r.out.result),
62                 "CloseCluster failed");
63
64         torture_assert(tctx,
65                 ndr_policy_handle_empty(Cluster),
66                 "policy_handle non empty after CloseCluster");
67
68         return true;
69 }
70
71 static bool test_OpenCluster(struct torture_context *tctx,
72                              struct dcerpc_pipe *p)
73 {
74         struct policy_handle Cluster;
75
76         if (!test_OpenCluster_int(tctx, p, &Cluster)) {
77                 return false;
78         }
79
80         test_CloseCluster_int(tctx, p, &Cluster);
81
82         return true;
83 }
84
85 static bool test_CloseCluster(struct torture_context *tctx,
86                               struct dcerpc_pipe *p)
87 {
88         struct policy_handle Cluster;
89
90         if (!test_OpenCluster_int(tctx, p, &Cluster)) {
91                 return false;
92         }
93
94         return test_CloseCluster_int(tctx, p, &Cluster);
95 }
96
97 struct torture_suite *torture_rpc_clusapi(TALLOC_CTX *mem_ctx)
98 {
99         struct torture_rpc_tcase *tcase;
100         struct torture_suite *suite = torture_suite_create(mem_ctx, "clusapi");
101
102         tcase = torture_suite_add_rpc_iface_tcase(suite, "clusapi",
103                                                   &ndr_table_clusapi);
104
105         torture_rpc_tcase_add_test(tcase, "OpenCluster",
106                                    test_OpenCluster);
107         torture_rpc_tcase_add_test(tcase, "CloseCluster",
108                                    test_CloseCluster);
109
110         return suite;
111 }