Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2015 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 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 22 | */ |
| 23 | |
| 24 | #include "lp/cache-policy.hpp" |
| 25 | |
| 26 | #include "boost-test.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace lp { |
| 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(LpCachePoicy) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Encode) |
| 35 | { |
| 36 | CachePolicy policy; |
| 37 | policy.setPolicy(CachePolicyType::NO_CACHE); |
| 38 | |
| 39 | Block wire; |
| 40 | BOOST_REQUIRE_NO_THROW(wire = policy.wireEncode()); |
| 41 | |
| 42 | // Sample encoded value obtained with: |
| 43 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 44 | // printf("0x%02x, ", *it); |
| 45 | // } |
| 46 | |
| 47 | // Contains CachePolicyType::NO_CACHE |
| 48 | static const uint8_t expectedBlock[] = { |
| 49 | 0xfd, 0x03, 0x34, 0x05, 0xfd, 0x03, 0x35, 0x01, 0x01 |
| 50 | }; |
| 51 | |
| 52 | BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock), |
| 53 | wire.begin(), wire.end()); |
| 54 | |
| 55 | BOOST_REQUIRE_NO_THROW(policy.wireDecode(wire)); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(DecodeUnknownPolicyError) |
| 59 | { |
| 60 | static const uint8_t expectedBlock[] = { |
| 61 | 0xfd, 0x03, 0x34, 0x08, 0xfd, 0x03, 0x35, 0x04, 0xff, 0xff, 0xff, 0xff |
| 62 | }; |
| 63 | |
| 64 | CachePolicy policy; |
| 65 | Block wire(expectedBlock, sizeof(expectedBlock)); |
| 66 | BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error); |
| 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_CASE(DecodeMissingPolicyError) |
| 70 | { |
| 71 | static const uint8_t inputBlock[] = { |
| 72 | 0xfd, 0x03, 0x34, 0x00 |
| 73 | }; |
| 74 | |
| 75 | CachePolicy policy; |
| 76 | Block wire(inputBlock, sizeof(inputBlock)); |
| 77 | BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error); |
| 78 | } |
| 79 | |
| 80 | BOOST_AUTO_TEST_CASE(DecodeInvalidPolicyError) |
| 81 | { |
| 82 | static const uint8_t inputBlock[] = { |
| 83 | 0xfd, 0x03, 0x34, 0x05, 0xfd, 0x03, 0x35, 0x01, 0x00 |
| 84 | }; |
| 85 | |
| 86 | CachePolicy policy; |
| 87 | Block wire(inputBlock, sizeof(inputBlock)); |
| 88 | BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error); |
| 89 | } |
| 90 | |
| 91 | BOOST_AUTO_TEST_CASE(Policy) |
| 92 | { |
| 93 | CachePolicy policy; |
| 94 | BOOST_CHECK_EQUAL(policy.getPolicy(), CachePolicyType::NONE); |
| 95 | |
| 96 | policy.setPolicy(CachePolicyType::NO_CACHE); |
| 97 | BOOST_CHECK_EQUAL(policy.getPolicy(), CachePolicyType::NO_CACHE); |
| 98 | } |
| 99 | |
| 100 | BOOST_AUTO_TEST_SUITE_END() |
| 101 | |
| 102 | } // namespace tests |
| 103 | } // namespace lp |
| 104 | } // namespace ndn |