Junxiao Shi | 02b5125 | 2016-09-04 04:30:31 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "encoding/buffer-stream.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace tests { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(Encoding) |
| 30 | BOOST_AUTO_TEST_SUITE(TestBufferStream) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(Empty) |
| 33 | { |
| 34 | OBufferStream os; |
| 35 | |
| 36 | shared_ptr<Buffer> buf = os.buf(); |
| 37 | BOOST_CHECK_EQUAL(buf->size(), 0); |
| 38 | } |
| 39 | |
| 40 | BOOST_AUTO_TEST_CASE(Put) |
| 41 | { |
| 42 | OBufferStream os; |
| 43 | os.put(0x33); |
| 44 | os.put(0x44); |
| 45 | |
| 46 | shared_ptr<Buffer> buf = os.buf(); |
| 47 | BOOST_REQUIRE_EQUAL(buf->size(), 2); |
| 48 | BOOST_CHECK_EQUAL(buf->at(0), 0x33); |
| 49 | BOOST_CHECK_EQUAL(buf->at(1), 0x44); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(Write) |
| 53 | { |
| 54 | OBufferStream os; |
| 55 | os.write("\x11\x22", 2); |
| 56 | |
| 57 | shared_ptr<Buffer> buf = os.buf(); |
| 58 | BOOST_REQUIRE_EQUAL(buf->size(), 2); |
| 59 | BOOST_CHECK_EQUAL(buf->at(0), 0x11); |
| 60 | BOOST_CHECK_EQUAL(buf->at(1), 0x22); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(Destructor) // Bug 3727 |
| 64 | { |
| 65 | auto os = make_unique<OBufferStream>(); |
| 66 | *os << 'x'; |
| 67 | os.reset(); // should not cause use-after-free |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 68 | |
| 69 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 70 | BOOST_CHECK(true); |
Junxiao Shi | 02b5125 | 2016-09-04 04:30:31 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_SUITE_END() // TestBufferStream |
| 74 | BOOST_AUTO_TEST_SUITE_END() // Encoding |
| 75 | |
| 76 | } // namespace tests |
| 77 | } // namespace ndn |