From 3e5e98aae4b14f5447c561ff5b0d854b74046312 Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Fri, 22 Apr 2016 14:16:34 +0200 Subject: DP TESTS: Mock data_provider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Sumit Bose Reviewed-by: Jakub Hrozek Reviewed-by: Lukáš Slebodník --- src/tests/cmocka/data_provider/mock_dp.c | 98 ++++++++++++++++++++++++++++++++ src/tests/cmocka/data_provider/mock_dp.h | 35 ++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/tests/cmocka/data_provider/mock_dp.c create mode 100644 src/tests/cmocka/data_provider/mock_dp.h (limited to 'src/tests') diff --git a/src/tests/cmocka/data_provider/mock_dp.c b/src/tests/cmocka/data_provider/mock_dp.c new file mode 100644 index 000000000..ee3177512 --- /dev/null +++ b/src/tests/cmocka/data_provider/mock_dp.c @@ -0,0 +1,98 @@ +/* + Authors: + Pavel Březina + + 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 . +*/ + +#include +#include + +#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; +} diff --git a/src/tests/cmocka/data_provider/mock_dp.h b/src/tests/cmocka/data_provider/mock_dp.h new file mode 100644 index 000000000..99e7bae8c --- /dev/null +++ b/src/tests/cmocka/data_provider/mock_dp.h @@ -0,0 +1,35 @@ +/* + Authors: + Pavel Březina + + 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 . +*/ + +#ifndef _MOCK_DP_H_ +#define _MOCK_DP_H_ + +#include + +#include "providers/backend.h" +#include "providers/data_provider/dp_private.h" + +struct data_provider *mock_dp(TALLOC_CTX *mem_ctx, + struct be_ctx *be_ctx); + +struct dp_method *mock_dp_get_methods(struct data_provider *provider, + enum dp_targets target); + +#endif /* _MOCK_DP_H_ */ -- cgit