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 {
32 virtual void Read(size_t num, void * bytes)
34 for (unsigned i = 0; i < num; ++i) {
35 ((unsigned char*)bytes)[i] = data[i + readPosition];
39 virtual void Write(size_t num, const void * bytes)
41 for (unsigned i = 0; i < num; ++i) {
42 data.push_back(((unsigned char*)bytes)[i]);
49 virtual ~BinaryStream(){};
52 std::vector<unsigned char> data;
53 unsigned readPosition;
56 static int return_func(int a, bool b)
65 static int called = 0;
67 static void void_func(int a)
72 static struct VoidDelegate
74 void operator()(int a)
80 static struct ReturnDelegate
88 RUNNER_TEST(Caller_function_void)
92 DPL::Serialization::Serialize(stream,a);
94 DPL::Caller::Call(stream,void_func);
95 RUNNER_ASSERT(called == a);
98 RUNNER_TEST(Caller_function_return)
103 DPL::Serialization::Serialize(stream,a);
104 DPL::Serialization::Serialize(stream,b);
105 int result = DPL::Caller::Call(stream,return_func);
106 RUNNER_ASSERT(result == a);
109 RUNNER_TEST(Caller_delegate_void)
114 DPL::Serialization::Serialize(stream,a);
115 DPL::Caller::CallDelegate(stream,voidDelegate);
116 RUNNER_ASSERT(called == a);
119 RUNNER_TEST(Caller_delegate_return)
124 DPL::Serialization::Serialize(stream,a);
126 DPL::Caller::CallDelegate(stream,returnDelegate,result);
127 RUNNER_ASSERT(result == a);