>From 0adbedaf8266aab52e2d15c3df2bf64042f73353 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Fri, 18 Apr 2014 15:01:55 +0200
Subject: [PATCH 4/5] TESTS: Split a separate common_mock_resp_dp module

Splitting the module would allow responders that test the Data Provider
requests to use the mock_rctx/mock_cctx functions without duplicate
definitions.
---
 Makefile.am                                        |  1 +
 src/tests/cmocka/common_mock_resp.c                | 71 ----------------------
 .../{common_mock_resp.c => common_mock_resp_dp.c}  | 53 +++-------------
 3 files changed, 9 insertions(+), 116 deletions(-)
 copy src/tests/cmocka/{common_mock_resp.c => common_mock_resp_dp.c} (73%)

diff --git a/Makefile.am b/Makefile.am
index f5a6594b0b25b733f0cd40ac1038ba5bef49e1fc..702193d69be18b06b38b3f55885a2cf95631951f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1404,6 +1404,7 @@ if HAVE_CMOCKA
 
 TEST_MOCK_RESP_OBJ = \
      src/tests/cmocka/common_mock_resp.c \
+     src/tests/cmocka/common_mock_resp_dp.c \
      src/responder/common/responder_packet.c \
      src/responder/common/responder_cmd.c \
      src/responder/common/negcache.c \
diff --git a/src/tests/cmocka/common_mock_resp.c b/src/tests/cmocka/common_mock_resp.c
index d74f6ffa7a76d2f80fc7cbcf46ecf9ac5bcc9878..767d4d7e1455d0998e6511cefa595ec6238ba07d 100644
--- a/src/tests/cmocka/common_mock_resp.c
+++ b/src/tests/cmocka/common_mock_resp.c
@@ -66,74 +66,3 @@ mock_cctx(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx)
     cctx->rctx = rctx;
     return cctx;
 }
-
-/* Mock DP requests that finish immediatelly and return
- * mocked values as per previous set by mock_account_recv
- */
-struct tevent_req *
-sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
-                        struct resp_ctx *rctx,
-                        struct sss_domain_info *dom,
-                        bool fast_reply,
-                        enum sss_dp_acct_type type,
-                        const char *opt_name,
-                        uint32_t opt_id,
-                        const char *extra)
-{
-    return test_req_succeed_send(mem_ctx, rctx->ev);
-}
-
-
-errno_t
-sss_dp_get_account_recv(TALLOC_CTX *mem_ctx,
-                        struct tevent_req *req,
-                        dbus_uint16_t *dp_err,
-                        dbus_uint32_t *dp_ret,
-                        char **err_msg)
-{
-    acct_cb_t cb;
-
-    *dp_err = sss_mock_type(dbus_uint16_t);
-    *dp_ret = sss_mock_type(dbus_uint32_t);
-    *dp_ret = sss_mock_type(dbus_uint32_t);
-
-    cb = sss_mock_ptr_type(acct_cb_t);
-    if (cb) {
-        (cb)(sss_mock_ptr_type(void *));
-    }
-
-    return test_request_recv(req);
-}
-
-void mock_account_recv(uint16_t dp_err, uint32_t dp_ret, char *msg,
-                       acct_cb_t acct_cb, void *pvt)
-{
-    will_return(sss_dp_get_account_recv, dp_err);
-    will_return(sss_dp_get_account_recv, dp_ret);
-    will_return(sss_dp_get_account_recv, msg);
-
-    will_return(sss_dp_get_account_recv, acct_cb);
-    if (acct_cb) {
-        will_return(sss_dp_get_account_recv, pvt);
-    }
-}
-
-void mock_account_recv_simple(void)
-{
-    return mock_account_recv(0, 0, NULL, NULL, NULL);
-}
-
-/* Mock subdomain requests */
-struct tevent_req *
-sss_dp_get_domains_send(TALLOC_CTX *mem_ctx,
-                        struct resp_ctx *rctx,
-                        bool force,
-                        const char *hint)
-{
-    return test_req_succeed_send(mem_ctx, rctx->ev);
-}
-
-errno_t sss_dp_get_domains_recv(struct tevent_req *req)
-{
-    return test_request_recv(req);
-}
diff --git a/src/tests/cmocka/common_mock_resp.c b/src/tests/cmocka/common_mock_resp_dp.c
similarity index 73%
copy from src/tests/cmocka/common_mock_resp.c
copy to src/tests/cmocka/common_mock_resp_dp.c
index d74f6ffa7a76d2f80fc7cbcf46ecf9ac5bcc9878..ddecc3cf8a0772d32fc62560bdb815fdb550ca0c 100644
--- a/src/tests/cmocka/common_mock_resp.c
+++ b/src/tests/cmocka/common_mock_resp_dp.c
@@ -4,7 +4,7 @@
 
     Copyright (C) 2013 Red Hat
 
-    SSSD tests: Common utilities for tests that exercise domains
+    SSSD tests: Fake Data Provider requests
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -23,50 +23,6 @@
 #include "util/util.h"
 #include "tests/cmocka/common_mock_resp.h"
 
-/* Mock a responder context */
-struct resp_ctx *
-mock_rctx(TALLOC_CTX *mem_ctx,
-          struct tevent_context *ev,
-          struct sss_domain_info *domains,
-          void *pvt_ctx)
-{
-    struct resp_ctx *rctx;
-    errno_t ret;
-
-    rctx = talloc_zero(mem_ctx, struct resp_ctx);
-    if (!rctx) return NULL;
-
-    ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
-    if (ret != EOK) {
-        talloc_free(rctx);
-        return NULL;
-    }
-
-    rctx->ev = ev;
-    rctx->domains = domains;
-    rctx->pvt_ctx = pvt_ctx;
-    return rctx;
-}
-
-/* Mock a client context */
-struct cli_ctx *
-mock_cctx(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx)
-{
-    struct cli_ctx *cctx;
-
-    cctx = talloc_zero(mem_ctx, struct cli_ctx);
-    if (!cctx) return NULL;
-
-    cctx->creq = talloc_zero(cctx, struct cli_request);
-    if (cctx->creq == NULL) {
-        talloc_free(cctx);
-        return NULL;
-    }
-
-    cctx->rctx = rctx;
-    return cctx;
-}
-
 /* Mock DP requests that finish immediatelly and return
  * mocked values as per previous set by mock_account_recv
  */
@@ -123,6 +79,12 @@ void mock_account_recv_simple(void)
     return mock_account_recv(0, 0, NULL, NULL, NULL);
 }
 
+void mock_parse_inp(const char *name, const char *domname)
+{
+    will_return(sss_parse_inp_recv, name);
+    will_return(sss_parse_inp_recv, domname);
+}
+
 /* Mock subdomain requests */
 struct tevent_req *
 sss_dp_get_domains_send(TALLOC_CTX *mem_ctx,
@@ -137,3 +99,4 @@ errno_t sss_dp_get_domains_recv(struct tevent_req *req)
 {
     return test_request_recv(req);
 }
+
-- 
1.9.0

