util-tests.c revision abac0f3ec2baa597d8e21a8744de6f33506299ce
/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2010 Red Hat
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 <talloc.h>
#include <check.h>
#include <fcntl.h>
#include "util/sss_utf8.h"
#include "util/murmurhash3.h"
#include "tests/common_check.h"
#define FILENAME_TEMPLATE "tests-atomicio-XXXXXX"
char *filename;
int atio_fd;
{
int ret;
"Wrong string added to newly created list.");
"Missing terminating NULL in newly created list.");
"Wrong string added to empty list.");
"Missing terminating NULL in newly created list.");
}
{
bool is_in;
char *empty_list[] = {NULL};
discard_const("DEF"),
discard_const("GHI"),
NULL};
}
{
struct pa_testcase {
const char *argstr;
const char **parsed;
};
int i, ii;
int ret;
char **parsed;
char **only_ret;
char **only_exp;
char **both;
/* Positive tests */
struct pa_testcase tc[] = {
{ "foo", parsed1 },
{ "foo a", parsed2 },
{ "foo b", parsed3 },
{ "foo a\\ c", parsed4 },
{ "foo a d ", parsed5 },
{ "foo a e ", parsed6 },
{ "foo a f ", parsed7 },
{ "foo a\\\tg", parsed8 },
};
"Could not parse correct argument string '%s'\n");
}
}
{
char **l1;
char **l2;
char **l3;
char **only_l1;
char **only_l2;
char **both;
int ret;
/* Test with all values returned */
/* Test with restricted return values */
/* Test with no overlap */
/* Test with 100% overlap */
/* Test with no second list */
}
{
const char no_specials[] = "username";
"Expected [%s], got [%s]",
const char has_asterisk[] = "*username";
const char has_asterisk_expected[] = "\\2ausername";
"Expected [%s], got [%s]",
const char has_lparen[] = "user(name";
const char has_lparen_expected[] = "user\\28name";
"Expected [%s], got [%s]",
const char has_rparen[] = "user)name";
const char has_rparen_expected[] = "user\\29name";
"Expected [%s], got [%s]",
const char has_backslash[] = "username\\";
const char has_backslash_expected[] = "username\\5c";
"Expected [%s], got [%s]",
const char has_all[] = "\\(user)*name";
const char has_all_expected[] = "\\5c\\28user\\29\\2aname";
"Expected [%s], got [%s]",
}
{
"overflow not detected");
"overflow not detected");
}
{
strlen((const char *)munchen_utf8_upcase),
&nlen);
fail_if(strlen((const char *) munchen_utf8_upcase) != nlen); /* This is not true for utf8 strings in general */
}
{
strlen((const char *) munchen_utf8_upcase),
&nsize);
}
{
char *lcase;
}
{
}
{
const char *invalid = "ad\351la\357d";
bool ret;
}
{
"abcdefghijk", "abcdefghili", "abcdefgh000" };
int i, j;
for (i = 0; i< 6; i++) {
0xdeadbeef);
for (j = 0; j < i; j++) {
}
}
}
{
char test[16];
unsigned int init_seed;
unsigned int seed;
int i;
/* generate a random string so each time we test with different values */
/* use also random length (min len = 1) */
for (i = 0; i < len; i++) {
}
}
void setup_atomicio(void)
{
int ret;
atio_fd = -1;
}
void teardown_atomicio(void)
{
int ret;
if (atio_fd != -1) {
}
}
{
char buf[64];
int fd;
errno = 0;
}
{
char wbuf[] = "foobar";
char rbuf[64];
errno = 0;
errno = 0;
}
{
char wbuf[] = "123456781234567812345678";
char rbuf[8];
errno = 0;
total = 0;
do {
errno = 0;
} while (numread != 0);
}
{
char wbuf[] = "12345678";
char rbuf[9];
errno = 0;
errno = 0;
/* We've reached end-of-file, next read must return 0 */
errno = 0;
}
{
char buf[64];
int fd;
errno = 0;
fail_unless(numread == 0,
"Read %d bytes expected 0\n", numread);
}
struct split_data {
const char *input;
const char **expected_list;
bool trim;
bool skip_empty;
int expected_size;
int expected_ret;
};
{
int size;
const char *str_ref;
const char *str_out;
int i;
int a;
int num_of_tests;
struct split_data sts[] = {
{
"one,two,three", /* input string */
false, false, /* trim, skip_empty */
3, 0 /* expec. size, expec. retval */
},
{
"one,two,three",
true, true,
3, 0
},
{
" one, two ,three ",
true, true,
3, 0
},
{
/* If skip empty is false, single comma means "empty,empty" */
",",
false, false,
2, 0
},
{
"one, ,",
(const char*[]){"one", " ", "NULL", "NULL"},
false, true,
2, 0
},
{
", ,,",
(const char*[]){NULL},
true, true,
0, 0
},
{
NULL,
NULL,
false, false,
0, EINVAL
},
};
for (a = 0; a < num_of_tests; a++) {
"split_on_separator failed [%d]: %s\n", ret,
if (ret) {
continue;
}
}
}
}
{
struct {
const char *host;
const char *domain;
bool expected;
{"client.example.com", "example.com", true},
{"client.child.example.com", "example.com", true},
{"example.com", "child.example.com", false},
{"client.example.com", "child.example.com", false},
{"client.child.example.com", "child.example.com", true},
{"myexample.com", "example.com", false},
bool ret;
int i;
}
}
Suite *util_suite(void)
{
suite_add_tcase (s, tc_util);
suite_add_tcase (s, tc_utf8);
suite_add_tcase (s, tc_mh3);
suite_add_tcase (s, tc_atomicio);
return s;
}
{
int opt;
int failure_count;
Suite *s = util_suite();
struct poptOption long_options[] = {
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
srunner_free (sr);
if (failure_count == 0) {
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}