dbus-policy : Simplified complex dbus config. rules.
[platform/core/connectivity/wifi-mesh-manager.git] / haltest / wmeshmgr.cpp
1 /*
2  * Copyright (c) 2018 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 <unistd.h>
23 #include <system_info.h>
24
25 #include "manager.h"
26 #include "wmesh.h"
27
28 using ::testing::InitGoogleTest;
29 using ::testing::Test;
30 using ::testing::TestCase;
31
32 char *mesh_id = (char *)"haltestnetwork";
33 char *feature_name = (char *)"http://tizen.org/feature/network.wifi.mesh";
34
35 bool CheckFeature()
36 {
37         bool mesh_supported = FALSE;
38         if (!system_info_get_platform_bool(feature_name, &mesh_supported)) {
39                 if (FALSE == mesh_supported) {
40                         GLOGD("wifi-mesh feature is disabled");
41                         return ERROR_NOT_SUPPORTED;
42                 }
43                 return ERROR_NONE;
44         } else {
45                 GLOGD("Error - Feature getting from System Info");
46                 return ERROR_INVALID_PARAMETER;
47         }
48 }
49
50 /*
51 @testcase       Enable_p
52 @since_tizen    5.0
53 @author         SRID(abhishek.s94)
54 @reviewer       HQ(saerome.kim)
55 @type           auto
56 @description    Positive, Enable wifi-mesh-manager
57 @apicovered     "enable" dbus method on net.wmesh.manager interface
58 @passcase       when EnableManager() returns ERROR_NONE
59 @failcase       when EnableManager() does not return ERROR_NONE
60 @precondition   None
61 @postcondition  None
62 */
63 TEST(WifiMeshManager, Enable_p)
64 {
65         error_e ret = ERROR_NONE;
66         Manager mgr;
67
68         if (ERROR_NONE == CheckFeature()) {
69                 ret = mgr.EnableManager();
70         }
71         EXPECT_EQ(ERROR_NONE, ret);
72 }
73
74 /*
75 @testcase       StartMesh_p
76 @since_tizen    5.0
77 @author         SRID(abhishek.s94)
78 @reviewer       HQ(saerome.kim)
79 @type           auto
80 @description    Positive, Start wifi-mesh-manager
81 @apicovered     "enable_mesh" dbus method on net.wmesh.manager interface
82 @passcase       when EnableMesh() returns ERROR_NONE
83 @failcase       when EnableMesh() does not return ERROR_NONE
84 @precondition   None
85 @postcondition  None
86 */
87 TEST(WifiMeshManager, EnableMesh_p)
88 {
89         error_e ret = ERROR_NONE;
90         Wmesh w;
91
92         if (ERROR_NONE == CheckFeature()) {
93                 ret = w.EnableMesh();
94         }
95         EXPECT_EQ(ERROR_NONE, ret);
96 }
97
98 /*
99 @testcase       Scan_p
100 @since_tizen    5.0
101 @author         SRID(abhishek.s94)
102 @reviewer       HQ(saerome.kim)
103 @type           auto
104 @description    Positive, Scan using wifi-mesh-manager
105 @apicovered     "scan" dbus method on net.wmesh.manager interface
106 @passcase       when Scan() returns ERROR_NONE
107 @failcase       when Scan() does not return ERROR_NONE
108 @precondition   None
109 @postcondition  None
110 */
111 TEST(WifiMeshManager, Scan_p)
112 {
113         error_e ret = ERROR_NONE;
114         Wmesh w;
115
116         if (ERROR_NONE == CheckFeature()) {
117                 ret = w.Scan();
118         }
119         EXPECT_EQ(ERROR_NONE, ret);
120 }
121
122 /*
123 @testcase       EnableSoftap_p
124 @since_tizen    5.0
125 @author         SRID(abhishek.s94)
126 @reviewer       HQ(saerome.kim)
127 @type           auto
128 @description    Positive, Enable softap using wifi-mesh-manager
129 @apicovered     "enable_softap" dbus method on net.wmesh.manager interface
130 @passcase       when EnableSoftap() returns ERROR_NONE
131 @failcase       when EnableSoftap() does not return ERROR_NONE
132 @precondition   None
133 @postcondition  None
134 */
135 TEST(WifiMeshManager, SetSoftap_p)
136 {
137         static char ssid[] = "haltestnetwork";
138         static char passphrase[] = "00000000";
139         static int channel = 1;
140         static int visibility = 1;
141         static int max_stations = 10;
142         static int security = 2;
143
144         error_e ret = ERROR_NONE;
145         Wmesh w;
146
147         if (ERROR_NONE == CheckFeature()) {
148                 ret = w.SetSoftap(ssid, passphrase,
149                                 channel, visibility, max_stations, security);
150                 EXPECT_EQ(ERROR_NONE, ret);
151
152                 ret = w.GetSoftap();
153
154                 EXPECT_EQ(ERROR_NONE, ret);
155
156                 ret = w.EnableSoftap();
157         }
158         EXPECT_EQ(ERROR_NONE, ret);
159 }
160
161 /*
162 @testcase       DisableSoftap_p
163 @since_tizen    5.0
164 @author         SRID(abhishek.s94)
165 @reviewer       HQ(saerome.kim)
166 @type           auto
167 @description    Positive, Disable softap using wifi-mesh-manager
168 @apicovered     "disable_softap" dbus method on net.wmesh.manager interface
169 @passcase       when DisableSoftap() returns ERROR_NONE
170 @failcase       when DisableSoftap() does not return ERROR_NONE
171 @precondition   None
172 @postcondition  None
173 */
174 TEST(WifiMeshManager, DisableSoftap_p)
175 {
176         error_e ret = ERROR_NONE;
177         Wmesh w;
178
179         if (ERROR_NONE == CheckFeature()) {
180                 ret = w.DisableSoftap();
181         }
182         EXPECT_EQ(ERROR_NONE, ret);
183 }
184
185 /*
186 @testcase       CreateMeshNetwork_p
187 @since_tizen    5.0
188 @author         SRID(abhishek.s94)
189 @reviewer       HQ(saerome.kim)
190 @type           auto
191 @description    Positive, Create mesh network using wifi-mesh-manager
192 @apicovered     "create_mesh_network" dbus method on net.wmesh.manager interface
193 @passcase       when CreateMeshNetwork() returns ERROR_NONE
194 @failcase       when CreateMeshNetwork() does not return ERROR_NONE
195 @precondition   None
196 @postcondition  None
197 */
198 TEST(WifiMeshManager, CreateMeshNetwork_p)
199 {
200         error_e ret = ERROR_NONE;
201         Wmesh w;
202
203         if (ERROR_NONE == CheckFeature()) {
204                 ret = w.CreateMeshNetwork(mesh_id, 1, 2, 1);
205         }
206         EXPECT_EQ(ERROR_NONE, ret);
207 }
208
209 /*
210 @testcase       ConnectMeshNetwork_p
211 @since_tizen    5.0
212 @author         SRID(abhishek.s94)
213 @reviewer       HQ(saerome.kim)
214 @type           auto
215 @description    Positive, Connect to a mesh network using wifi-mesh-manager
216 @apicovered     "connect_mesh_network" dbus method on net.wmesh.manager interface
217 @passcase       when ConnectMeshNetwork() returns ERROR_NONE
218 @failcase       when ConnectMeshNetwork() does not return ERROR_NONE
219 @precondition   None
220 @postcondition  None
221 */
222 TEST(WifiMeshManager, ConnectMeshNetwork_p)
223 {
224         error_e ret = ERROR_NONE;
225         Wmesh w;
226         char *passphrase = (char *)"00000000";
227
228         if (ERROR_NONE == CheckFeature()) {
229                 ret = w.ConnectMeshNetwork(mesh_id, 1, 2, passphrase);
230         }
231         EXPECT_EQ(ERROR_NONE, ret);
232 }
233
234
235 /*
236 @testcase       Stop_p
237 @since_tizen    5.0
238 @author         SRID(abhishek.s94)
239 @reviewer       HQ(saerome.kim)
240 @type           auto
241 @description    Positive, Stop wifi-mesh-manager
242 @apicovered     "disable_mesh" dbus method on net.wmesh.manager interface
243 @passcase       when DisableMesh() returns ERROR_NONE
244 @failcase       when DisableMesh() does not return ERROR_NONE
245 @precondition   None
246 @postcondition  None
247 */
248 TEST(WifiMeshManager, DisableMesh_p)
249 {
250         error_e ret = ERROR_NONE;
251         Wmesh w;
252
253         if (ERROR_NONE == CheckFeature()) {
254                 ret = w.DisableMesh();
255         }
256         EXPECT_EQ(ERROR_NONE, ret);
257 }
258
259 /*
260 @testcase       Disable_p
261 @since_tizen    5.0
262 @author         SRID(abhishek.s94)
263 @reviewer       HQ(saerome.kim)
264 @type           auto
265 @description    Positive, Disable wifi-mesh-manager
266 @apicovered     "disable" dbus method on net.wmesh.manager interface
267 @passcase       when DisableManager() returns ERROR_NONE
268 @failcase       when DisableManager() does not return ERROR_NONE
269 @precondition   None
270 @postcondition  None
271 */
272 TEST(WifiMeshManager, Disable_p)
273 {
274         error_e ret = ERROR_NONE;
275         Manager mgr;
276
277         if (ERROR_NONE == CheckFeature()) {
278                 ret = mgr.DisableManager();
279         }
280         EXPECT_EQ(ERROR_NONE, ret);
281 }
282
283 int main(int argc, char **argv)
284 {
285         int ret = 0;
286         try {
287                 testing::InitGoogleTest(&argc, argv);
288         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
289                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
290         } catch (...) {
291                 std::cerr << "Caught: unknown exception" << std::endl;
292         }
293
294         try {
295                 ret = RUN_ALL_TESTS();
296         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
297                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
298         } catch (...) {
299                 std::cerr << "Caught: unknown exception" << std::endl;
300         }
301         return ret;
302 }