spirosmastorakis | 0e2b197 | 2016-03-27 20:54:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of the nTorrent codebase. |
| 6 | * |
| 7 | * nTorrent 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 | * nTorrent 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 nTorrent, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS for complete list of nTorrent authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "boost-test.hpp" |
| 23 | #include "stats-table-record.hpp" |
| 24 | |
| 25 | #include <ndn-cxx/name.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ntorrent { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestStatsTableRecord) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(TestCoreAPI) |
| 34 | { |
| 35 | StatsTableRecord record(Name("isp1")); |
| 36 | |
| 37 | BOOST_CHECK_EQUAL(record.getRecordName().toUri(), "/isp1"); |
| 38 | BOOST_CHECK_EQUAL(record.getRecordSentInterests(), 0); |
| 39 | BOOST_CHECK_EQUAL(record.getRecordReceivedData(), 0); |
| 40 | BOOST_CHECK_EQUAL(record.getRecordSuccessRate(), 0); |
| 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_CASE(TestIncrement) |
| 44 | { |
| 45 | StatsTableRecord record(Name("isp1")); |
| 46 | record.incrementSentInterests(); |
| 47 | |
| 48 | BOOST_CHECK_EQUAL(record.getRecordName().toUri(), "/isp1"); |
| 49 | BOOST_CHECK_EQUAL(record.getRecordSentInterests(), 1); |
| 50 | BOOST_CHECK_EQUAL(record.getRecordReceivedData(), 0); |
| 51 | BOOST_CHECK_EQUAL(record.getRecordSuccessRate(), 0); |
| 52 | |
| 53 | record.incrementReceivedData(); |
| 54 | |
| 55 | BOOST_CHECK_EQUAL(record.getRecordName().toUri(), "/isp1"); |
| 56 | BOOST_CHECK_EQUAL(record.getRecordSentInterests(), 1); |
| 57 | BOOST_CHECK_EQUAL(record.getRecordReceivedData(), 1); |
| 58 | BOOST_CHECK_EQUAL(record.getRecordSuccessRate(), 1); |
| 59 | } |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE(TestIncrementThrow) |
| 62 | { |
| 63 | StatsTableRecord record(Name("isp1")); |
| 64 | BOOST_REQUIRE_THROW(record.incrementReceivedData(), StatsTableRecord::Error); |
| 65 | |
| 66 | BOOST_CHECK_EQUAL(record.getRecordName().toUri(), "/isp1"); |
| 67 | BOOST_CHECK_EQUAL(record.getRecordSentInterests(), 0); |
| 68 | BOOST_CHECK_EQUAL(record.getRecordReceivedData(), 0); |
| 69 | BOOST_CHECK_EQUAL(record.getRecordSuccessRate(), 0); |
| 70 | } |
| 71 | |
| 72 | BOOST_AUTO_TEST_CASE(TestEqualityOperator) |
| 73 | { |
| 74 | StatsTableRecord record1(Name("isp1")); |
| 75 | record1.incrementSentInterests(); |
| 76 | record1.incrementReceivedData(); |
| 77 | |
| 78 | StatsTableRecord record2(Name("isp1")); |
| 79 | record2.incrementSentInterests(); |
| 80 | record2.incrementReceivedData(); |
| 81 | |
| 82 | BOOST_CHECK(record1 == record2); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE(TestInequalityOperator) |
| 86 | { |
| 87 | StatsTableRecord record1(Name("isp2")); |
| 88 | record1.incrementSentInterests(); |
| 89 | record1.incrementReceivedData(); |
| 90 | |
| 91 | StatsTableRecord record2(Name("isp1")); |
| 92 | record2.incrementSentInterests(); |
| 93 | record2.incrementReceivedData(); |
| 94 | |
| 95 | BOOST_CHECK(record1 != record2); |
| 96 | |
| 97 | StatsTableRecord record3(Name("isp1")); |
| 98 | record3.incrementSentInterests(); |
| 99 | |
| 100 | BOOST_CHECK(record2 != record3); |
| 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_CASE(TestCopyConstructor) |
| 104 | { |
| 105 | StatsTableRecord record1(Name("isp2")); |
| 106 | record1.incrementSentInterests(); |
| 107 | record1.incrementReceivedData(); |
| 108 | |
| 109 | StatsTableRecord record2(record1); |
| 110 | |
| 111 | BOOST_CHECK(record1 == record2); |
| 112 | |
| 113 | record2.incrementSentInterests(); |
| 114 | |
| 115 | BOOST_CHECK(record1 != record2); |
| 116 | |
| 117 | record1.incrementSentInterests(); |
| 118 | |
| 119 | BOOST_CHECK(record1 == record2); |
| 120 | } |
| 121 | |
| 122 | BOOST_AUTO_TEST_SUITE_END() |
| 123 | |
| 124 | } // namespace tests |
| 125 | } // namespace ntorrent |
| 126 | } // namespace ndn |