~ubuntu-branches/ubuntu/precise/libssh/precise

« back to all changes in this revision

Viewing changes to tests/unittests/torture_isipaddr.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-06-15 15:48:07 UTC
  • mfrom: (1.1.10 upstream) (4.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110615154807-3muklcqfftr1vtch
Tags: 0.5.0-2
* debian/patches/0002-Check-for-NULL-pointers-in-string-c.patch:
  Consolidate patch (Should fix previous REJECT)
* Support multiarch spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define LIBSSH_STATIC
 
2
 
 
3
#include "torture.h"
 
4
 
 
5
#include "misc.c"
 
6
#include "error.c"
 
7
 
 
8
/*
 
9
 * Test the behavior of ssh_is_ipaddr()
 
10
 */
 
11
static void torture_ssh_is_ipaddr(void **state) {
 
12
  (void)state;
 
13
 
 
14
  assert_int_equal(ssh_is_ipaddr("127.0.0.1"),1);
 
15
  assert_int_equal(ssh_is_ipaddr("0.0.0.0"),1);
 
16
  assert_int_equal(ssh_is_ipaddr("1.1.1.1"),1);
 
17
  assert_int_equal(ssh_is_ipaddr("255.255.255.255"),1);
 
18
  assert_int_equal(ssh_is_ipaddr("128.128.128.128"),1);
 
19
  assert_int_equal(ssh_is_ipaddr("1.10.100.1"),1);
 
20
  assert_int_equal(ssh_is_ipaddr("0.1.10.100"),1);
 
21
 
 
22
  assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),1);
 
23
  assert_int_equal(ssh_is_ipaddr("fe80:0000:0000:0000:0202:b3ff:fe1e:8329"),1);
 
24
  assert_int_equal(ssh_is_ipaddr("fe80:0:0:0:202:b3ff:fe1e:8329"),1);
 
25
  assert_int_equal(ssh_is_ipaddr("fe80::202:b3ff:fe1e:8329"),1);
 
26
  assert_int_equal(ssh_is_ipaddr("::1"),1);
 
27
 
 
28
  assert_int_equal(ssh_is_ipaddr("::ffff:192.0.2.128"),1);
 
29
 
 
30
  assert_int_equal(ssh_is_ipaddr("0.0.0.0.0"),0);
 
31
  assert_int_equal(ssh_is_ipaddr("0.0.0.0.a"),0);
 
32
  assert_int_equal(ssh_is_ipaddr("a.0.0.0"),0);
 
33
  assert_int_equal(ssh_is_ipaddr("0a.0.0.0.0"),0);
 
34
  assert_int_equal(ssh_is_ipaddr(""),0);
 
35
  assert_int_equal(ssh_is_ipaddr("0.0.0."),0);
 
36
  assert_int_equal(ssh_is_ipaddr("0.0"),0);
 
37
  assert_int_equal(ssh_is_ipaddr("0"),0);
 
38
 
 
39
  assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334:1002"), 0);
 
40
  assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
 
41
  assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
 
42
  assert_int_equal(ssh_is_ipaddr(":1"), 0);
 
43
}
 
44
 
 
45
int torture_run_tests(void) {
 
46
    int rc;
 
47
    const UnitTest tests[] = {
 
48
        unit_test(torture_ssh_is_ipaddr)
 
49
    };
 
50
 
 
51
    ssh_init();
 
52
    rc=run_tests(tests);
 
53
    ssh_finalize();
 
54
    return rc;
 
55
}