2011-02-12 17:06:15 +03:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
#include "misc.c"
|
2011-02-12 17:06:15 +03:00
|
|
|
|
|
|
|
/*
|
2011-02-12 21:12:39 +03:00
|
|
|
* Test the behavior of ssh_is_ipaddr()
|
2011-02-12 17:06:15 +03:00
|
|
|
*/
|
2011-02-12 21:12:39 +03:00
|
|
|
static void torture_ssh_is_ipaddr(void **state) {
|
2011-02-12 17:06:15 +03:00
|
|
|
(void)state;
|
2011-02-12 21:14:30 +03:00
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("127.0.0.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("1.1.1.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("255.255.255.255"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("128.128.128.128"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("1.10.100.1"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.1.10.100"),1);
|
2011-02-12 17:06:15 +03:00
|
|
|
|
2011-02-12 21:14:30 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:0000:0000:0000:0202:b3ff:fe1e:8329"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80:0:0:0:202:b3ff:fe1e:8329"),1);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("fe80::202:b3ff:fe1e:8329"),1);
|
|
|
|
|
|
|
|
assert_int_equal(ssh_is_ipaddr("::ffff:192.0.2.128"),1);
|
|
|
|
|
2011-02-12 21:12:39 +03:00
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0.0.a"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("a.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0a.0.0.0.0"),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr(""),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0."),0);
|
|
|
|
assert_int_equal(ssh_is_ipaddr("0.0.0"),0);
|
2011-02-12 17:06:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int torture_run_tests(void) {
|
|
|
|
int rc;
|
|
|
|
const UnitTest tests[] = {
|
2011-02-12 21:12:39 +03:00
|
|
|
unit_test(torture_ssh_is_ipaddr)
|
2011-02-12 17:06:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
ssh_init();
|
|
|
|
rc=run_tests(tests);
|
|
|
|
ssh_finalize();
|
|
|
|
return rc;
|
|
|
|
}
|