2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @brief This file is the implementation file of test bind
24 #include <dpl/test/test_runner.h>
28 const int MAGIC_INT = 42;
29 const double MAGIC_DOUBLE = 42.42;
32 BindTestBase() : called{false} {}
37 struct BindNoArguments : BindTestBase {
38 void foo() { called = true; }
41 struct BindWithArguments : BindTestBase {
42 void foo(int, double) { called = true; }
45 struct BindWithArgumentsAndResult : BindTestBase {
46 int foo(int, double) { called = true; return MAGIC_INT; }
50 RUNNER_TEST_GROUP_INIT(DPL)
53 Name: Bind_NoArguments
54 Description: tests binding method without arguments
55 Expected: bound method called
57 RUNNER_TEST(Bind_NoArguments)
61 std::function<void()> delegate = DPL::Bind(&BindNoArguments::foo, &test);
64 RUNNER_ASSERT(test.called);
68 Name: Bind_WithArguments
69 Description: tests binding method with arguments
70 Expected: bound method called
72 RUNNER_TEST(Bind_WithArguments)
74 BindWithArguments test;
76 std::function<void(int, double)> delegate =
77 DPL::Bind(&BindWithArguments::foo, &test);
78 delegate(MAGIC_INT, MAGIC_DOUBLE);
80 RUNNER_ASSERT(test.called);
84 Name: Bind_WithArgumentsAndResult
85 Description: tests binding method with arguments and result
86 Expected: bound method called
88 RUNNER_TEST(Bind_WithArgumentsAndResult)
90 BindWithArgumentsAndResult test;
92 std::function<int(int, double)> delegate =
93 DPL::Bind(&BindWithArgumentsAndResult::foo, &test);
94 int result = delegate(MAGIC_INT, MAGIC_DOUBLE);
96 RUNNER_ASSERT(test.called);
97 RUNNER_ASSERT(MAGIC_INT == result);