90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek/*
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek Authors:
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek Copyright (C) 2014 Red Hat
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek SSSD tests: Data Provider Option Tests
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek This program is free software; you can redistribute it and/or modify
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek it under the terms of the GNU General Public License as published by
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek (at your option) any later version.
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek This program is distributed in the hope that it will be useful,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek GNU General Public License for more details.
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek You should have received a copy of the GNU General Public License
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek*/
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#include <popt.h>
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#include "providers/data_provider.h"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#include "tests/cmocka/common_mock.h"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define STRING_DEFAULT "stringval"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define BLOB_DEFAULT "blobval"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define INT_DEFAULT 123
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define TEST_CONF_DB "test_opt_conf.ldb"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define TEST_DOM_NAME "opt_test"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek#define TEST_ID_PROVIDER "ldap"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekenum test_opts {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_STRING_NODEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_STRING_DEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_BLOB_NODEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_BLOB_DEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_INT_NODEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_INT_DEFAULT,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_BOOL_TRUE,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_BOOL_FALSE,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek OPT_NUM_OPTS
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek};
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekstruct dp_option test_def_opts[] = {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "string_nodefault", DP_OPT_STRING, NULL_STRING, NULL_STRING },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "string_default", DP_OPT_STRING, { STRING_DEFAULT }, NULL_STRING},
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "blob_nodefault", DP_OPT_BLOB, NULL_BLOB, NULL_BLOB },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "blob_default", DP_OPT_BLOB,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { .blob = { discard_const(BLOB_DEFAULT),
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek sizeof(BLOB_DEFAULT) - 1 } },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek NULL_BLOB },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "int_nodefault", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "int_default", DP_OPT_NUMBER, { .number = INT_DEFAULT }, NULL_NUMBER },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "bool_true", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "bool_false", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek DP_OPTION_TERMINATOR
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek};
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekstatic void assert_defaults(struct dp_option *opts)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek char *s;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int i;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bool bo;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_string_equal(s, STRING_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, strlen(BLOB_DEFAULT));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_memory_equal(b.data, BLOB_DEFAULT, strlen(BLOB_DEFAULT));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, INT_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bo = dp_opt_get_bool(opts, OPT_BOOL_TRUE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_true(bo == true);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bo = dp_opt_get_bool(opts, OPT_BOOL_FALSE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_true(bo == false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekvoid opt_test_copy_default(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek TALLOC_CTX *mem_ctx;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek mem_ctx = talloc_new(global_talloc_context);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(mem_ctx);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_copy_defaults(mem_ctx, test_def_opts, OPT_NUM_OPTS, &opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_defaults(opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek /* Test that copy_defaults would still copy defaults even if we
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * change the values
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_string(opts, OPT_STRING_NODEFAULT, "str1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_string(opts, OPT_STRING_DEFAULT, "str2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.data = discard_const_p(uint8_t, "blob1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.length = strlen("blob1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_blob(opts, OPT_BLOB_NODEFAULT, b);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_blob(opts, OPT_BLOB_DEFAULT, b);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.data = discard_const_p(uint8_t, "blob2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.length = strlen("blob2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_int(opts, OPT_INT_NODEFAULT, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_int(opts, OPT_INT_DEFAULT, 789);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_bool(opts, OPT_BOOL_FALSE, true);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek talloc_free(opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_copy_defaults(mem_ctx, test_def_opts, OPT_NUM_OPTS, &opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_defaults(opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekvoid opt_test_copy_options(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek TALLOC_CTX *mem_ctx;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek char *s;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int i;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bool bo;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek mem_ctx = talloc_new(global_talloc_context);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(mem_ctx);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_copy_options(mem_ctx, test_def_opts, OPT_NUM_OPTS, &opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_string(opts, OPT_STRING_NODEFAULT, "str1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.data = discard_const_p(uint8_t, "blob1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.length = strlen("blob1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_blob(opts, OPT_BLOB_NODEFAULT, b);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_int(opts, OPT_INT_NODEFAULT, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek /* Test that options set to an explicit value retain
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * the value and even options with default value
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * do not return the default unless explicitly set
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_string_equal(s, "str1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, strlen("blob1"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_memory_equal(b.data, "blob1", strlen("blob1"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bo = dp_opt_get_bool(opts, OPT_BOOL_TRUE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_false(bo == true);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekvoid opt_test_get(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct sss_test_ctx *tctx;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct sss_test_conf_param params[] = {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "string_nodefault", "stringval2" },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "blob_nodefault", "blobval2" },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "int_nodefault", "456" },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { "bool_true", "false" },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek { NULL, NULL }, /* Sentinel */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek };
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek char *s;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int i;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bool bo;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek tctx = create_dom_test_ctx(global_talloc_context, TESTS_PATH, TEST_CONF_DB,
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik TEST_DOM_NAME, TEST_ID_PROVIDER, params);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(tctx);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek ret = dp_get_options(global_talloc_context, tctx->confdb, tctx->conf_dom_path,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek test_def_opts, OPT_NUM_OPTS, &opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek /* Options that were not specified explicitly should only have the default
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * value, those that have been specified explicitly should carry that
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * value
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_string_equal(s, "stringval2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_string_equal(s, STRING_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, strlen("blobval2"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_memory_equal(b.data, "blobval2", strlen("blobval2"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, strlen(BLOB_DEFAULT));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_memory_equal(b.data, BLOB_DEFAULT, strlen(BLOB_DEFAULT));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, INT_DEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bo = dp_opt_get_bool(opts, OPT_BOOL_TRUE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_true(bo == false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bo = dp_opt_get_bool(opts, OPT_BOOL_FALSE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_true(bo == false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int opt_test_getset_setup(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_copy_defaults(global_talloc_context,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek test_def_opts, OPT_NUM_OPTS, &opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_defaults(opts);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek *state = opts;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int opt_test_getset_teardown(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek talloc_free(opts);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void assert_nondefault_string_empty(struct dp_option *opts)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek char *s;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(s);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void set_nondefault_string(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_string(opts, OPT_STRING_NODEFAULT, "str1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void check_nondefault_string(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek char *s;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek s = dp_opt_get_string(opts, OPT_STRING_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(s);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_string_equal(s, "str1");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekvoid opt_test_getset_string(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_string_empty(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_string(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek check_nondefault_string(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void assert_nondefault_blob_empty(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, 0);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void set_nondefault_blob(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek struct dp_opt_blob b;
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.data = discard_const_p(uint8_t, "blob2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b.length = strlen("blob2");
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_blob(opts, OPT_BLOB_NODEFAULT, b);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void check_nondefault_blob(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek struct dp_opt_blob b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_blob(opts, OPT_BLOB_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_non_null(b.data);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(b.length, strlen("blob2"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_memory_equal(b.data, "blob2", strlen("blob2"));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekvoid opt_test_getset_blob(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_blob_empty(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_blob(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek check_nondefault_blob(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void assert_nondefault_int_notset(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int i;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 0);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void set_nondefault_int(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_int(opts, OPT_INT_NODEFAULT, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekstatic void assert_nondefault_int_set(struct dp_option *opts)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int i;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek i = dp_opt_get_int(opts, OPT_INT_NODEFAULT);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(i, 456);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekvoid opt_test_getset_int(void **state)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_int_notset(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_int(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_int_set(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekvoid opt_test_getset_bool(void **state)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek bool b;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_bool(opts, OPT_BOOL_TRUE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_true(b == true);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_int_equal(ret, EOK);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek b = dp_opt_get_bool(opts, OPT_BOOL_TRUE);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek assert_false(b == true);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozekvoid opt_test_inherit(void **state)
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek{
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek struct dp_option *opts = talloc_get_type(*state, struct dp_option);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek int ret;
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek struct dp_option *opts_copy;
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek const char *s;
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek const char *sd_inherit_match[] = { "string_nodefault",
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek "blob_nodefault",
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek "int_nodefault",
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek "bool_true",
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek NULL };
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek ret = dp_copy_defaults(opts, test_def_opts,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek OPT_NUM_OPTS, &opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_int_equal(ret, EOK);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_defaults(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek dp_option_inherit(NULL, OPT_STRING_NODEFAULT,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opts, opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek s = dp_opt_get_string(opts_copy, OPT_STRING_NODEFAULT);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_null(s);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek /* string */
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_string_empty(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_string(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek dp_option_inherit(discard_const(sd_inherit_match),
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek OPT_STRING_NODEFAULT,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opts, opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek check_nondefault_string(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek /* blob */
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_blob_empty(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_blob(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek dp_option_inherit(discard_const(sd_inherit_match),
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek OPT_BLOB_NODEFAULT,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opts, opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek check_nondefault_blob(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek /* number */
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_int_notset(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek set_nondefault_int(opts);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek dp_option_inherit(discard_const(sd_inherit_match),
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek OPT_INT_NODEFAULT,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opts, opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_nondefault_int_set(opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek /* bool */
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_true(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_int_equal(ret, EOK);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek dp_option_inherit(discard_const(sd_inherit_match),
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek OPT_BOOL_TRUE,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opts, opts_copy);
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek assert_false(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek}
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekint main(int argc, const char *argv[])
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek{
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int no_cleanup = 0;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek poptContext pc;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int opt;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek int ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek struct poptOption long_options[] = {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek POPT_AUTOHELP
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek SSSD_DEBUG_OPTS
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek POPT_TABLEEND
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek };
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(opt_test_getset_string,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(opt_test_getset_int,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(opt_test_getset_bool,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(opt_test_getset_blob,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek opt_test_getset_teardown),
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek cmocka_unit_test_setup_teardown(opt_test_inherit,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opt_test_getset_setup,
b3d110fbc424a03674a6e50e489a7cbab9702f0bJakub Hrozek opt_test_getset_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(opt_test_copy_default),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(opt_test_copy_options),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(opt_test_get)
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek };
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek /* Set debug level to invalid value so we can deside if -d 0 was used. */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek debug_level = SSSDBG_INVALID;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek switch(opt) {
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek default:
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek poptPrintUsage(pc, stderr, 0);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek return 1;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek }
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek }
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek poptFreeContext(pc);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek /* Even though normally the tests should clean up after themselves
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek * they might not after a failed run. Remove the old db to be sure */
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek tests_set_cwd();
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek ret = cmocka_run_group_tests(tests, NULL, NULL);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek if (ret == 0 && !no_cleanup) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek }
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek return ret;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek}