Skip to content

Commit

Permalink
test: add tests for parse_ip_port
Browse files Browse the repository at this point in the history
This tests the basic functionality of parse_ip_port, which is used in
parse_wireaddr.

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 authored and rustyrussell committed Dec 21, 2017
1 parent 7ecccd5 commit 3e7aabe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lightningd/test/run-commit_tx
lightningd/test/run-find_my_path
lightningd/test/run-funding_tx
lightningd/test/run-key_derive
common/test/run-ip_port_parsing
wire/test/run-peer-wire
bitcoin/test/run-tx-encode
channeld/test/run-full_channel
Expand Down
52 changes: 52 additions & 0 deletions common/test/run-ip_port_parsing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "../common/wireaddr.c"

#include <stdio.h>
#include <assert.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire */
const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED)
{ fprintf(stderr, "fromwire called!\n"); abort(); }
/* Generated stub for fromwire_u16 */
u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u16 called!\n"); abort(); }
/* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
/* Generated stub for towire */
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "towire called!\n"); abort(); }
/* Generated stub for towire_u16 */
void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
{ fprintf(stderr, "towire_u16 called!\n"); abort(); }
/* Generated stub for towire_u8 */
void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
{ fprintf(stderr, "towire_u8 called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

int main(void)
{
tal_t *ctx = tal_tmpctx(NULL);
char *ip;
u16 port;

/* ret = getaddrinfo("[::1]:80", NULL, NULL, &res); */
assert(parse_ip_port(ctx, "[::1]:80", &ip, &port));
assert(streq(ip, "::1"));
assert(port == 80);

assert(!parse_ip_port(ctx, "::1", &ip, &port));
assert(streq(ip, "::1"));
assert(port == 0);

assert(parse_ip_port(ctx, "192.168.1.1:8000", &ip, &port));
assert(streq(ip, "192.168.1.1"));
assert(port == 8000);

assert(!parse_ip_port(ctx, "192.168.2.255", &ip, &port));
assert(streq(ip, "192.168.2.255"));
assert(port == 0);

tal_free(ctx);
return 0;
}

0 comments on commit 3e7aabe

Please sign in to comment.