blob: ee31775129c06d76635377d0fde8281726979c8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
Authors:
Pavel Březina <pbrezina@redhat.com>
Copyright (C) 2016 Red Hat
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include <tevent.h>
#include "providers/backend.h"
#include "providers/data_provider/dp_private.h"
#include "providers/data_provider/dp.h"
#include "tests/cmocka/common_mock.h"
static struct dp_method *mock_dp_methods(TALLOC_CTX *mem_ctx)
{
struct dp_method *methods;
methods = talloc_zero_array(mem_ctx, struct dp_method,
DP_METHOD_SENTINEL + 1);
assert_non_null(methods);
return methods;
}
static struct dp_target **mock_dp_targets(TALLOC_CTX *mem_ctx)
{
struct dp_target **targets;
enum dp_targets type;
targets = talloc_zero_array(mem_ctx, struct dp_target *,
DP_TARGET_SENTINEL + 1);
assert_non_null(targets);
for (type = 0; type != DP_TARGET_SENTINEL; type++) {
targets[type] = talloc_zero(targets, struct dp_target);
assert_non_null(targets[type]);
targets[type]->name = dp_target_to_string(type);
targets[type]->module_name = "test-module";
targets[type]->module = NULL;
targets[type]->methods = mock_dp_methods(targets[type]);
targets[type]->initialized = true;
}
return targets;
}
struct data_provider *mock_dp(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx)
{
struct data_provider *provider;
provider = talloc_zero(mem_ctx, struct data_provider);
assert_non_null(provider);
provider->ev = be_ctx->ev;
provider->be_ctx = be_ctx;
provider->terminating = false;
provider->requests.index = 0;
provider->requests.num_active = 0;
provider->requests.active = NULL;
provider->targets = mock_dp_targets(provider);
provider->modules = NULL;
be_ctx->provider = provider;
return provider;
}
struct dp_method *mock_dp_get_methods(struct data_provider *provider,
enum dp_targets target)
{
struct dp_method *methods;
assert_non_null(provider);
assert_non_null(provider->targets);
assert_non_null(provider->targets[target]);
methods = provider->targets[target]->methods;
assert_non_null(methods);
return methods;
}
|