8c0ae36d7cd773cf36cc42bd8e6d77fb50508177
[platform/core/connectivity/net-config.git] / gtest / mptcp.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <iostream>
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include <stdint.h>
23
24 #include "mptcp.h"
25
26 Mptcp::Mptcp()
27 {
28         Create();
29 }
30
31 Mptcp::~Mptcp()
32 {
33         Destroy();
34 }
35
36 error_e Mptcp::MptcpSupported(bool *supported)
37 {
38         GVariant *message = NULL;
39         error_e error = ERROR_NONE;
40
41         message = InvokeMethod(NETCONFIG_SERVICE,
42                 NETCONFIG_MPTCP_PATH,
43                 NETCONFIG_MPTCP_INTERFACE,
44                 MPTCP_SUPPORTED,
45                 NULL,
46                 &error);
47
48         if (message == NULL) {
49                 GLOGD("Failed to invoke dbus method");
50                 return error;
51         }
52
53         g_variant_get(message, "(b)", supported);
54         g_variant_unref(message);
55
56         return ERROR_NONE;
57 }
58
59 error_e Mptcp::MptcpSetEnable(int enabled)
60 {
61         GVariant *message = NULL;
62         error_e error = ERROR_NONE;
63
64         message = InvokeMethod(NETCONFIG_SERVICE,
65                 NETCONFIG_MPTCP_PATH,
66                 NETCONFIG_MPTCP_INTERFACE,
67                 MPTCP_SET_ENABLE,
68                 g_variant_new("(i)", enabled),
69                 &error);
70
71         if (message == NULL) {
72                 GLOGD("Failed to invoke dbus method");
73                 return error;
74         }
75
76         g_variant_unref(message);
77
78         return ERROR_NONE;
79 }
80
81 error_e Mptcp::MptcpGetEnabled(int *enabled)
82 {
83         GVariant *message = NULL;
84         error_e error = ERROR_NONE;
85
86         message = InvokeMethod(NETCONFIG_SERVICE,
87                 NETCONFIG_MPTCP_PATH,
88                 NETCONFIG_MPTCP_INTERFACE,
89                 MPTCP_GET_ENABLED,
90                 NULL,
91                 &error);
92
93         if (message == NULL) {
94                 GLOGD("Failed to invoke dbus method");
95                 return error;
96         }
97
98         g_variant_get(message, "(i)", enabled);
99         g_variant_unref(message);
100
101         return ERROR_NONE;
102 }
103
104 error_e Mptcp::MptcpSetPathManager(const char *path)
105 {
106         GVariant *message = NULL;
107         error_e error = ERROR_NONE;
108
109         message = InvokeMethod(NETCONFIG_SERVICE,
110                 NETCONFIG_MPTCP_PATH,
111                 NETCONFIG_MPTCP_INTERFACE,
112                 MPTCP_SET_PATH_MANAGER,
113                 g_variant_new("(s)", path),
114                 &error);
115
116         if (message == NULL) {
117                 GLOGD("Failed to invoke dbus method");
118                 return error;
119         }
120
121         g_variant_unref(message);
122
123         return ERROR_NONE;
124 }
125
126 error_e Mptcp::MptcpGetPathManager(char *path)
127 {
128         GVariant *message = NULL;
129         error_e error = ERROR_NONE;
130
131         message = InvokeMethod(NETCONFIG_SERVICE,
132                 NETCONFIG_MPTCP_PATH,
133                 NETCONFIG_MPTCP_INTERFACE,
134                 MPTCP_GET_PATH_MANAGER,
135                 NULL,
136                 &error);
137
138         if (message == NULL) {
139                 GLOGD("Failed to invoke dbus method");
140                 return error;
141         }
142
143         g_variant_get(message, "(s)", path);
144         g_variant_unref(message);
145
146         return ERROR_NONE;
147 }
148
149 error_e Mptcp::MptcpSetScheduler(const char *sched)
150 {
151         GVariant *message = NULL;
152         error_e error = ERROR_NONE;
153
154         message = InvokeMethod(NETCONFIG_SERVICE,
155                 NETCONFIG_MPTCP_PATH,
156                 NETCONFIG_MPTCP_INTERFACE,
157                 MPTCP_SET_SCHEDULER,
158                 g_variant_new("(s)", sched),
159                 &error);
160
161         if (message == NULL) {
162                 GLOGD("Failed to invoke dbus method");
163                 return error;
164         }
165
166         g_variant_unref(message);
167
168         return ERROR_NONE;
169 }
170
171 error_e Mptcp::MptcpGetScheduler(char *sched)
172 {
173         GVariant *message = NULL;
174         error_e error = ERROR_NONE;
175
176         message = InvokeMethod(NETCONFIG_SERVICE,
177                 NETCONFIG_MPTCP_PATH,
178                 NETCONFIG_MPTCP_INTERFACE,
179                 MPTCP_GET_SCHEDULER,
180                 NULL,
181                 &error);
182
183         if (message == NULL) {
184                 GLOGD("Failed to invoke dbus method");
185                 return error;
186         }
187
188         g_variant_get(message, "(s)", sched);
189         g_variant_unref(message);
190
191         return ERROR_NONE;
192 }
193