tests: fix blocking semantic in DBusProxyTest
[profile/ivi/common-api-dbus-runtime.git] / src / test / DBusSerializableStructTest.cpp
1 /* Copyright (C) 2013 BMW Group
2  * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
3  * Author: Juergen Gehring (juergen.gehring@bmw.de)
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <iostream>
8
9 #include <common-api-dbus/dbus-message.h>
10
11 #include "TestDBusSerializableStruct.h"
12
13
14 #define COMMON_API_TEST_TEST_STRUCT_SIGNATURE                                   "(ud)"
15 #define COMMON_API_TEST_TEST_STRUCT_ARRAY_SIGNATURE                             "a" COMMON_API_TEST_TEST_STRUCT_SIGNATURE
16
17 #define COMMON_API_TEST_TEST_STRUCT_EXTENDED_SIGNATURE                  "(uds)"
18 #define COMMON_API_TEST_TEST_STRUCT_EXTENDED_ARRAY_SIGNATURE    "a" COMMON_API_TEST_TEST_STRUCT_EXTENDED_SIGNATURE
19
20
21 namespace common {
22 namespace api {
23 namespace test {
24
25
26 TestStruct::TestStruct(const uint32_t& fromIntValue, const double& fromDoubleValue):
27                 intValue(fromIntValue),
28                 doubleValue(fromDoubleValue) {
29 }
30
31 common::api::dbus::DBusInputMessageStream& TestStruct::readFromDBusInputMessageStream(
32                 common::api::dbus::DBusInputMessageStream& inputMessageStream) {
33         return inputMessageStream >> intValue
34                                                           >> doubleValue;
35 }
36
37 common::api::dbus::DBusOutputMessageStream& TestStruct::writeToDBusOutputMessageStream(
38                 common::api::dbus::DBusOutputMessageStream& outputMessageStream) const {
39         return outputMessageStream << intValue
40                                                            << doubleValue;
41 }
42
43
44 TestStructExtended::TestStructExtended(const uint32_t& fromIntValue, const double& fromDoubleValue, const std::string& fromStringValue):
45                 TestStruct(fromIntValue, fromDoubleValue),
46                 stringValue(fromStringValue) {
47 }
48
49 common::api::dbus::DBusInputMessageStream& TestStructExtended::readFromDBusInputMessageStream(
50                 common::api::dbus::DBusInputMessageStream& inputMessageStream) {
51   return TestStruct::readFromDBusInputMessageStream(inputMessageStream) >> stringValue;
52 }
53
54 common::api::dbus::DBusOutputMessageStream& TestStructExtended::writeToDBusOutputMessageStream(
55                 common::api::dbus::DBusOutputMessageStream& outputMessageStream) const {
56   return TestStruct::writeToDBusOutputMessageStream(outputMessageStream) << stringValue;
57 }
58
59 } //namespace test
60 } //namespace api
61 } //namespace common
62
63
64 int main(void) {
65         using namespace common::api::test;
66
67         TestStructExtended testStructExtended(123, 456.789, "TestStructExtended");
68
69         common::api::dbus::DBusMessage message = common::api::dbus::DBusMessage::createMethodCall(
70                         "com.bmw.test.TestStruct",
71                         "/com/bmw/test/TestStruct",
72                         "com.bmw.test.TestStruct",
73                         "SingleTestStruct",
74                         COMMON_API_TEST_TEST_STRUCT_EXTENDED_SIGNATURE);
75
76         common::api::dbus::DBusOutputMessageStream outStream(message);
77         outStream << testStructExtended;
78         outStream.flush();
79 }