tizen 2.4 release
[external/nghttp2.git] / tests / nghttp2_test_helper.h
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 Tatsuhiro Tsujikawa
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef NGHTTP2_TEST_HELPER_H
26 #define NGHTTP2_TEST_HELPER_H
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif /* HAVE_CONFIG_H */
31
32 #include "nghttp2_frame.h"
33 #include "nghttp2_hd.h"
34 #include "nghttp2_session.h"
35
36 #define MAKE_NV(NAME, VALUE)                                                   \
37   {                                                                            \
38     (uint8_t *) NAME, (uint8_t *)VALUE, strlen(NAME), strlen(VALUE),           \
39         NGHTTP2_NV_FLAG_NONE                                                   \
40   }
41 #define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0]))
42
43 #define assert_nv_equal(A, B, len)                                             \
44   do {                                                                         \
45     size_t alloclen = sizeof(nghttp2_nv) * len;                                \
46     nghttp2_nv *sa = A, *sb = B;                                               \
47     nghttp2_nv *a = malloc(alloclen);                                          \
48     nghttp2_nv *b = malloc(alloclen);                                          \
49     ssize_t i_;                                                                \
50     memcpy(a, sa, alloclen);                                                   \
51     memcpy(b, sb, alloclen);                                                   \
52     nghttp2_nv_array_sort(a, len);                                             \
53     nghttp2_nv_array_sort(b, len);                                             \
54     for (i_ = 0; i_ < (ssize_t)len; ++i_) {                                    \
55       CU_ASSERT(nghttp2_nv_equal(&a[i_], &b[i_]));                             \
56     }                                                                          \
57     free(b);                                                                   \
58     free(a);                                                                   \
59   } while (0);
60
61 int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs);
62
63 int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len);
64
65 int strmemeq(const char *a, const uint8_t *b, size_t bn);
66
67 int nvnameeq(const char *a, nghttp2_nv *nv);
68
69 int nvvalueeq(const char *a, nghttp2_nv *nv);
70
71 typedef struct {
72   nghttp2_nv nva[256];
73   size_t nvlen;
74 } nva_out;
75
76 void nva_out_init(nva_out *out);
77 void nva_out_reset(nva_out *out);
78
79 void add_out(nva_out *out, nghttp2_nv *nv);
80
81 ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
82                    nghttp2_bufs *bufs, size_t offset);
83
84 int frame_pack_bufs_init(nghttp2_bufs *bufs);
85
86 void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size);
87
88 nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id);
89
90 nghttp2_stream *open_stream_with_dep(nghttp2_session *session,
91                                      int32_t stream_id,
92                                      nghttp2_stream *dep_stream);
93
94 nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session,
95                                             int32_t stream_id, int32_t weight,
96                                             nghttp2_stream *dep_stream);
97
98 nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session,
99                                           int32_t stream_id,
100                                           nghttp2_stream *dep_stream);
101
102 nghttp2_outbound_item *create_data_ob_item(void);
103
104 #endif /* NGHTTP2_TEST_HELPER_H */