Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Oct 15, 2020
1 parent 1be8151 commit eaf841e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions base/hosts_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ Ensure (hosts, gvm_hosts_new_with_max_returns_error)
assert_that (gvm_hosts_new_with_max ("127.0.0.1|127.0.0.2", 2), is_null);
}

Ensure (hosts, gvm_hosts_move_host_to_end)
{
gvm_hosts_t *hosts = NULL;
gvm_host_t *host = NULL;
int totalhosts;
size_t current;

hosts = gvm_hosts_new("192.168.0.0/28");

// Get first host
host = gvm_hosts_next (hosts);

totalhosts = gvm_hosts_count (hosts);
assert_that (totalhosts, is_equal_to (14));

while (g_strcmp0 (gvm_host_value_str (host), "192.168.0.9"))
{
host = gvm_hosts_next (hosts);
}
assert_that (g_strcmp0 (gvm_host_value_str (host), "192.168.0.9"), is_equal_to (0));

current = hosts->current;
gvm_hosts_move_current_host_to_end(hosts);
assert_that (hosts->current, is_equal_to (current - 1));

host = gvm_hosts_next (hosts);
assert_that (g_strcmp0 (gvm_host_value_str (host), "192.168.0.10"), is_equal_to (0));
assert_that (g_strcmp0 (gvm_host_value_str (hosts->hosts[totalhosts - 1]), "192.168.0.9"), is_equal_to (0));

gvm_hosts_free (hosts);
}

/* Test suite. */

int
Expand Down Expand Up @@ -245,6 +277,8 @@ main (int argc, char **argv)
add_test_with_context (suite, hosts, gvm_hosts_new_with_max_returns_error);
add_test_with_context (suite, hosts, gvm_hosts_new_with_max_returns_success);

add_test_with_context (suite, hosts, gvm_hosts_move_host_to_end);

if (argc > 1)
return run_single_test (suite, argv[1], create_text_reporter ());

Expand Down

0 comments on commit eaf841e

Please sign in to comment.