xref: /third_party/nghttp2/src/buffer_test.cc (revision 2c593315)
12c593315Sopenharmony_ci/*
22c593315Sopenharmony_ci * nghttp2 - HTTP/2 C Library
32c593315Sopenharmony_ci *
42c593315Sopenharmony_ci * Copyright (c) 2015 Tatsuhiro Tsujikawa
52c593315Sopenharmony_ci *
62c593315Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
72c593315Sopenharmony_ci * a copy of this software and associated documentation files (the
82c593315Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
92c593315Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
102c593315Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
112c593315Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
122c593315Sopenharmony_ci * the following conditions:
132c593315Sopenharmony_ci *
142c593315Sopenharmony_ci * The above copyright notice and this permission notice shall be
152c593315Sopenharmony_ci * included in all copies or substantial portions of the Software.
162c593315Sopenharmony_ci *
172c593315Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
182c593315Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
192c593315Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
202c593315Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
212c593315Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
222c593315Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
232c593315Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
242c593315Sopenharmony_ci */
252c593315Sopenharmony_ci#include "buffer_test.h"
262c593315Sopenharmony_ci
272c593315Sopenharmony_ci#include <cstring>
282c593315Sopenharmony_ci#include <iostream>
292c593315Sopenharmony_ci#include <tuple>
302c593315Sopenharmony_ci
312c593315Sopenharmony_ci#include <CUnit/CUnit.h>
322c593315Sopenharmony_ci
332c593315Sopenharmony_ci#include <nghttp2/nghttp2.h>
342c593315Sopenharmony_ci
352c593315Sopenharmony_ci#include "buffer.h"
362c593315Sopenharmony_ci
372c593315Sopenharmony_cinamespace nghttp2 {
382c593315Sopenharmony_ci
392c593315Sopenharmony_civoid test_buffer_write(void) {
402c593315Sopenharmony_ci  Buffer<16> b;
412c593315Sopenharmony_ci  CU_ASSERT(0 == b.rleft());
422c593315Sopenharmony_ci  CU_ASSERT(16 == b.wleft());
432c593315Sopenharmony_ci
442c593315Sopenharmony_ci  b.write("012", 3);
452c593315Sopenharmony_ci
462c593315Sopenharmony_ci  CU_ASSERT(3 == b.rleft());
472c593315Sopenharmony_ci  CU_ASSERT(13 == b.wleft());
482c593315Sopenharmony_ci  CU_ASSERT(b.pos == std::begin(b.buf));
492c593315Sopenharmony_ci
502c593315Sopenharmony_ci  b.drain(3);
512c593315Sopenharmony_ci
522c593315Sopenharmony_ci  CU_ASSERT(0 == b.rleft());
532c593315Sopenharmony_ci  CU_ASSERT(13 == b.wleft());
542c593315Sopenharmony_ci  CU_ASSERT(3 == b.pos - std::begin(b.buf));
552c593315Sopenharmony_ci
562c593315Sopenharmony_ci  auto n = b.write("0123456789ABCDEF", 16);
572c593315Sopenharmony_ci
582c593315Sopenharmony_ci  CU_ASSERT(n == 13);
592c593315Sopenharmony_ci
602c593315Sopenharmony_ci  CU_ASSERT(13 == b.rleft());
612c593315Sopenharmony_ci  CU_ASSERT(0 == b.wleft());
622c593315Sopenharmony_ci  CU_ASSERT(3 == b.pos - std::begin(b.buf));
632c593315Sopenharmony_ci  CU_ASSERT(0 == memcmp(b.pos, "0123456789ABC", 13));
642c593315Sopenharmony_ci
652c593315Sopenharmony_ci  b.reset();
662c593315Sopenharmony_ci
672c593315Sopenharmony_ci  CU_ASSERT(0 == b.rleft());
682c593315Sopenharmony_ci  CU_ASSERT(16 == b.wleft());
692c593315Sopenharmony_ci  CU_ASSERT(b.pos == std::begin(b.buf));
702c593315Sopenharmony_ci
712c593315Sopenharmony_ci  b.write(5);
722c593315Sopenharmony_ci
732c593315Sopenharmony_ci  CU_ASSERT(5 == b.rleft());
742c593315Sopenharmony_ci  CU_ASSERT(11 == b.wleft());
752c593315Sopenharmony_ci  CU_ASSERT(b.pos == std::begin(b.buf));
762c593315Sopenharmony_ci}
772c593315Sopenharmony_ci
782c593315Sopenharmony_ci} // namespace nghttp2
79