Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/websocket-factory.hpp" |
| 27 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 28 | #include "factory-test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 29 | #include "tests/limited-io.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace tests { |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(Face) |
| 35 | BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, BaseFixture) |
| 36 | |
| 37 | using nfd::Face; |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 40 | { |
| 41 | WebSocketFactory factory; |
| 42 | BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); |
| 43 | |
| 44 | std::vector<shared_ptr<const Channel>> expectedChannels; |
| 45 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); |
| 46 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); |
| 47 | expectedChannels.push_back(factory.createChannel("::1", "20071")); |
| 48 | |
| 49 | for (const auto& i : factory.getChannels()) { |
| 50 | auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i); |
| 51 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 52 | expectedChannels.erase(pos); |
| 53 | } |
| 54 | |
| 55 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
| 59 | { |
| 60 | WebSocketFactory factory; |
| 61 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 62 | createFace(factory, |
| 63 | FaceUri("ws://127.0.0.1:20070"), |
| 64 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame^] | 65 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 66 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 67 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 68 | createFace(factory, |
| 69 | FaceUri("ws://127.0.0.1:20070"), |
| 70 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame^] | 71 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 72 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 73 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 74 | createFace(factory, |
| 75 | FaceUri("ws://127.0.0.1:20070"), |
| 76 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame^] | 77 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 78 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_SUITE_END() // TestWebSocketFactory |
| 82 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 83 | |
| 84 | } // namespace tests |
| 85 | } // namespace nfd |