Change file mode into 644
[platform/core/connectivity/stc-manager.git] / unittest / unittest.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 <unistd.h>
23
24 #include "unittest.h"
25 #include "restriction.h"
26 #include "statistics.h"
27 #include "manager.h"
28
29 using ::testing::InitGoogleTest;
30 using ::testing::Test;
31 using ::testing::TestCase;
32
33 TEST(StcManager_Statistics, Init_p)
34 {
35         error_e ret = ERROR_NONE;
36         Statistics stat;
37
38         ret = stat.InitStatistics();
39         EXPECT_EQ(ERROR_NONE, ret);
40 }
41
42 TEST(StcManager_Statistics, Get_p)
43 {
44         error_e ret = ERROR_NONE;
45         Statistics stat;
46         time_t from = 0;
47         time_t to = 0;
48
49         from = stat.MakeTime(2000, 1, 1, 1, 1);
50         time(&to);
51
52         ret = stat.SetRule("TOTAL_DATACALL",
53                 NULL,
54                 IFACE_DATACALL,
55                 from,
56                 to,
57                 TIME_PERIOD_DAY);
58         EXPECT_EQ(ERROR_NONE, ret);
59
60         ret = stat.GetStatistics();
61         EXPECT_EQ(ERROR_NONE, ret);
62
63         ret = stat.SetRule("TOTAL_WIFI",
64                 NULL,
65                 IFACE_WIFI,
66                 from,
67                 to,
68                 TIME_PERIOD_UNKNOWN);
69         EXPECT_EQ(ERROR_NONE, ret);
70
71         ret = stat.GetStatistics();
72         EXPECT_EQ(ERROR_NONE, ret);
73 }
74
75 TEST(StcManager_Statistics, GetAll_p)
76 {
77         error_e ret = ERROR_NONE;
78         Statistics stat;
79         time_t from = 0;
80         time_t to = 0;
81
82         from = stat.MakeTime(2000, 1, 1, 1, 1);
83         time(&to);
84
85         ret = stat.SetRule(NULL,
86                 NULL,
87                 IFACE_UNKNOWN,
88                 from,
89                 to,
90                 TIME_PERIOD_UNKNOWN);
91         EXPECT_EQ(ERROR_NONE, ret);
92
93         ret = stat.GetAllStatistics();
94         EXPECT_EQ(ERROR_NONE, ret);
95 }
96
97 TEST(StcManager_Statistics, GetTotal_p)
98 {
99         error_e ret = ERROR_NONE;
100         Statistics stat;
101         time_t from = 0;
102         time_t to = 0;
103
104         from = stat.MakeTime(2000, 1, 1, 1, 1);
105         time(&to);
106
107         ret = stat.SetRule(NULL,
108                 NULL,
109                 IFACE_DATACALL,
110                 from,
111                 to,
112                 TIME_PERIOD_UNKNOWN);
113         EXPECT_EQ(ERROR_NONE, ret);
114
115         ret = stat.GetTotalStatistics();
116         EXPECT_EQ(ERROR_NONE, ret);
117
118         ret = stat.SetRule(NULL,
119                 NULL,
120                 IFACE_WIFI,
121                 from,
122                 to,
123                 TIME_PERIOD_UNKNOWN);
124         EXPECT_EQ(ERROR_NONE, ret);
125
126         ret = stat.GetTotalStatistics();
127         EXPECT_EQ(ERROR_NONE, ret);
128 }
129
130 TEST(StcManager_Restriction, Set_p)
131 {
132         error_e ret = ERROR_NONE;
133         Restriction rest;
134
135         ret = rest.SetRule("Test_tel",
136                 "seth_w0",
137                 "1234567890abcdefg",
138                 IFACE_DATACALL,
139                 0,
140                 0,
141                 ROAMING_UNKNOWN);
142         EXPECT_EQ(ERROR_NONE, ret);
143
144         ret = rest.SetRstriction();
145         EXPECT_EQ(ERROR_NONE, ret);
146
147         ret = rest.SetRule("TOTAL_WIFI",
148                 "wlan0",
149                 NULL,
150                 IFACE_WIFI,
151                 2,
152                 1,
153                 ROAMING_UNKNOWN);
154         EXPECT_EQ(ERROR_NONE, ret);
155
156         ret = rest.SetRstriction();
157         EXPECT_EQ(ERROR_NONE, ret);
158
159         ret = rest.SetRule("Test_eth",
160                 "eth0",
161                 NULL,
162                 IFACE_WIRED,
163                 100000,
164                 80000,
165                 ROAMING_UNKNOWN);
166         EXPECT_EQ(ERROR_NONE, ret);
167
168         ret = rest.SetRstriction();
169         EXPECT_EQ(ERROR_NONE, ret);
170 }
171
172 TEST(StcManager_Restriction, Exclude_p)
173
174 {
175         error_e ret = ERROR_NONE;
176         Restriction rest;
177
178         ret = rest.SetRule("TOTAL_DATACALL",
179                 "seth_w0",
180                 NULL,
181                 IFACE_DATACALL,
182                 0,
183                 0,
184                 ROAMING_UNKNOWN);
185         EXPECT_EQ(ERROR_NONE, ret);
186
187         ret = rest.ExcludeRstriction();
188         EXPECT_EQ(ERROR_NONE, ret);
189 }
190
191 TEST(StcManager_Restriction, Get_p)
192 {
193         error_e ret = ERROR_NONE;
194         Restriction rest;
195
196         ret = rest.SetRule("Test_tel",
197                 "seth_w0",
198                 "1234567890abcdefg",
199                 IFACE_DATACALL,
200                 0,
201                 0,
202                 ROAMING_UNKNOWN);
203         EXPECT_EQ(ERROR_NONE, ret);
204
205         ret = rest.GetRstriction();
206         EXPECT_EQ(ERROR_NONE, ret);
207
208         ret = rest.SetRule("TOTAL_WIFI",
209                 "wlan0",
210                 NULL,
211                 IFACE_WIFI,
212                 0,
213                 0,
214                 ROAMING_UNKNOWN);
215         EXPECT_EQ(ERROR_NONE, ret);
216
217         ret = rest.GetRstriction();
218         EXPECT_EQ(ERROR_NONE, ret);
219
220         ret = rest.SetRule("TOTAL_IPV4",
221                 "seth_w0",
222                 NULL,
223                 IFACE_DATACALL,
224                 0,
225                 0,
226                 ROAMING_UNKNOWN);
227         EXPECT_EQ(ERROR_NONE, ret);
228
229         ret = rest.GetRstriction();
230         EXPECT_EQ(ERROR_NONE, ret);
231 }
232
233 TEST(StcManager_Restriction, GetAll_p)
234 {
235         error_e ret = ERROR_NONE;
236         Restriction rest;
237
238         ret = rest.GetAllRstriction();
239         EXPECT_EQ(ERROR_NONE, ret);
240 }
241
242 TEST(StcManager_Restriction, GetRst_p)
243 {
244         error_e ret = ERROR_NONE;
245         Restriction rest;
246         restriction_status_e status = RESTRICTION_UNKNOWN;
247
248         ret = rest.SetRule("Test_tel",
249                 "seth_w0",
250                 NULL,
251                 IFACE_DATACALL,
252                 0,
253                 0,
254                 ROAMING_UNKNOWN);
255         EXPECT_EQ(ERROR_NONE, ret);
256
257         ret = rest.GetRstrictionStatus(&status);
258         EXPECT_EQ(ERROR_NONE, ret);
259         EXPECT_LE(RESTRICTION_UNKNOWN, status);
260         EXPECT_GE(RESTRICTION_LAST_ELEM, status);
261
262         ret = rest.SetRule("Test_eth",
263                 "eth0",
264                 NULL,
265                 IFACE_WIRED,
266                 100000,
267                 80000,
268                 ROAMING_UNKNOWN);
269         EXPECT_EQ(ERROR_NONE, ret);
270
271         ret = rest.GetRstrictionStatus(&status);
272         EXPECT_EQ(ERROR_NONE, ret);
273         EXPECT_LE(RESTRICTION_UNKNOWN, status);
274         EXPECT_GE(RESTRICTION_LAST_ELEM, status);
275 }
276
277 TEST(StcManager_Restriction, Unset_p)
278 {
279         error_e ret = ERROR_NONE;
280         Restriction rest;
281
282         ret = rest.SetRule("Test_tel",
283                 "seth_w0",
284                 "1234567890abcdefg",
285                 IFACE_DATACALL,
286                 0,
287                 0,
288                 ROAMING_UNKNOWN);
289         EXPECT_EQ(ERROR_NONE, ret);
290
291         ret = rest.UnsetRstriction();
292         EXPECT_EQ(ERROR_NONE, ret);
293
294         ret = rest.SetRule("TOTAL_WIFI",
295                 "wlan0",
296                 NULL,
297                 IFACE_WIFI,
298                 2,
299                 1,
300                 ROAMING_UNKNOWN);
301         EXPECT_EQ(ERROR_NONE, ret);
302
303         ret = rest.UnsetRstriction();
304         EXPECT_EQ(ERROR_NONE, ret);
305
306         ret = rest.SetRule("Test_eth",
307                 "eth0",
308                 NULL,
309                 IFACE_WIRED,
310                 100000,
311                 80000,
312                 ROAMING_UNKNOWN);
313         EXPECT_EQ(ERROR_NONE, ret);
314
315         ret = rest.UnsetRstriction();
316         EXPECT_EQ(ERROR_NONE, ret);
317
318         ret = rest.SetRule("TOTAL_DATACALL",
319                 "seth_w0",
320                 NULL,
321                 IFACE_DATACALL,
322                 0,
323                 0,
324                 ROAMING_UNKNOWN);
325         EXPECT_EQ(ERROR_NONE, ret);
326
327         ret = rest.UnsetRstriction();
328         EXPECT_EQ(ERROR_NONE, ret);
329 }
330
331 TEST(StcManager_Statistics, Reset_p)
332 {
333         error_e ret = ERROR_NONE;
334         Statistics stat;
335         time_t from = 0;
336         time_t to = 0;
337
338         from = stat.MakeTime(2000, 1, 1, 1, 1);
339         time(&to);
340
341         ret = stat.SetRule("TOTAL_DATACALL",
342                 "1234567890abcdefg",
343                 IFACE_DATACALL,
344                 from,
345                 to,
346                 TIME_PERIOD_UNKNOWN);
347         EXPECT_EQ(ERROR_NONE, ret);
348
349         ret = stat.ResetStatistics();
350         EXPECT_EQ(ERROR_NONE, ret);
351
352         ret = stat.SetRule(NULL,
353                 NULL,
354                 IFACE_UNKNOWN,
355                 from,
356                 to,
357                 TIME_PERIOD_UNKNOWN);
358         EXPECT_EQ(ERROR_NONE, ret);
359
360         ret = stat.ResetStatistics();
361         EXPECT_EQ(ERROR_NONE, ret);
362 }
363
364 TEST(StcManager_Manager, Stop_p)
365 {
366         error_e ret = ERROR_NONE;
367         Manager mgr;
368
369         ret = mgr.StopManager();
370         EXPECT_EQ(ERROR_NONE, ret);
371 }
372
373 int main(int argc, char **argv)
374 {
375         InitGoogleTest(&argc, argv);
376         return RUN_ALL_TESTS();
377 }