Browse Source
We get structeq and htable updates we don't need for free. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>fee-tracking2
Rusty Russell
6 years ago
11 changed files with 255 additions and 45 deletions
@ -1,3 +1,3 @@ |
|||
CCAN imported from http://ccodearchive.net. |
|||
|
|||
CCAN version: init-2446-g1b4ed377 |
|||
CCAN version: init-2451-gfedf5151 |
|||
|
@ -0,0 +1,45 @@ |
|||
#include <ccan/io/io.h> |
|||
/* Include the C files directly. */ |
|||
#include <ccan/io/poll.c> |
|||
#include <ccan/io/io.c> |
|||
#include <ccan/tap/tap.h> |
|||
#include <sys/wait.h> |
|||
#include <stdio.h> |
|||
|
|||
static size_t len; |
|||
|
|||
static void finished_read(struct io_conn *conn, int *expect) |
|||
{ |
|||
ok1(errno == *expect); |
|||
} |
|||
|
|||
static struct io_plan *init_conn_read(struct io_conn *conn, int *expect) |
|||
{ |
|||
io_set_finish(conn, finished_read, expect); |
|||
return io_read(conn, &expect, sizeof(expect), io_never, expect); |
|||
} |
|||
|
|||
static struct io_plan *init_conn_read_partial(struct io_conn *conn, int *expect) |
|||
{ |
|||
io_set_finish(conn, finished_read, expect); |
|||
return io_read_partial(conn, &expect, sizeof(expect), &len, |
|||
io_never, expect); |
|||
} |
|||
|
|||
int main(void) |
|||
{ |
|||
int fd, expect_errno = 0; |
|||
|
|||
/* This is how many tests you plan to run */ |
|||
plan_tests(2); |
|||
fd = open("/dev/null", O_RDONLY); |
|||
io_new_conn(NULL, fd, init_conn_read, &expect_errno); |
|||
|
|||
fd = open("/dev/null", O_RDONLY); |
|||
io_new_conn(NULL, fd, init_conn_read_partial, &expect_errno); |
|||
|
|||
io_loop(NULL, NULL); |
|||
|
|||
/* This exits depending on whether all tests passed */ |
|||
return exit_status(); |
|||
} |
@ -0,0 +1,20 @@ |
|||
#include <ccan/structeq/structeq.h> |
|||
|
|||
struct mydata { |
|||
int start, end; |
|||
int pad; |
|||
}; |
|||
#ifdef FAIL |
|||
#define PADDING -1 |
|||
#else |
|||
#define PADDING -(int)sizeof(int) |
|||
#endif |
|||
|
|||
STRUCTEQ_DEF(mydata, PADDING, start, end); |
|||
|
|||
int main(void) |
|||
{ |
|||
struct mydata a = { 0, 100 }; |
|||
|
|||
return mydata_eq(&a, &a); |
|||
} |
@ -0,0 +1,39 @@ |
|||
#include <ccan/structeq/structeq.h> |
|||
#include <ccan/tap/tap.h> |
|||
|
|||
/* In theory, this could be generated without padding, if alignof(int) were 0,
|
|||
* and test would fail. Call me when that happens. */ |
|||
struct mydata { |
|||
char start; |
|||
int end; |
|||
}; |
|||
|
|||
STRUCTEQ_DEF(mydata, -3, start, end); |
|||
|
|||
struct mydata2 { |
|||
char start; |
|||
int end; |
|||
}; |
|||
|
|||
STRUCTEQ_DEF(mydata2, -4, start, end); |
|||
|
|||
int main(void) |
|||
{ |
|||
struct mydata a, b; |
|||
|
|||
/* This is how many tests you plan to run */ |
|||
plan_tests(3); |
|||
|
|||
a.start = 0; |
|||
a.end = 100; |
|||
ok1(mydata_eq(&a, &a)); |
|||
|
|||
b = a; |
|||
ok1(mydata_eq(&a, &b)); |
|||
|
|||
b.end++; |
|||
ok1(!mydata_eq(&a, &b)); |
|||
|
|||
/* This exits depending on whether all tests passed */ |
|||
return exit_status(); |
|||
} |
Loading…
Reference in new issue