test-strv.c revision 8dd4c05b5495c7ffe0f12ace87e71abe17bd0a0e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
Copyright 2013 Thomas H.P. Andersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <string.h>
#include "util.h"
#include "specifier.h"
#include "strv.h"
static void test_specifier_printf(void) {
{}
};
_cleanup_free_ char *w = NULL;
int r;
assert_se(r >= 0);
assert_se(w);
puts(w);
free(w);
assert_se(r >= 0);
assert_se(w);
puts(w);
}
static const char* const input_table_multiple[] = {
"one",
"two",
"three",
NULL,
};
static const char* const input_table_one[] = {
"one",
NULL,
};
static const char* const input_table_none[] = {
NULL,
};
static const char* const input_table_quotes[] = {
"\"",
"'",
"\"\"",
"\\",
"\\\\",
NULL,
};
#define QUOTES_STRING \
"\"\\\"\" " \
"\"\\\'\" " \
"\"\\\"\\\"\" " \
"\"\\\\\" " \
"\"\\\\\\\\\""
static const char * const input_table_spaces[] = {
" ",
"' '",
"\" ",
" \"",
" \\\\ ",
NULL,
};
#define SPACES_STRING \
"\" \" " \
"\"\\' \\'\" " \
"\"\\\" \" " \
"\" \\\"\" " \
"\" \\\\\\\\ \""
static void test_strv_find(void) {
}
static void test_strv_find_prefix(void) {
}
static void test_strv_find_startswith(void) {
char *r;
}
static void test_strv_join(void) {
assert_se(p);
assert_se(q);
assert_se(r);
assert_se(s);
assert_se(t);
}
_cleanup_free_ char *p;
_cleanup_strv_free_ char **s = NULL;
char **t;
int r;
p = strv_join_quoted((char **)split);
assert_se(p);
assert_se(p);
assert_se(r == (int) strv_length(s));
assert_se(s);
STRV_FOREACH(t, s) {
assert_se(*t);
split++;
}
}
_cleanup_strv_free_ char **s;
_cleanup_free_ char *j;
unsigned i = 0;
char **t;
int r;
assert_se(s);
j = strv_join(s, " | ");
assert_se(j);
puts(j);
STRV_FOREACH(t, s)
}
static void test_invalid_unquote(const char *quoted) {
char **s = NULL;
int r;
}
static void test_strv_split(void) {
char **s;
unsigned i = 0;
_cleanup_strv_free_ char **l = NULL;
const char str[] = "one,two,three";
assert_se(l);
STRV_FOREACH(s, l) {
}
}
static void test_strv_split_extract(void) {
_cleanup_strv_free_ char **l = NULL;
const char *str = ":foo\\:bar::waldo:";
int r;
assert_se(r == (int) strv_length(l));
}
static void test_strv_split_newlines(void) {
unsigned i = 0;
char **s;
_cleanup_strv_free_ char **l = NULL;
const char str[] = "one\ntwo\nthree";
l = strv_split_newlines(str);
assert_se(l);
STRV_FOREACH(s, l) {
}
}
static void test_strv_split_nulstr(void) {
_cleanup_strv_free_ char **l = NULL;
const char nulstr[] = "str0\0str1\0str2\0str3\0";
l = strv_split_nulstr (nulstr);
assert_se(l);
}
static void test_strv_parse_nulstr(void) {
_cleanup_strv_free_ char **l = NULL;
const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
assert_se(l);
puts("Parse nulstr:");
strv_print(l);
}
static void test_strv_overlap(void) {
const char * const input_table[] = {
"one",
"two",
"three",
};
const char * const input_table_overlap[] = {
"two",
};
const char * const input_table_unique[] = {
"four",
"five",
"six",
};
}
static void test_strv_sort(void) {
const char* input_table[] = {
"durian",
"apple",
"citrus",
"CAPITAL LETTERS FIRST",
"banana",
};
strv_sort((char **)input_table);
}
static void test_strv_extend_strv_concat(void) {
assert_se(a);
assert_se(b);
}
static void test_strv_extend_strv(void) {
assert_se(a);
assert_se(b);
assert_se(strv_extend_strv(&a, b) >= 0);
}
static void test_strv_extend(void) {
assert_se(a);
}
static void test_strv_extendf(void) {
assert_se(a);
}
static void test_strv_foreach(void) {
_cleanup_strv_free_ char **a;
unsigned i = 0;
char **check;
assert_se(a);
STRV_FOREACH(check, a) {
}
}
static void test_strv_foreach_backwards(void) {
_cleanup_strv_free_ char **a;
unsigned i = 2;
char **check;
assert_se(a);
STRV_FOREACH_BACKWARDS(check, a) {
}
}
static void test_strv_foreach_pair(void) {
_cleanup_strv_free_ char **a = NULL;
char **x, **y;
"pair_two", "pair_two",
"pair_three", "pair_three",
NULL);
STRV_FOREACH_PAIR(x, y, a) {
}
}
static void test_strv_from_stdarg_alloca_one(char **l, const char *first, ...) {
char **j;
unsigned i;
j = strv_from_stdarg_alloca(first);
for (i = 0;; i++) {
if (!l[i])
break;
}
}
static void test_strv_from_stdarg_alloca(void) {
}
static void test_strv_push_prepend(void) {
_cleanup_strv_free_ char **a = NULL;
assert_se(!a[4]);
assert_se(!a[5]);
}
static void test_strv_push(void) {
_cleanup_strv_free_ char **a = NULL;
char *i, *j;
assert_se(strv_push_pair(&a, i, j) >= 0);
}
static void test_strv_equal(void) {
_cleanup_strv_free_ char **a = NULL;
_cleanup_strv_free_ char **b = NULL;
_cleanup_strv_free_ char **c = NULL;
assert_se(a);
assert_se(a);
assert_se(a);
assert_se(strv_equal(a, a));
assert_se(strv_equal(a, b));
assert_se(!strv_equal(a, c));
assert_se(!strv_equal(b, c));
}
static void test_strv_is_uniq(void) {
assert_se(a);
assert_se(strv_is_uniq(a));
assert_se(b);
assert_se(strv_is_uniq(b));
assert_se(c);
assert_se(strv_is_uniq(c));
assert_se(d);
assert_se(!strv_is_uniq(d));
}
static void test_strv_reverse(void) {
assert_se(a);
strv_reverse(a);
assert_se(strv_isempty(a));
assert_se(b);
strv_reverse(b);
assert_se(c);
strv_reverse(c);
assert_se(d);
strv_reverse(d);
}
static void test_strv_shell_escape(void) {
_cleanup_strv_free_ char **v = NULL;
assert_se(v);
}
static void test_strv_skip_one(char **a, size_t n, char **b) {
a = strv_skip(a, n);
assert_se(strv_equal(a, b));
}
static void test_strv_skip(void) {
}
static void test_strv_extend_n(void) {
_cleanup_strv_free_ char **v = NULL;
assert_se(v);
v = strv_free(v);
}
/* trailing backslashes */
test_invalid_unquote(" x\\");
test_invalid_unquote("a --b='c \"d e\"''");
test_invalid_unquote("a --b='c \"d e\" '\"");
test_invalid_unquote("a --b='c \"d e\"garbage");
test_invalid_unquote("'");
test_invalid_unquote("\"");
test_invalid_unquote("'x'y'g");
return 0;
}