blob: 35cb8cc54dc016f582d413d0127f430cdd825254 [file] [log] [blame]
Davide Pesavento409cc202015-09-19 14:13:16 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Weiwei Liucfaa1ad2016-08-28 16:30:56 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Davide Pesavento409cc202015-09-19 14:13:16 +02004 *
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 "util/backports.hpp"
23
24#include "boost-test.hpp"
25
26namespace ndn {
27namespace tests {
28
29BOOST_AUTO_TEST_SUITE(Util)
30BOOST_AUTO_TEST_SUITE(TestBackports)
31
32BOOST_AUTO_TEST_CASE(MakeUnique)
33{
34 std::unique_ptr<int> v0 = make_unique<int>();
35 std::unique_ptr<int> v1 = make_unique<int>(1728);
36 BOOST_CHECK_EQUAL(*v0, 0);
37 BOOST_CHECK_EQUAL(*v1, 1728);
38
39 auto str = make_unique<std::string>("meow");
40 BOOST_CHECK_EQUAL(*str, "meow");
41
42 class Movable
43 {
44 public:
45 Movable()
46 : value(42)
47 {
48 }
49
50 Movable(const Movable&) = delete;
51 Movable(Movable&&) = default;
52
53 public:
54 int value;
55 };
56
57 class Container
58 {
59 public:
60 explicit
61 Container(Movable m)
62 : m(std::move(m))
63 {
64 }
65
66 public:
67 Movable m;
68 };
69
70 Movable m;
71 auto ptr = make_unique<Container>(std::move(m));
72 BOOST_CHECK_EQUAL(ptr->m.value, 42);
73}
74
Weiwei Liucfaa1ad2016-08-28 16:30:56 -070075BOOST_AUTO_TEST_CASE(Clamp)
76{
77 int x = clamp(5, 1, 10);
78 BOOST_CHECK_EQUAL(x, 5);
79
80 x = clamp(-5, 1, 10);
81 BOOST_CHECK_EQUAL(x, 1);
82
83 x = clamp(15, 1, 10);
84 BOOST_CHECK_EQUAL(x, 10);
85
86 x = clamp(5, 10, 1, std::greater<int>());
87 BOOST_CHECK_EQUAL(x, 5);
88
89 x = clamp(-5, 10, 1, std::greater<int>());
90 BOOST_CHECK_EQUAL(x, 1);
91
92 x = clamp(15, 10, 1, std::greater<int>());
93 BOOST_CHECK_EQUAL(x, 10);
94}
95
Davide Pesavento409cc202015-09-19 14:13:16 +020096BOOST_AUTO_TEST_SUITE_END()
97BOOST_AUTO_TEST_SUITE_END()
98
99} // namespace tests
100} // namespace ndn