Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2013 Red Hat
6 :
7 : SSSD tests: Common utilities for tests that exercise domains
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "util/util.h"
24 : #include "tests/cmocka/common_mock_resp.h"
25 :
26 : /* Mock a responder context */
27 : struct resp_ctx *
28 130 : mock_rctx(TALLOC_CTX *mem_ctx,
29 : struct tevent_context *ev,
30 : struct sss_domain_info *domains,
31 : void *pvt_ctx)
32 : {
33 : struct resp_ctx *rctx;
34 : errno_t ret;
35 :
36 130 : rctx = talloc_zero(mem_ctx, struct resp_ctx);
37 130 : if (!rctx) return NULL;
38 :
39 130 : ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
40 130 : if (ret != EOK) {
41 0 : talloc_free(rctx);
42 0 : return NULL;
43 : }
44 :
45 130 : rctx->ev = ev;
46 130 : rctx->domains = domains;
47 130 : rctx->pvt_ctx = pvt_ctx;
48 130 : return rctx;
49 : }
50 :
51 : /* Mock a client context */
52 : struct cli_ctx *
53 75 : mock_cctx(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx)
54 : {
55 : struct cli_ctx *cctx;
56 :
57 75 : cctx = talloc_zero(mem_ctx, struct cli_ctx);
58 75 : if (!cctx) return NULL;
59 :
60 75 : cctx->creq = talloc_zero(cctx, struct cli_request);
61 75 : if (cctx->creq == NULL) {
62 0 : talloc_free(cctx);
63 0 : return NULL;
64 : }
65 :
66 75 : cctx->rctx = rctx;
67 75 : return cctx;
68 : }
|