@@ -137,6 +137,8 @@
|
||||
/tags
|
||||
/test-architecture
|
||||
/test-audit-type
|
||||
/test-af-list
|
||||
/test-arphrd-list
|
||||
/test-async
|
||||
/test-barrier
|
||||
/test-bitmap
|
||||
|
||||
+14
@@ -1437,6 +1437,8 @@ tests += \
|
||||
test-cap-list \
|
||||
test-sigbus \
|
||||
test-verbs \
|
||||
test-af-list \
|
||||
test-arphrd-list \
|
||||
test-dns-domain
|
||||
|
||||
EXTRA_DIST += \
|
||||
@@ -2047,6 +2049,18 @@ test_bus_policy_LDADD = \
|
||||
libbus-proxy-core.la \
|
||||
libshared.la
|
||||
|
||||
test_af_list_SOURCES = \
|
||||
src/test/test-af-list.c
|
||||
|
||||
test_af_list_LDADD = \
|
||||
libbasic.la
|
||||
|
||||
test_arphrd_list_SOURCES = \
|
||||
src/test/test-arphrd-list.c
|
||||
|
||||
test_arphrd_list_LDADD = \
|
||||
libbasic.la
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
## .PHONY so it always rebuilds it
|
||||
.PHONY: coverage lcov-run lcov-report coverage-sync
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
This file is part of systemd
|
||||
|
||||
Copyright 2015 Daniel Mack
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
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 <sys/socket.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
|
||||
static const struct af_name* lookup_af(register const char *str, register unsigned int len);
|
||||
|
||||
#include "af-list.h"
|
||||
#include "af-to-name.h"
|
||||
#include "af-from-name.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(af_names); i++) {
|
||||
if (af_names[i]) {
|
||||
assert_se(streq(af_to_name(i), af_names[i]));
|
||||
assert_se(af_from_name(af_names[i]) == (int) i);
|
||||
}
|
||||
}
|
||||
|
||||
assert_se(af_to_name(af_max()) == NULL);
|
||||
assert_se(af_to_name(-1) == NULL);
|
||||
assert_se(af_from_name("huddlduddl") == AF_UNSPEC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
This file is part of systemd
|
||||
|
||||
Copyright 2015 Daniel Mack
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
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 <net/if_arp.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
|
||||
static const struct arphrd_name* lookup_arphrd(register const char *str, register unsigned int len);
|
||||
|
||||
#include "arphrd-list.h"
|
||||
#include "arphrd-to-name.h"
|
||||
#include "arphrd-from-name.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i = 1; i < ELEMENTSOF(arphrd_names); i++) {
|
||||
if (arphrd_names[i]) {
|
||||
assert_se(streq(arphrd_to_name(i), arphrd_names[i]));
|
||||
assert_se(arphrd_from_name(arphrd_names[i]) == (int) i);
|
||||
}
|
||||
}
|
||||
|
||||
assert_se(arphrd_to_name(arphrd_max()) == NULL);
|
||||
assert_se(arphrd_to_name(0) == NULL);
|
||||
assert_se(arphrd_from_name("huddlduddl") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -158,6 +158,20 @@ static void test_socket_address_is_netlink(void) {
|
||||
assert_se(!socket_address_is_netlink(&a, "route 1"));
|
||||
}
|
||||
|
||||
static void test_in_addr_is_null(void) {
|
||||
|
||||
union in_addr_union i = {};
|
||||
|
||||
assert_se(in_addr_is_null(AF_INET, &i) == true);
|
||||
assert_se(in_addr_is_null(AF_INET6, &i) == true);
|
||||
|
||||
i.in.s_addr = 0x1000000;
|
||||
assert_se(in_addr_is_null(AF_INET, &i) == false);
|
||||
assert_se(in_addr_is_null(AF_INET6, &i) == false);
|
||||
|
||||
assert_se(in_addr_is_null(-1, &i) == -EAFNOSUPPORT);
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigned apl, const char *b, unsigned bpl, int result) {
|
||||
union in_addr_union ua, ub;
|
||||
|
||||
@@ -340,6 +354,7 @@ int main(int argc, char *argv[]) {
|
||||
test_socket_address_is();
|
||||
test_socket_address_is_netlink();
|
||||
|
||||
test_in_addr_is_null();
|
||||
test_in_addr_prefix_intersect();
|
||||
test_in_addr_prefix_next();
|
||||
test_in_addr_to_string();
|
||||
|
||||
@@ -280,6 +280,39 @@ static void test_parse_uid(void) {
|
||||
r = parse_uid("100", &uid);
|
||||
assert_se(r == 0);
|
||||
assert_se(uid == 100);
|
||||
|
||||
r = parse_uid("65535", &uid);
|
||||
assert_se(r == -ENXIO);
|
||||
}
|
||||
|
||||
static void test_safe_atou16(void) {
|
||||
int r;
|
||||
uint16_t l;
|
||||
|
||||
r = safe_atou16("12345", &l);
|
||||
assert_se(r == 0);
|
||||
assert_se(l == 12345);
|
||||
|
||||
r = safe_atou16("123456", &l);
|
||||
assert_se(r == -ERANGE);
|
||||
|
||||
r = safe_atou16("junk", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoi16(void) {
|
||||
int r;
|
||||
int16_t l;
|
||||
|
||||
r = safe_atoi16("-12345", &l);
|
||||
assert_se(r == 0);
|
||||
assert_se(l == -12345);
|
||||
|
||||
r = safe_atoi16("36536", &l);
|
||||
assert_se(r == -ERANGE);
|
||||
|
||||
r = safe_atoi16("junk", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atolli(void) {
|
||||
@@ -583,6 +616,15 @@ static void test_unbase32hexmem(void) {
|
||||
assert_se(unbase32hexmem("AAAAB===", strlen("AAAAB==="), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("AAAAAAB=", strlen("AAAAAAB="), true, &mem, &len) == -EINVAL);
|
||||
|
||||
assert_se(unbase32hexmem("XPNMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CXNMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPXMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPNXUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPNMXOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPNMUXJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPNMUOX1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
assert_se(unbase32hexmem("CPNMUOJX", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL);
|
||||
|
||||
assert_se(unbase32hexmem("", strlen(""), false, &mem, &len) == 0);
|
||||
assert_se(streq(strndupa(mem, len), ""));
|
||||
free(mem);
|
||||
@@ -1249,6 +1291,16 @@ static void test_endswith(void) {
|
||||
assert_se(!endswith("foobar", "foobarfoofoo"));
|
||||
}
|
||||
|
||||
static void test_endswith_no_case(void) {
|
||||
assert_se(endswith_no_case("fooBAR", "bar"));
|
||||
assert_se(endswith_no_case("foobar", ""));
|
||||
assert_se(endswith_no_case("foobar", "FOOBAR"));
|
||||
assert_se(endswith_no_case("", ""));
|
||||
|
||||
assert_se(!endswith_no_case("foobar", "FOO"));
|
||||
assert_se(!endswith_no_case("foobar", "FOOBARFOOFOO"));
|
||||
}
|
||||
|
||||
static void test_close_nointr(void) {
|
||||
char name[] = "/tmp/test-test-close_nointr.XXXXXX";
|
||||
int fd;
|
||||
@@ -2099,6 +2151,8 @@ int main(int argc, char *argv[]) {
|
||||
test_parse_boolean();
|
||||
test_parse_pid();
|
||||
test_parse_uid();
|
||||
test_safe_atou16();
|
||||
test_safe_atoi16();
|
||||
test_safe_atolli();
|
||||
test_safe_atod();
|
||||
test_strappend();
|
||||
@@ -2148,6 +2202,7 @@ int main(int argc, char *argv[]) {
|
||||
test_is_valid_documentation_url();
|
||||
test_file_in_same_dir();
|
||||
test_endswith();
|
||||
test_endswith_no_case();
|
||||
test_close_nointr();
|
||||
test_unlink_noerrno();
|
||||
test_readlink_and_make_absolute();
|
||||
|
||||
Reference in New Issue
Block a user