1#include <gtest/gtest.h>
6TEST(callback, objectMethod) {
9 inline int handler(
const int& num1,
const int& num2)
const {
18 cb.
set([&myClass](
const int& num1,
const int& num2) ->
int {
19 return myClass.
handler(num1, num2);
21 ASSERT_EQ(cb(4, 5), 9);
22 ASSERT_NE(cb(4, 5), 8);
26TEST(callback, classStaticMethod) {
29 static inline int staticHandler(
const int& num1,
const int& num2) {
36 cb.
set([](
const int& num1,
const int& num2) ->
int {
39 ASSERT_EQ(cb(4, 5), 9);
40 ASSERT_NE(cb(4, 5), 8);
51 cb.
set([](
const int& num1,
const int& num2) ->
int {
54 ASSERT_EQ(cb(4, 5), 9);
55 ASSERT_NE(cb(4, 5), 8);
62 cb.
set([](
const int& num1,
const int& num2) ->
int {
65 ASSERT_EQ(cb(4, 5), 9);
66 ASSERT_NE(cb(4, 5), 8);
73 cb.
set([](
const int& num1,
const int& num2) ->
bool {
76 ASSERT_TRUE(cb(1, 1));
77 ASSERT_FALSE(cb(1, 2));
81TEST(callback, voidWithoutParameters) {
94TEST(callback, voidWithConstParameter) {
97 cb.
set([](
const std::string& s) {
98 ASSERT_STREQ(s.c_str(),
"test");
107 ASSERT_FALSE(cb.
is_set());
115 ASSERT_FALSE(cb.
is_set());
122 ASSERT_FALSE(cb.
is_set());
128 return_class() : value_(0) {};
134 return_class ret = cb();
135 ASSERT_EQ(ret.value_, 0);
136 cb.
set([]() -> return_class {
142 ASSERT_EQ(ret.value_, 1);
148 cb.
set([]() -> std::string {
151 ASSERT_STREQ(cb().c_str(),
"test");
156 [](
const int& num1,
const int& num2) ->
bool {
159 ASSERT_FALSE(cb(1, 2));
int functionHandler(const int &num1, const int &num2)
TEST(callback, objectMethod)
int handler(const int &num1, const int &num2) const
static int staticHandler(const int &num1, const int &num2)
void set(callbackfunction_t &&callback)