mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
tests: modify ipacl-test to use 'check' framework
This commit is contained in:
parent
deeb0f05b3
commit
70acd7bf66
2 changed files with 36 additions and 15 deletions
|
|
@ -335,9 +335,9 @@ get_binary_name_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMIN
|
||||||
get_binary_name_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
|
get_binary_name_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
|
||||||
|
|
||||||
ipacl_test_SOURCES = tests/ipacl-test.c
|
ipacl_test_SOURCES = tests/ipacl-test.c
|
||||||
ipacl_test_CFLAGS = $(AM_CFLAGS)
|
ipacl_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
|
||||||
ipacl_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
|
ipacl_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
|
||||||
ipacl_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
|
ipacl_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
|
||||||
|
|
||||||
hook_list_test_SOURCES = tests/hook-list-test.c
|
hook_list_test_SOURCES = tests/hook-list-test.c
|
||||||
hook_list_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
|
hook_list_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
#ifdef HAVE_NETINET_IN_H
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -27,15 +29,16 @@ static void do_ip_acl_check(const char *s, int fd, int expected) {
|
||||||
pa_ip_acl *acl;
|
pa_ip_acl *acl;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
pa_assert_se(acl = pa_ip_acl_new(s));
|
acl = pa_ip_acl_new(s);
|
||||||
|
fail_unless(acl != NULL);
|
||||||
result = pa_ip_acl_check(acl, fd);
|
result = pa_ip_acl_check(acl, fd);
|
||||||
pa_ip_acl_free(acl);
|
pa_ip_acl_free(acl);
|
||||||
|
|
||||||
pa_log_info("%-20s result=%u (should be %u)", s, result, expected);
|
pa_log_info("%-20s result=%u (should be %u)", s, result, expected);
|
||||||
pa_assert(result == expected);
|
fail_unless(result == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
START_TEST (ipacl_test) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
struct sockaddr_in6 sa6;
|
struct sockaddr_in6 sa6;
|
||||||
|
|
@ -43,18 +46,15 @@ int main(int argc, char *argv[]) {
|
||||||
int fd;
|
int fd;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!getenv("MAKE_CHECK"))
|
|
||||||
pa_log_set_level(PA_LOG_DEBUG);
|
|
||||||
|
|
||||||
fd = socket(PF_INET, SOCK_STREAM, 0);
|
fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
pa_assert(fd >= 0);
|
fail_unless(fd >= 0);
|
||||||
|
|
||||||
sa.sin_family = AF_INET;
|
sa.sin_family = AF_INET;
|
||||||
sa.sin_port = htons(22);
|
sa.sin_port = htons(22);
|
||||||
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
|
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||||
|
|
||||||
r = connect(fd, (struct sockaddr*) &sa, sizeof(sa));
|
r = connect(fd, (struct sockaddr*) &sa, sizeof(sa));
|
||||||
pa_assert(r >= 0);
|
fail_unless(r >= 0);
|
||||||
|
|
||||||
do_ip_acl_check("127.0.0.1", fd, 1);
|
do_ip_acl_check("127.0.0.1", fd, 1);
|
||||||
do_ip_acl_check("127.0.0.2/0", fd, 1);
|
do_ip_acl_check("127.0.0.2/0", fd, 1);
|
||||||
|
|
@ -70,16 +70,16 @@ int main(int argc, char *argv[]) {
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if ( (fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0 ) {
|
if ( (fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0 ) {
|
||||||
pa_log_error("Unable to open IPv6 socket, IPv6 tests ignored");
|
pa_log_error("Unable to open IPv6 socket, IPv6 tests ignored");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sa6, 0, sizeof(sa6));
|
memset(&sa6, 0, sizeof(sa6));
|
||||||
sa6.sin6_family = AF_INET6;
|
sa6.sin6_family = AF_INET6;
|
||||||
sa6.sin6_port = htons(22);
|
sa6.sin6_port = htons(22);
|
||||||
pa_assert_se(inet_pton(AF_INET6, "::1", &sa6.sin6_addr) == 1);
|
fail_unless(inet_pton(AF_INET6, "::1", &sa6.sin6_addr) == 1);
|
||||||
|
|
||||||
r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6));
|
r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6));
|
||||||
pa_assert(r >= 0);
|
fail_unless(r >= 0);
|
||||||
|
|
||||||
do_ip_acl_check("::1", fd, 1);
|
do_ip_acl_check("::1", fd, 1);
|
||||||
do_ip_acl_check("::1/9", fd, 1);
|
do_ip_acl_check("::1/9", fd, 1);
|
||||||
|
|
@ -90,6 +90,27 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
return 0;
|
END_TEST
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int failed = 0;
|
||||||
|
Suite *s;
|
||||||
|
TCase *tc;
|
||||||
|
SRunner *sr;
|
||||||
|
|
||||||
|
if (!getenv("MAKE_CHECK"))
|
||||||
|
pa_log_set_level(PA_LOG_DEBUG);
|
||||||
|
|
||||||
|
s = suite_create("IP ACL");
|
||||||
|
tc = tcase_create("ipacl");
|
||||||
|
tcase_add_test(tc, ipacl_test);
|
||||||
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
sr = srunner_create(s);
|
||||||
|
srunner_run_all(sr, CK_NORMAL);
|
||||||
|
failed = srunner_ntests_failed(sr);
|
||||||
|
srunner_free(sr);
|
||||||
|
|
||||||
|
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue