test: replace single binary with per-module test binaries
This commit is contained in:
parent
d884a97c02
commit
36b9956b3a
20 changed files with 39 additions and 528 deletions
|
|
@ -1,59 +1,8 @@
|
||||||
check_PROGRAMS = ft_ping_test
|
check_PROGRAMS = test_tracker test_stats test_send
|
||||||
|
|
||||||
ft_ping_test_SOURCES = \
|
test_tracker_SOURCES = test_support.c ping/tracker/test_tracker.c
|
||||||
test_main.c \
|
test_stats_SOURCES = test_support.c ping/stats/test_stats.c
|
||||||
cli/handlers/test_handle_count.c \
|
test_send_SOURCES = test_support.c send/test_do_send.c
|
||||||
cli/handlers/test_handle_flood.c \
|
|
||||||
cli/handlers/test_handle_help.c \
|
|
||||||
cli/handlers/test_handle_interval.c \
|
|
||||||
cli/handlers/test_handle_quiet.c \
|
|
||||||
cli/handlers/test_handler_map.c \
|
|
||||||
cli/handlers/test_handle_size.c \
|
|
||||||
cli/handlers/test_handle_timeout.c \
|
|
||||||
cli/handlers/test_handle_ttl.c \
|
|
||||||
cli/handlers/test_handle_version.c \
|
|
||||||
cli/handlers/test_handle_verbose.c \
|
|
||||||
cli/handlers/test_handle_dont_fragment.c \
|
|
||||||
cli/handlers/test_handle_deadline.c \
|
|
||||||
cli/parse_utils/test_parse_int.c \
|
|
||||||
cli/parse_utils/test_parse_float.c \
|
|
||||||
cli/parse_utils/test_parse_inet_addr.c \
|
|
||||||
cli/parse_utils/test_parse_destinations.c \
|
|
||||||
ping/stats/test_stats.c \
|
|
||||||
ping/tracker/test_tracker.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/parse.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_count.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_dont_fragment.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_deadline.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_flood.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_help.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_interval.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_quiet.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/option_map.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_size.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_timeout.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_ttl.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_version.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/handlers/handle_verbose.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/parse_utils/parse_inet_addr.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/parse_utils/parse_destinations.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/config_free.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/messages/help.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/messages/version.c \
|
|
||||||
$(top_srcdir)/src/ping/cli/messages/error.c \
|
|
||||||
$(top_srcdir)/src/ping/tracker/init.c \
|
|
||||||
$(top_srcdir)/src/ping/tracker/record_send.c \
|
|
||||||
$(top_srcdir)/src/ping/tracker/record_recv.c \
|
|
||||||
$(top_srcdir)/src/ping/stats/stats_get.c \
|
|
||||||
$(top_srcdir)/src/ping/stats/stats_init.c \
|
|
||||||
$(top_srcdir)/src/ping/stats/stats_update.c
|
|
||||||
|
|
||||||
ft_ping_test_CPPFLAGS = \
|
|
||||||
-I $(top_srcdir)/includes \
|
|
||||||
-I $(top_srcdir)/libicmp/includes \
|
|
||||||
-I $(top_srcdir)/libcli/include \
|
|
||||||
-I $(top_srcdir)/tests \
|
|
||||||
-D_GNU_SOURCE
|
|
||||||
|
|
||||||
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
||||||
|
|
||||||
|
|
@ -69,15 +18,42 @@ else
|
||||||
SANITIZER_FLAGS =
|
SANITIZER_FLAGS =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ft_ping_test_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS)
|
TEST_CPPFLAGS = \
|
||||||
ft_ping_test_LDFLAGS = $(SANITIZER_FLAGS)
|
-I $(top_srcdir)/includes \
|
||||||
ft_ping_test_LDADD = \
|
-I $(top_srcdir)/libicmp/includes \
|
||||||
|
-I $(top_srcdir)/libcli/include \
|
||||||
|
-I $(top_srcdir)/tests \
|
||||||
|
-D_GNU_SOURCE
|
||||||
|
|
||||||
|
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS)
|
||||||
|
|
||||||
|
TEST_LDADD = \
|
||||||
|
$(top_builddir)/src/ping/libping_core.la \
|
||||||
$(top_srcdir)/libicmp/libicmp.a \
|
$(top_srcdir)/libicmp/libicmp.a \
|
||||||
$(top_builddir)/libcli/src/libcli.la \
|
$(top_builddir)/libcli/src/libcli.la \
|
||||||
$(CRITERION_LIBS) \
|
$(CRITERION_LIBS) \
|
||||||
-lm
|
-lm
|
||||||
|
|
||||||
TESTS = ft_ping_test
|
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
|
test_tracker_CFLAGS = $(TEST_CFLAGS)
|
||||||
|
test_tracker_LDFLAGS = $(SANITIZER_FLAGS)
|
||||||
|
test_tracker_LDADD = $(TEST_LDADD)
|
||||||
|
|
||||||
|
test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
|
test_stats_CFLAGS = $(TEST_CFLAGS)
|
||||||
|
test_stats_LDFLAGS = $(SANITIZER_FLAGS)
|
||||||
|
test_stats_LDADD = $(TEST_LDADD)
|
||||||
|
|
||||||
|
test_send_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
|
test_send_CFLAGS = $(TEST_CFLAGS)
|
||||||
|
test_send_LDFLAGS = $(SANITIZER_FLAGS) \
|
||||||
|
-Wl,--wrap=icmp_send_echo \
|
||||||
|
-Wl,--wrap=icmp_should_retry \
|
||||||
|
-Wl,--wrap=icmp_strerror \
|
||||||
|
-Wl,--wrap=ping_scheduler_arm
|
||||||
|
test_send_LDADD = $(TEST_LDADD)
|
||||||
|
|
||||||
|
TESTS = test_tracker test_stats test_send
|
||||||
|
|
||||||
# Version header needed by test_main.c
|
# Version header needed by test_main.c
|
||||||
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h
|
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: basic test */
|
|
||||||
Test(cli_handle_count, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "42";
|
|
||||||
int ret = cli_handle_count(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_eq(config.count, 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: invalid number */
|
|
||||||
Test(cli_handle_count, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-42";
|
|
||||||
int ret = cli_handle_count(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
Test(cli_handle_deadline, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "1.5";
|
|
||||||
int ret = cli_handle_deadline(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_float_eq(config.deadline, 1.5, .001);
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(cli_handle_deadline, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-1";
|
|
||||||
int ret = cli_handle_deadline(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "ping/ft_ping_flags.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
Test(handle_dont_fragment, flag_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
const int ret = cli_handle_dont_fragment(arg, &config);
|
|
||||||
|
|
||||||
cr_assert(HAS_FLAG(config.flags, FLAG_DONT_FRAGMENT));
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
#include "ping/ft_ping_flags.h"
|
|
||||||
|
|
||||||
/* Test 1: test flag*/
|
|
||||||
Test(handle_flood, flag_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
const int ret = cli_handle_flood(arg, &config);
|
|
||||||
|
|
||||||
cr_assert(HAS_FLAG(config.flags, FLAG_FLOOD));
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: exit code test */
|
|
||||||
Test(handle_help, exit_code)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
int ret = cli_handle_help(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: basic test */
|
|
||||||
Test(cli_handle_interval, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = ".42";
|
|
||||||
int ret = cli_handle_interval(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_float_eq(config.interval, .42, .001);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: invalid number */
|
|
||||||
Test(cli_handle_interval, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-42";
|
|
||||||
int ret = cli_handle_interval(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "ping/ft_ping_flags.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
#include <criterion/criterion.h>
|
|
||||||
|
|
||||||
/* Test 1: test flag*/
|
|
||||||
Test(handle_quiet, flag_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
const int ret = cli_handle_quiet(arg, &config);
|
|
||||||
|
|
||||||
cr_assert(HAS_FLAG(config.flags, FLAG_QUIET));
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: basic test */
|
|
||||||
Test(cli_handle_size, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "65527";
|
|
||||||
int ret = cli_handle_size(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_eq(config.packet_size, 65527);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: invalid number */
|
|
||||||
Test(cli_handle_size, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-42";
|
|
||||||
int ret = cli_handle_size(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 3: max test */
|
|
||||||
Test(cli_handle_size, limit_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "65528";
|
|
||||||
int ret = cli_handle_size(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: basic test */
|
|
||||||
Test(cli_handle_timeout, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = ".42";
|
|
||||||
int ret = cli_handle_timeout(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_float_eq(config.timeout, .42, .001);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: invalid number */
|
|
||||||
Test(cli_handle_timeout, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-42";
|
|
||||||
int ret = cli_handle_timeout(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: basic test */
|
|
||||||
Test(cli_handle_ttl, valid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "255";
|
|
||||||
int ret = cli_handle_ttl(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_eq(config.ttl, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: invalid number */
|
|
||||||
Test(cli_handle_ttl, invalid_number)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "-1";
|
|
||||||
int ret = cli_handle_ttl(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 3: max test */
|
|
||||||
Test(cli_handle_ttl, limit_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "256";
|
|
||||||
int ret = cli_handle_ttl(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "ping/ft_ping_flags.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
#include <criterion/criterion.h>
|
|
||||||
|
|
||||||
/* Test 1: test flag*/
|
|
||||||
Test(handle_verbose, flag_test)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
const int ret = cli_handle_verbose(arg, &config);
|
|
||||||
|
|
||||||
cr_assert(HAS_FLAG(config.flags, FLAG_VERBOSE));
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
|
|
||||||
/* Test 1: exit code test */
|
|
||||||
Test(handle_version, exit_code)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
const char *arg = "";
|
|
||||||
int ret = cli_handle_version(arg, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
/* Test 1: g_options is null terminated */
|
|
||||||
Test(_test_handler_map, always_pass)
|
|
||||||
{
|
|
||||||
size_t i = 0;
|
|
||||||
for (i = 0; NULL != g_options[i].description; ++i);
|
|
||||||
|
|
||||||
cr_assert(g_options[i].description == NULL);
|
|
||||||
cr_assert(g_options[i].arg_type == 0);
|
|
||||||
cr_assert(g_options[i].handler == NULL);
|
|
||||||
cr_assert(g_options[i].has_arg == 0);
|
|
||||||
cr_assert(g_options[i].long_opt == NULL);
|
|
||||||
cr_assert(g_options[i].short_opt == 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "ping/cli.h"
|
|
||||||
#include "internal/ping/parse_utils.h"
|
|
||||||
|
|
||||||
Test(cli_parse_destinations, no_destinations)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
char *argv[] = {"ping"};
|
|
||||||
int argc = 1;
|
|
||||||
int ret = cli_parse_destinations(argc, argv, argc, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(cli_parse_destinations, single_destination)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
char *argv[] = {"ping", "127.0.0.1"};
|
|
||||||
int argc = 2;
|
|
||||||
int ret = cli_parse_destinations(argc, argv, 1, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_eq(config.nb_destinations, (size_t)1);
|
|
||||||
free(config.destinations);
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(cli_parse_destinations, multiple_destinations)
|
|
||||||
{
|
|
||||||
struct ping_config config = {0};
|
|
||||||
char *argv[] = {"ping", "127.0.0.1", "127.0.0.2"};
|
|
||||||
int argc = 3;
|
|
||||||
int ret = cli_parse_destinations(argc, argv, 1, &config);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, CLI_SUCCESS);
|
|
||||||
cr_assert_eq(config.nb_destinations, (size_t)2);
|
|
||||||
free(config.destinations);
|
|
||||||
}
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "internal/cli/parse_utils.h"
|
|
||||||
|
|
||||||
/* Test 1: Valid simple number */
|
|
||||||
Test(parse_float, valid_number)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float("42.42", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_float_eq(result, 42.42, 0.0001);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: Zero */
|
|
||||||
Test(parse_float, zero)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float("0", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_float_eq(result, 0, 0.0001);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 3: NULL pointer */
|
|
||||||
Test(parse_float, null_pointer)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float(NULL, &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 4: Empty string */
|
|
||||||
Test(parse_float, empty_string)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float("", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 5: Negative number (cli_parse_float accepts negatives; use cli_parse_ufloat to reject) */
|
|
||||||
Test(parse_float, negative_number)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float("-42", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_float_eq(result, -42.0f, 0.001f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 6: Invalid characters */
|
|
||||||
Test(parse_float, invalid_characters)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float("42abc", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 7: Dot + number */
|
|
||||||
Test(parse_float, dot)
|
|
||||||
{
|
|
||||||
float result;
|
|
||||||
int ret = cli_parse_float(".42", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_float_eq(result, 0.42, 0.0001);
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "ping/ping.h"
|
|
||||||
#include "internal/ping/parse_utils.h"
|
|
||||||
|
|
||||||
Test(cli_parse_inet_addr, valid_ip)
|
|
||||||
{
|
|
||||||
struct destinations out = {0};
|
|
||||||
int ret = cli_parse_inet_addr("127.0.0.1", &out);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_str_eq(out.dom, "127.0.0.1");
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(cli_parse_inet_addr, invalid_host)
|
|
||||||
{
|
|
||||||
struct destinations out = {0};
|
|
||||||
int ret = cli_parse_inet_addr("invalid.host.local", &out);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "internal/cli/parse_utils.h"
|
|
||||||
|
|
||||||
/* Test 1: Valid simple number */
|
|
||||||
Test(parse_uint64, valid_number)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("42", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_eq(result, 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: Zero */
|
|
||||||
Test(parse_uint64, zero)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("0", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 0);
|
|
||||||
cr_assert_eq(result, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 3: NULL pointer */
|
|
||||||
Test(parse_uint64, null_pointer)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64(NULL, &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 4: Empty string */
|
|
||||||
Test(parse_uint64, empty_string)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 5: Negative number */
|
|
||||||
Test(parse_uint64, negative_number)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("-42", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 6: Invalid characters */
|
|
||||||
Test(parse_uint64, invalid_characters)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("42abc", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 7: Overflow */
|
|
||||||
Test(parse_uint64, overflow)
|
|
||||||
{
|
|
||||||
uint64_t result;
|
|
||||||
int ret = cli_parse_uint64("18446744073709551616", &result);
|
|
||||||
|
|
||||||
cr_assert_eq(ret, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
#include <criterion/criterion.h>
|
|
||||||
#include "version_gen.h"
|
|
||||||
|
|
||||||
char *g_prog_name = "ft_ping";
|
|
||||||
Test(dummy, always_pass)
|
|
||||||
{
|
|
||||||
cr_assert(1, "Hello, world!");
|
|
||||||
}
|
|
||||||
|
|
||||||
4
tests/test_support.c
Normal file
4
tests/test_support.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#include "version_gen.h"
|
||||||
|
|
||||||
|
char *g_prog_name = "ft_ping";
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue