Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_type_traits_queries01.cpp
Go to the documentation of this file.
1/*
2 * Multiple Authors: firda (post @ stackoverflow),
3 * Sven Gothel <sgothel@jausoft.com>
4 *
5 * Editor: Sven Gothel <sgothel@jausoft.com>
6 * Copyright (c) 2021 Gothel Software e.K.
7 * Copyright (c) 2021 The Authors (see above)
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28#include <cassert>
29#include <cinttypes>
30#include <cstring>
31#include <iostream>
32
34
36
37using namespace jau;
38
39struct One {
40 typedef int type;
41 static constexpr bool v = true;
43 One(type x_ = 0): x(x_) {}
44 ~One() = default;
45 type get() { return x; }
46 type add(type x_, type y_) { return x_+y_; }
47};
48struct Two: One {};
49struct Not {};
50
51#if 0
52TYPEDEF_CHECKER(has_type, type);
53TYPEDEF_CHECKER_ANY(any_type, type);
54TYPEDEF_CHECKER_STRICT(exact_type, type);
55MVALUE_CHECKER(true_v, v, true);
56MVALUE_CHECKER(true_z, z, true);
57MVALUE_CHECKER(false_v, v, false);
58MVALUE_CHECKER(one_v, v, 1);
59MVALUE_CHECKER_STRICT(exact_v, v, 1);
60#endif
61
62MTYPE_CHECKER(has_x, x);
65
66METHOD_CHECKER(has_get, get, long, ());
67METHOD_CHECKER(has_add, add, long, (1,2))
68METHOD_CHECKER_ANY(any_get, get, ());
69METHOD_CHECKER_STRICT_RET(int_get, get, int, ())
70METHOD_CHECKER_STRICT_RET(long_get, get, long, ())
71
72TEST_CASE( "01 Type Traits Queries") {
73 #define CHECK_2(name, desc, ...) std::cout << std::endl; \
74 std::cout << "One " << (name<One, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
75 std::cout << "Two " << (name<Two, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
76 std::cout << "Not " << (name<Not, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
77 std::cout << "int " << (name<int, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl
78
79 std::string sep = std::string(60, '-');
80#if 0
81 std::cout << sep;
82 CHECK_2(any_type, "typedef type");
83 CHECK_2(has_type, "typedef type convertible to long", long);
84 CHECK_2(exact_type, "typedef type = int", int);
85 CHECK_2(exact_type, "typedef type = long", long);
86
87 std::cout << sep;
88 CHECK_2(true_v, "var v with value equal to true");
89 CHECK_2(true_z, "var z with value equal to true");
90 CHECK_2(false_v, "var v with value equal to false");
91 CHECK_2(one_v, "var v with value equal to 1");
92 CHECK_2(exact_v, "var v with value equal to 1 of type int");
93#endif
94
95 std::cout << sep;
96 CHECK_2(any_x, "var x");
97 CHECK_2(has_x, "var x of type convertible to long", long);
98 CHECK_2(exact_x, "var x of type int", int);
99 CHECK_2(exact_x, "var x of type long", long);
100
101 std::cout << sep;
102 CHECK_2(has_get, "get()");
103 CHECK_2(has_get, "get() with return type covertible to long");
104 CHECK_2(has_add, "add() accepting two ints and returning ~ long");
105 CHECK_2(int_get, "int get()");
106 CHECK_2(long_get, "long get()");
107}
#define METHOD_CHECKER_STRICT_RET(name, fn, ret, args)
Checker for member function with exact retutn type and accepting given arguments.
Entry * get(const EUI48 &addr, const std::string &name, AddressNameEntryMatchFunc m) noexcept
Returns a matching BTSecurityRegistry::Entry with the given addr and/or name.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
~One()=default
static constexpr bool v
type add(type x_, type y_)
#define CHECK_2(name, desc,...)
MTYPE_CHECKER_ANY(any_x, x)
TEST_CASE("01 Type Traits Queries")
METHOD_CHECKER_ANY(any_get, get,())
MTYPE_CHECKER_STRICT(exact_x, x)
METHOD_CHECKER(has_get, get, long,())
MTYPE_CHECKER(has_x, x)