test-util.c revision a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8
/*-*- 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 <unistd.h>
#include <fcntl.h>
#include <locale.h>
#include <errno.h>
#include <signal.h>
#include "util.h"
#include "mkdir.h"
#include "strv.h"
#include "def.h"
#include "fileio.h"
#include "conf-parser.h"
static void test_streq_ptr(void) {
}
static void test_align_power2(void) {
unsigned long i, p2;
assert_se(ALIGN_POWER2(0) == 0);
for (i = 1; i < 131071; ++i) {
/* empty */ ;
}
/* empty */ ;
}
}
static void test_first_word(void) {
}
static void test_close_many(void) {
int fds[3];
char name0[] = "/tmp/test-close-many.XXXXXX";
char name1[] = "/tmp/test-close-many.XXXXXX";
char name2[] = "/tmp/test-close-many.XXXXXX";
}
static void test_parse_boolean(void) {
}
static void test_parse_pid(void) {
int r;
assert_se(r == 0);
assert_se(r == 0);
}
static void test_parse_uid(void) {
int r;
assert_se(r == 0);
}
static void test_safe_atolli(void) {
int r;
long long l;
r = safe_atolli("12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atolli("junk", &l);
}
static void test_safe_atod(void) {
int r;
double d;
char *e;
r = safe_atod("junk", &d);
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
/* Check if this really is locale independent */
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
/* And check again, reset */
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
}
static void test_strappend(void) {
}
static void test_strstrip(void) {
char *r;
char input[] = " hello, waldo. ";
}
static void test_delete_chars(void) {
char *r;
char input[] = " hello, waldo. abc";
}
static void test_in_charset(void) {
}
static void test_hexchar(void) {
}
static void test_unhexchar(void) {
}
static void test_octchar(void) {
}
static void test_unoctchar(void) {
}
static void test_decchar(void) {
}
static void test_undecchar(void) {
}
static void test_cescape(void) {
_cleanup_free_ char *escaped;
}
static void test_cunescape(void) {
_cleanup_free_ char *unescaped;
}
static void test_foreach_word(void) {
size_t l;
int i = 0;
const char test[] = "test abc d\te f ";
const char * const expected[] = {
"test",
"abc",
"d",
"e",
"f",
"",
};
}
static void test_foreach_word_quoted(void) {
size_t l;
int i = 0;
const char test[] = "test a b c 'd' e '' '' hhh '' '' \"a b c\"";
const char * const expected[] = {
"test",
"a",
"b",
"c",
"d",
"e",
"",
"",
"hhh",
"",
"",
"a b c",
};
_cleanup_free_ char *t = NULL;
printf("<%s>\n", t);
}
}
static void test_default_term_for_tty(void) {
}
static void test_memdup_multiply(void) {
int *dup;
}
static void test_hostname_is_valid(void) {
assert(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
}
static void test_u64log2(void) {
}
static void test_get_process_comm(void) {
unsigned long long b;
pid_t e;
uid_t u;
gid_t g;
dev_t h;
int r;
log_info("pid1 comm: '%s'", a);
} else {
log_warning("/proc/1/comm does not exist.");
}
log_info("pid1 starttime: '%llu'", b);
log_info("pid1 cmdline: '%s'", c);
log_info("pid1 cmdline truncated: '%s'", d);
assert_se(e == 0);
r = get_process_exe(1, &f);
assert_se(u == 0);
assert_se(g == 0);
}
static void test_protect_errno(void) {
errno = 12;
{
errno = 11;
}
}
static void test_parse_size(void) {
}
static void test_config_parse_iec_off(void) {
assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0);
assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
}
static void test_strextend(void) {
}
static void test_strrep(void) {
}
static void test_split_pair(void) {
free(a);
free(b);
free(a);
free(b);
}
static void test_fstab_node_to_udev_node(void) {
char *n;
n = fstab_node_to_udev_node("LABEL=applé/jack");
puts(n);
free(n);
n = fstab_node_to_udev_node("PARTLABEL=pinkié pie");
puts(n);
free(n);
n = fstab_node_to_udev_node("UUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
puts(n);
free(n);
n = fstab_node_to_udev_node("PARTUUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
puts(n);
free(n);
n = fstab_node_to_udev_node("PONIES=awesome");
puts(n);
free(n);
n = fstab_node_to_udev_node("/dev/xda1");
puts(n);
free(n);
}
static void test_get_files_in_directory(void) {
}
static void test_in_set(void) {
}
static void test_writing_tmpfile(void) {
char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
int fd, r;
assert(r >= 0);
assert(r == 0);
}
static void test_hexdump(void) {
unsigned i;
for (i = 0; i < ELEMENTSOF(data); i++)
data[i] = i*2;
}
static void test_log2i(void) {
}
static void test_foreach_string(void) {
const char * const t[] = {
"foo",
"bar",
"waldo",
};
const char *x;
unsigned i = 0;
assert_se(i == 3);
FOREACH_STRING(x, "zzz")
}
static void test_filename_is_safe(void) {
int i;
for (i=0; i<FILENAME_MAX+1; i++)
foo[i] = 'a';
}
static void test_string_has_cc(void) {
}
static void test_ascii_strlower(void) {
char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
}
static void test_files_same(void) {
char name[] = "/tmp/test-files_same.XXXXXX";
char name_alias[] = "/tmp/test-files_same.alias";
}
static void test_is_valid_documentation_url(void) {
}
static void test_file_in_same_dir(void) {
}
static void test_endswith(void) {
}
static void test_close_nointr(void) {
char name[] = "/tmp/test-test-close_nointr.XXXXXX";
int fd;
}
static void test_unlink_noerrno(void) {
char name[] = "/tmp/test-close_nointr.XXXXXX";
int fd;
{
errno = -42;
}
}
static void test_readlink_and_make_absolute(void) {
char tempdir[] = "/tmp/test-readlink_and_make_absolute";
char name[] = "/tmp/test-readlink_and_make_absolute/original";
char name2[] = "test-readlink_and_make_absolute/original";
char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
char *r = NULL;
free(r);
free(r);
}
static void test_read_one_char(void) {
char r;
bool need_nl;
char name[] = "/tmp/test-read_one_char.XXXXXX";
assert_se(r == 'c');
}
static void test_ignore_signals(void) {
}
static void test_strshorten(void) {
char s[] = "foobar";
}
log_open();
test_hexchar();
test_octchar();
test_decchar();
test_cescape();
test_u64log2();
test_strrep();
test_in_set();
test_hexdump();
test_log2i();
return 0;
}