• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2015 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 #include "buffer_test.h"
26 
27 #include <cstring>
28 #include <iostream>
29 #include <tuple>
30 
31 #include "munitxx.h"
32 
33 #include <nghttp2/nghttp2.h>
34 
35 #include "buffer.h"
36 
37 namespace nghttp2 {
38 
39 namespace {
40 const MunitTest tests[]{
41     munit_void_test(test_buffer_write),
42     munit_test_end(),
43 };
44 } // namespace
45 
46 const MunitSuite buffer_suite{
47     "/buffer", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE,
48 };
49 
test_buffer_write(void)50 void test_buffer_write(void) {
51   Buffer<16> b;
52   assert_size(0, ==, b.rleft());
53   assert_size(16, ==, b.wleft());
54 
55   b.write("012", 3);
56 
57   assert_size(3, ==, b.rleft());
58   assert_size(13, ==, b.wleft());
59   assert_ptr_equal(b.pos, std::begin(b.buf));
60 
61   b.drain(3);
62 
63   assert_size(0, ==, b.rleft());
64   assert_size(13, ==, b.wleft());
65   assert_ptrdiff(3, ==, b.pos - std::begin(b.buf));
66 
67   auto n = b.write("0123456789ABCDEF", 16);
68 
69   assert_ssize(13, ==, n);
70 
71   assert_size(13, ==, b.rleft());
72   assert_size(0, ==, b.wleft());
73   assert_ptrdiff(3, ==, b.pos - std::begin(b.buf));
74   assert_memory_equal(13, b.pos, "0123456789ABC");
75 
76   b.reset();
77 
78   assert_size(0, ==, b.rleft());
79   assert_size(16, ==, b.wleft());
80   assert_ptr_equal(b.pos, std::begin(b.buf));
81 
82   b.write(5);
83 
84   assert_size(5, ==, b.rleft());
85   assert_size(11, ==, b.wleft());
86   assert_ptr_equal(b.pos, std::begin(b.buf));
87 }
88 
89 } // namespace nghttp2
90