39 #include "testutils.h" |
39 #include "testutils.h" |
40 |
40 |
41 Session* testutil_session(void) { |
41 Session* testutil_session(void) { |
42 pool_handle_t *pool = pool_create(); |
42 pool_handle_t *pool = pool_create(); |
43 NSAPISession *sn = nsapisession_create(pool); |
43 NSAPISession *sn = nsapisession_create(pool); |
|
44 sn->connection = testutil_dummy_connection(pool); |
44 |
45 |
45 return &sn->sn; |
46 return &sn->sn; |
46 } |
47 } |
47 |
48 |
48 Request* testutil_request(pool_handle_t *pool, const char *method, const char *uri) { |
49 Request* testutil_request(pool_handle_t *pool, const char *method, const char *uri) { |
71 rq->rq.reqpb); |
72 rq->rq.reqpb); |
72 |
73 |
73 pblock_nvinsert("uri", uri, rq->rq.reqpb); |
74 pblock_nvinsert("uri", uri, rq->rq.reqpb); |
74 |
75 |
75 return &rq->rq; |
76 return &rq->rq; |
|
77 } |
|
78 |
|
79 static int dummyconn_read(Connection *conn, void *buf, int len) { |
|
80 return len; |
|
81 } |
|
82 |
|
83 static int dummyconn_write(Connection *conn, const void *buf, int len) { |
|
84 return len; |
|
85 } |
|
86 |
|
87 static void dummyconn_close(Connection *conn) { |
|
88 |
|
89 } |
|
90 |
|
91 |
|
92 Connection* testutil_dummy_connection(pool_handle_t *pool) { |
|
93 Connection *conn = pool_malloc(pool, sizeof(Connection)); |
|
94 ZERO(conn, sizeof(Connection)); |
|
95 conn->read = dummyconn_read; |
|
96 conn->write = dummyconn_write; |
|
97 conn->close = dummyconn_close; |
|
98 return conn; |
76 } |
99 } |
77 |
100 |
78 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) { |
101 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) { |
79 sstr_t cl = ucx_sprintf("%d", (int)len); |
102 sstr_t cl = ucx_sprintf("%d", (int)len); |
80 pblock_nvreplace("content-length", cl.ptr, rq->headers); |
103 pblock_nvreplace("content-length", cl.ptr, rq->headers); |