1
/******************************************************************************
2
* Copyright © 2012-2014 Institut für Nachrichtentechnik, Universität Rostock *
3
* Copyright © 2006-2012 Quality & Usability Lab, *
4
* Telekom Innovation Laboratories, TU Berlin *
6
* This file is part of the Audio Processing Framework (APF). *
8
* The APF is free software: you can redistribute it and/or modify it under *
9
* the terms of the GNU General Public License as published by the Free *
10
* Software Foundation, either version 3 of the License, or (at your option) *
11
* any later version. *
13
* The APF is distributed in the hope that it will be useful, but WITHOUT ANY *
14
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
15
* FOR A PARTICULAR PURPOSE. *
16
* See the GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License along *
19
* with this program. If not, see <http://www.gnu.org/licenses/>. *
21
* http://AudioProcessingFramework.github.com *
22
******************************************************************************/
29
#include "catch/catch.hpp"
31
template<typename Derived>
32
struct B : apf::CRTP<Derived>
34
int value() { return this->derived().i; }
45
CHECK(d.value() == 42);
48
TEST_CASE("BlockParameter", "")
51
SECTION("default ctor", "")
53
auto bp = apf::BlockParameter<int>();
60
auto bp = apf::BlockParameter<int>(111);
61
CHECK(111 == bp.get());
62
CHECK(111 == bp.old());
63
CHECK(111 == bp.both());
64
CHECK(bp.both() == 111);
65
CHECK_FALSE(bp.changed());
67
// TODO: once Catch supports checking for asserts, enable this:
68
//assert(bp.exactly_one_assignment());
71
CHECK(222 == bp.get());
72
CHECK(111 == bp.old());
75
CHECK_FALSE(111 == bp.both());
76
CHECK_FALSE(bp.both() == 111);
77
CHECK(bp.both() != 0);
78
CHECK(0 != bp.both());
80
CHECK(bp.both() >= 0);
81
CHECK_FALSE(0 > bp.both());
82
CHECK_FALSE(0 >= bp.both());
83
CHECK_FALSE(bp.both() > 333);
84
CHECK_FALSE(bp.both() >= 333);
85
CHECK(333 > bp.both());
86
CHECK(333 >= bp.both());
87
CHECK(bp.both() < 333);
88
CHECK(bp.both() <= 333);
89
CHECK_FALSE(333 < bp.both());
90
CHECK_FALSE(333 <= bp.both());
91
CHECK_FALSE(bp.both() < 0);
92
CHECK_FALSE(bp.both() <= 0);
94
CHECK(0 <= bp.both());
96
assert(bp.exactly_one_assignment());
99
CHECK(333 == bp.get());
100
CHECK(222 == bp.old());
104
CHECK_FALSE(bp.changed());
107
CHECK(222 == bp.old());
108
CHECK(223 == bp.get());
110
assert(bp.exactly_one_assignment());
113
SECTION("conversion operator", "")
115
auto bp = apf::BlockParameter<int>(42);
120
CHECK((i - bp) == 0);
123
SECTION("conversion operator from const object", "")
125
const auto bp = apf::BlockParameter<int>(42);
130
CHECK((i - bp) == 0);
135
NonCopyable(int) {}; // hypothetical constructor
136
NonCopyable(const NonCopyable&) = delete;
137
NonCopyable(NonCopyable&&) = default;
138
NonCopyable& operator=(NonCopyable&& other) = default;
141
SECTION("non-copyable T", "")
143
// These are just compile-time checks:
145
auto bp = apf::BlockParameter<NonCopyable>{42};
146
bp = NonCopyable(43);
149
// TODO: move CountCtors in a separate file?
153
CountCtors() { ++ default_constructor; }
154
CountCtors(const CountCtors&) { ++ copy_constructor; }
155
CountCtors(CountCtors&&) { ++move_constructor; }
157
CountCtors& operator=(const CountCtors&) { ++copy_assignment; return *this; };
158
CountCtors& operator=(CountCtors&&) { ++move_assignment; return *this; };
160
int default_constructor = 0;
161
int copy_constructor = 0;
162
int move_constructor = 0;
164
int copy_assignment = 0;
165
int move_assignment = 0;
168
SECTION("check if move ctor and move assignment is used", "")
170
auto bp = apf::BlockParameter<CountCtors>{CountCtors()};
171
CHECK(bp.get().copy_constructor == 1);
172
CHECK(bp.old().move_constructor == 1);
176
CHECK(bp.get().move_assignment == 1);
177
CHECK(bp.get().copy_assignment == 0);
178
CHECK(bp.old().move_assignment == 1);
179
CHECK(bp.old().copy_assignment == 0);
184
// Settings for Vim (http://www.vim.org/), please do not remove:
185
// vim:softtabstop=2:shiftwidth=2:expandtab:textwidth=80:cindent