b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina Copyright (C) 2015 Red Hat
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina This program is free software; you can redistribute it and/or modify
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina it under the terms of the GNU General Public License as published by
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina the Free Software Foundation; either version 3 of the License, or
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina (at your option) any later version.
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina This program is distributed in the hope that it will be useful,
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina GNU General Public License for more details.
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina You should have received a copy of the GNU General Public License
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina#include "providers/data_provider/dp_private.h"
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina ret = dp_req_table_init(test_ctx, &test_ctx->table);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina test_ctx = talloc_get_type_abort(*state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březinastatic const char *get_req_key(struct test_ctx* test_ctx)
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina "custom_part");
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina req = tevent_req_create(test_ctx, &state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(test_ctx->table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina sbus_req = talloc(test_ctx, struct sbus_request);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina ret = dp_req_table_add(test_ctx->table, key, req, sbus_req);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(test_ctx->table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina tv = dp_req_table_lookup(test_ctx->table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina tv2 = dp_req_table_lookup(test_ctx->table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(test_ctx->table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březinastatic void test_del_non_present_req(void **state)
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina req = tevent_req_create(test_ctx, &state, struct test_ctx);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Add 1st request */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina sbus_req = talloc(test_ctx, struct sbus_request);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina ret = dp_req_table_add(table, key, req, sbus_req);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(tv->list->sbus_req, sbus_req);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Add 2nd request */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina sbus_req2 = talloc(test_ctx, struct sbus_request);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina ret = dp_req_table_add(table, key, NULL, sbus_req2);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(tv->list->sbus_req, sbus_req2);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(tv->list->next->sbus_req, sbus_req);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Del req */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Free memory */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina/* This test is aimed to test 'dp_sbus_req_item_destructor()' */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina const int N = 5;
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina req = tevent_req_create(test_ctx, &state, struct test_ctx);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Insert N sbus_requests for req_name */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina for (int i = 0; i < N; i++) {
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina sbus_req[i] = talloc(test_ctx, struct sbus_request);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina ret = dp_req_table_add(table, key, req, sbus_req[i]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina for (int i = 0; i < N; i++) {
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(ri->sbus_req, sbus_req[N-i-1]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Del one req */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Check that only magic is missing */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(ri->sbus_req, sbus_req[N-1]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Skip deleted MAGIC request */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(ri->sbus_req, sbus_req[N-3]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(ri->sbus_req, sbus_req[N-4]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina assert_ptr_equal(ri->sbus_req, sbus_req[N-5]);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina is_present = dp_req_table_has_key(table, key);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina /* Free memory */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina for (int i = 0; i < N; i++) {
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina _("Do not delete the test database after a test run"), NULL },
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina cmocka_unit_test_setup_teardown(test_add_del_req,
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina cmocka_unit_test_setup_teardown(test_del_non_present_req,
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina cmocka_unit_test_setup_teardown(test_mult_req,
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina cmocka_unit_test_setup_teardown(test_destructor_req,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b9d83e10cec267ae11fee64a30f42a12bbf7abe4Pavel Březina fprintf(stderr, "\nInvalid option %s: %s\n\n",