| 977 close(fds[0]); |
972 close(fds[0]); |
| 978 close(fds[1]); |
973 close(fds[1]); |
| 979 http_client_free(client); |
974 http_client_free(client); |
| 980 } |
975 } |
| 981 |
976 |
| 982 static CX_TEST(test_http_client_io_simple) { |
977 static CX_TEST_SUBROUTINE(test_http_client_io_simple, size_t blocksz) { |
| 983 char *response_str = |
978 char *response_str = |
| 984 "HTTP/1.1 200 OK\r\n" |
979 "HTTP/1.1 200 OK\r\n" |
| 985 "Host: localhost\r\n" |
980 "Host: localhost\r\n" |
| 986 "Content-length: 13\r\n" |
981 "Content-length: 13\r\n" |
| 987 "\r\n" |
982 "\r\n" |
| 988 "Hello World!\n"; |
983 "Hello World!\n"; |
| 989 CxBuffer *buf = cxBufferCreate(NULL, NULL, 1024, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
984 CxBuffer *buf = cxBufferCreate(NULL, NULL, 1024, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
| 990 |
985 |
| 991 CX_TEST_DO { |
986 CX_TEST_CALL_SUBROUTINE(test_http_client_io, response_str, 200, "OK", buf, blocksz); |
| 992 CX_TEST_CALL_SUBROUTINE(test_http_client_io, response_str, 200, "OK", buf, 1024); |
987 CX_TEST_ASSERT(buf->size == 13); |
| 993 CX_TEST_ASSERT(buf->size == 13); |
988 CX_TEST_ASSERT(!cx_strcmp(cx_strn(buf->space, buf->size), "Hello World!\n")); |
| 994 CX_TEST_ASSERT(!cx_strcmp(cx_strn(buf->space, buf->size), "Hello World!\n")); |
|
| 995 } |
|
| 996 |
989 |
| 997 cxBufferFree(buf); |
990 cxBufferFree(buf); |
| 998 } |
991 } |
| |
992 |
| |
993 static CX_TEST(test_http_client_io_simple_1b) { |
| |
994 CX_TEST_DO { |
| |
995 CX_TEST_CALL_SUBROUTINE(test_http_client_io_simple, 1); |
| |
996 } |
| |
997 } |
| |
998 |
| |
999 static CX_TEST(test_http_client_io_simple_2b) { |
| |
1000 CX_TEST_DO { |
| |
1001 CX_TEST_CALL_SUBROUTINE(test_http_client_io_simple, 2); |
| |
1002 } |
| |
1003 } |
| |
1004 |
| |
1005 static CX_TEST(test_http_client_io_simple_3b) { |
| |
1006 CX_TEST_DO { |
| |
1007 CX_TEST_CALL_SUBROUTINE(test_http_client_io_simple, 3); |
| |
1008 } |
| |
1009 } |
| |
1010 |
| |
1011 static CX_TEST(test_http_client_io_simple_16b) { |
| |
1012 CX_TEST_DO { |
| |
1013 CX_TEST_CALL_SUBROUTINE(test_http_client_io_simple, 16); |
| |
1014 } |
| |
1015 } |
| |
1016 |
| |
1017 static CX_TEST(test_http_client_io_simple_512b) { |
| |
1018 CX_TEST_DO { |
| |
1019 CX_TEST_CALL_SUBROUTINE(test_http_client_io_simple, 512); |
| |
1020 } |
| |
1021 } |
| |
1022 |
| |
1023 static CX_TEST_SUBROUTINE(test_http_client_io_chunked_transfer, size_t blocksz) { |
| |
1024 char *response_str = |
| |
1025 "HTTP/1.1 200 OK\r\n" |
| |
1026 "Host: localhost\r\n" |
| |
1027 "Transfer-encoding: chunked\r\n" |
| |
1028 "\r\n" |
| |
1029 "d\r\n" |
| |
1030 "Hello World!\n" |
| |
1031 "\r\n" |
| |
1032 "0\r\n\r\n"; |
| |
1033 CxBuffer *buf = cxBufferCreate(NULL, NULL, 1024, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
| |
1034 |
| |
1035 CX_TEST_CALL_SUBROUTINE(test_http_client_io, response_str, 200, "OK", buf, blocksz); |
| |
1036 CX_TEST_ASSERT(buf->size == 13); |
| |
1037 CX_TEST_ASSERT(!cx_strcmp(cx_strn(buf->space, buf->size), "Hello World!\n")); |
| |
1038 |
| |
1039 cxBufferFree(buf); |
| |
1040 } |
| |
1041 |
| |
1042 static CX_TEST(test_http_client_io_chunked_transfer_1b) { |
| |
1043 CX_TEST_DO { |
| |
1044 CX_TEST_CALL_SUBROUTINE(test_http_client_io_chunked_transfer, 10); |
| |
1045 } |
| |
1046 } |
| |
1047 |
| |
1048 /* |
| |
1049 static CX_TEST(test_http_client_io_chunked_transfer_8b) { |
| |
1050 CX_TEST_DO { |
| |
1051 CX_TEST_CALL_SUBROUTINE(test_http_client_io_chunked_transfer, 16); |
| |
1052 } |
| |
1053 } |
| |
1054 |
| |
1055 static CX_TEST(test_http_client_io_chunked_transfer_64b) { |
| |
1056 CX_TEST_DO { |
| |
1057 CX_TEST_CALL_SUBROUTINE(test_http_client_io_chunked_transfer, 64); |
| |
1058 } |
| |
1059 } |
| |
1060 */ |
| 999 |
1061 |
| 1000 void http_client_add_tests(CxTestSuite *suite) { |
1062 void http_client_add_tests(CxTestSuite *suite) { |
| 1001 cx_test_register(suite, test_http_client_send_request); |
1063 cx_test_register(suite, test_http_client_send_request); |
| 1002 cx_test_register(suite, test_http_client_send_request_body_chunked); |
1064 cx_test_register(suite, test_http_client_send_request_body_chunked); |
| 1003 cx_test_register(suite, test_http_client_read_response_head); |
1065 cx_test_register(suite, test_http_client_read_response_head); |
| 1004 cx_test_register(suite, test_http_client_read_response_ctlen); |
1066 cx_test_register(suite, test_http_client_read_response_ctlen); |
| 1005 cx_test_register(suite, test_http_client_read_response_ctlen_big); |
1067 cx_test_register(suite, test_http_client_read_response_ctlen_big); |
| 1006 cx_test_register(suite, test_http_client_io_simple); |
1068 cx_test_register(suite, test_http_client_io_simple_1b); |
| 1007 } |
1069 cx_test_register(suite, test_http_client_io_simple_2b); |
| |
1070 cx_test_register(suite, test_http_client_io_simple_3b); |
| |
1071 cx_test_register(suite, test_http_client_io_simple_16b); |
| |
1072 cx_test_register(suite, test_http_client_io_simple_512b); |
| |
1073 cx_test_register(suite, test_http_client_io_chunked_transfer_1b); |
| |
1074 } |