2 * Copyright (c) 2011 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.
17 * @file test_address.cpp
18 * @author Tomasz Swierczek (t.swierczek@samsung.com)
20 * @brief This file is the implementation file of caller tests
23 #include <dpl/test_runner.h>
24 #include <dpl/serialization.h>
25 #include <dpl/caller.h>
27 RUNNER_TEST_GROUP_INIT(DPL)
30 class BinaryStream : public DPL::IStream
33 virtual void Read(size_t num, void * bytes)
35 for (unsigned i = 0; i < num; ++i) {
36 ((unsigned char*)bytes)[i] = data[i + readPosition];
40 virtual void Write(size_t num, const void * bytes)
42 for (unsigned i = 0; i < num; ++i) {
43 data.push_back(((unsigned char*)bytes)[i]);
50 virtual ~BinaryStream(){}
53 std::vector<unsigned char> data;
54 unsigned readPosition;
57 static int return_func(int a, bool b)
66 static int called = 0;
68 static void void_func(int a)
73 static struct VoidDelegate
75 void operator()(int a)
81 static struct ReturnDelegate
89 RUNNER_TEST(Caller_function_void)
93 DPL::Serialization::Serialize(stream, a);
95 DPL::Caller::Call(stream, void_func);
96 RUNNER_ASSERT(called == a);
99 RUNNER_TEST(Caller_function_return)
104 DPL::Serialization::Serialize(stream, a);
105 DPL::Serialization::Serialize(stream, b);
106 int result = DPL::Caller::Call(stream, return_func);
107 RUNNER_ASSERT(result == a);
110 RUNNER_TEST(Caller_delegate_void)
115 DPL::Serialization::Serialize(stream, a);
116 DPL::Caller::CallDelegate(stream, voidDelegate);
117 RUNNER_ASSERT(called == a);
120 RUNNER_TEST(Caller_delegate_return)
125 DPL::Serialization::Serialize(stream, a);
127 DPL::Caller::CallDelegate(stream, returnDelegate, result);
128 RUNNER_ASSERT(result == a);