From d6f2e199243ef6eb4b1b96dbff16793a5fe2c202 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 17 Jul 2009 18:38:46 +0000 Subject: [PATCH] Unit tests for bufferevent_get(fd|_underlying) svn:r1351 --- test/regress_bufferevent.c | 12 ++++++++++++ test/tinytest_macros.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/test/regress_bufferevent.c b/test/regress_bufferevent.c index 0eca8d1a..8130eb66 100644 --- a/test/regress_bufferevent.c +++ b/test/regress_bufferevent.c @@ -128,9 +128,13 @@ test_bufferevent_impl(int use_pair) bev2 = pair[1]; bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL); bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL); + tt_int_op(bufferevent_getfd(bev1), ==, -1); + tt_ptr_op(bufferevent_get_underlying(bev1), ==, NULL); } else { bev1 = bufferevent_new(pair[0], readcb, writecb, errorcb, NULL); bev2 = bufferevent_new(pair[1], readcb, writecb, errorcb, NULL); + tt_int_op(bufferevent_getfd(bev1), ==, pair[0]); + tt_ptr_op(bufferevent_get_underlying(bev1), ==, NULL); } bufferevent_disable(bev1, EV_READ); @@ -316,6 +320,7 @@ static void test_bufferevent_filters_impl(int use_pair) { struct bufferevent *bev1 = NULL, *bev2 = NULL; + struct bufferevent *bev1_base = NULL, *bev2_base = NULL; char buffer[8333]; int i; @@ -330,6 +335,8 @@ test_bufferevent_filters_impl(int use_pair) bev1 = bufferevent_socket_new(NULL, pair[0], 0); bev2 = bufferevent_socket_new(NULL, pair[1], 0); } + bev1_base = bev1; + bev2_base = bev2; for (i = 0; i < sizeof(buffer); i++) buffer[i] = i; @@ -342,6 +349,11 @@ test_bufferevent_filters_impl(int use_pair) bufferevent_setcb(bev1, NULL, writecb, errorcb, NULL); bufferevent_setcb(bev2, readcb, NULL, errorcb, NULL); + tt_ptr_op(bufferevent_get_underlying(bev1), ==, bev1_base); + tt_ptr_op(bufferevent_get_underlying(bev2), ==, bev2_base); + tt_ptr_op(bufferevent_getfd(bev1), ==, -1); + tt_ptr_op(bufferevent_getfd(bev2), ==, -1); + bufferevent_disable(bev1, EV_READ); bufferevent_enable(bev2, EV_READ); /* insert some filters */ diff --git a/test/tinytest_macros.h b/test/tinytest_macros.h index e3373d98..d989de99 100644 --- a/test/tinytest_macros.h +++ b/test/tinytest_macros.h @@ -134,6 +134,9 @@ #define tt_uint_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long, \ (_val1 op _val2),"%lu") +#define tt_ptr_op(a,op,b) \ + tt_assert_test_type(a,b,#a" "#op" "#b,void*, \ + (_val1 op _val2),"%p") #define tt_str_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ -- 2.40.0