test_dp_opts.c revision 6b57784f0f175275fd900eca21c77415e3a5ea52
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2014 Red Hat
SSSD tests: Data Provider Option Tests
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 <popt.h>
#include "providers/data_provider.h"
#include "tests/cmocka/common_mock.h"
#define STRING_DEFAULT "stringval"
#define BLOB_DEFAULT "blobval"
#define INT_DEFAULT 123
#define TESTS_PATH "tests_opts"
#define TEST_CONF_DB "test_opt_conf.ldb"
#define TEST_DOM_NAME "opt_test"
#define TEST_ID_PROVIDER "ldap"
enum test_opts {
};
struct dp_option test_def_opts[] = {
{ "blob_default", DP_OPT_BLOB,
sizeof(BLOB_DEFAULT) - 1 } },
NULL_BLOB },
};
{
char *s;
struct dp_opt_blob b;
int i;
bool bo;
assert_null(s);
assert_non_null(s);
assert_null(b.data);
assert_int_equal(b.length, 0);
assert_non_null(b.data);
assert_int_equal(i, 0);
assert_true(bo == true);
assert_true(bo == false);
}
void opt_test_copy_default(void **state)
{
int ret;
struct dp_opt_blob b;
/* Test that copy_defaults would still copy defaults even if we
* change the values
*/
}
void opt_test_copy_options(void **state)
{
int ret;
char *s;
struct dp_opt_blob b;
int i;
bool bo;
/* Test that options set to an explicit value retain
* the value and even options with default value
* do not return the default unless explicitly set
*/
assert_string_equal(s, "str1");
assert_null(s);
assert_non_null(b.data);
assert_null(b.data);
assert_int_equal(b.length, 0);
assert_int_equal(i, 456);
assert_int_equal(i, 0);
assert_false(bo == true);
}
void opt_test_get(void **state)
{
int ret;
struct sss_test_ctx *tctx;
struct sss_test_conf_param params[] = {
{ "string_nodefault", "stringval2" },
{ "blob_nodefault", "blobval2" },
{ "int_nodefault", "456" },
{ "bool_true", "false" },
};
char *s;
struct dp_opt_blob b;
int i;
bool bo;
/* Options that were not specified explicitly should only have the default
* value, those that have been specified explicitly should carry that
* value
*/
assert_non_null(s);
assert_string_equal(s, "stringval2");
assert_non_null(s);
assert_non_null(b.data);
assert_non_null(b.data);
assert_int_equal(i, 456);
assert_true(bo == false);
assert_true(bo == false);
}
void opt_test_getset_setup(void **state)
{
int ret;
}
void opt_test_getset_teardown(void **state)
{
}
void opt_test_getset_string(void **state)
{
int ret;
char *s;
assert_null(s);
assert_non_null(s);
assert_string_equal(s, "str1");
}
void opt_test_getset_blob(void **state)
{
int ret;
struct dp_opt_blob b;
assert_null(b.data);
assert_int_equal(b.length, 0);
assert_non_null(b.data);
}
void opt_test_getset_int(void **state)
{
int ret;
int i;
assert_int_equal(i, 0);
assert_int_equal(i, 456);
}
void opt_test_getset_bool(void **state)
{
int ret;
bool b;
assert_true(b == true);
assert_false(b == true);
}
{
int no_cleanup = 0;
int opt;
int ret;
struct poptOption long_options[] = {
_("Do not delete the test database after a test run"), NULL },
};
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
if (ret == 0 && !no_cleanup) {
}
return ret;
}