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