gtest: add testcases for asnyc API
[platform/core/api/tethering.git] / tests / mocks / tethering_vconf.c
1 /*
2  * Copyright (c) 2020 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 #include "tethering_vconf.h"
17
18 #include <vconf.h>
19
20 #include <stdio.h>
21 #include <stdbool.h>
22 #include <string.h>
23
24 static bool tethering_mock_vconf_result;
25
26 typedef struct {
27         bool usb;
28         bool wifi;
29         bool bluetooth;
30         bool p2p;
31 } tethering_mock_enabled_state_s;
32
33 static tethering_mock_enabled_state_s tethering_mock_enabled_state;
34
35 extern int __real_vconf_get_int(const char *in_key, int *intval);
36
37 void tethering_mock_set_vconf_result(bool result)
38 {
39         tethering_mock_vconf_result = result;
40 }
41
42 void tethering_mock_set_enabled_state(bool usb, bool wifi, bool bluetooth, bool p2p)
43 {
44         tethering_mock_enabled_state.usb = usb;
45         tethering_mock_enabled_state.wifi = wifi;
46         tethering_mock_enabled_state.bluetooth = bluetooth;
47         tethering_mock_enabled_state.p2p = p2p;
48 }
49
50 int __wrap_vconf_get_int(const char *in_key, int *intval)
51 {
52         if (!tethering_mock_vconf_result)
53                 return -1;
54
55         if (strcmp(in_key, VCONFKEY_MOBILE_HOTSPOT_MODE) == 0) {
56                 *intval |= tethering_mock_enabled_state.usb ? VCONFKEY_MOBILE_HOTSPOT_MODE_USB : 0;
57                 *intval |= tethering_mock_enabled_state.wifi ? VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI : 0;
58                 *intval |= tethering_mock_enabled_state.bluetooth ? VCONFKEY_MOBILE_HOTSPOT_MODE_BT : 0;
59                 *intval |= tethering_mock_enabled_state.p2p ? VCONFKEY_MOBILE_HOTSPOT_MODE_P2P : 0;
60         } else if (strcmp(in_key, VCONFKEY_MOBILE_HOTSPOT_SECURITY) == 0) {
61                 *intval = 1; // PSK
62         } else {
63                 *intval = 0;
64         }
65
66         return 0;
67 }
68
69 int __wrap_vconf_set_int(const char *key, int intval)
70 {
71         if (!tethering_mock_vconf_result)
72                 return -1;
73
74         return 0;
75 }
76
77 char *__wrap_vconf_get_str(const char *key)
78 {
79         if (!tethering_mock_vconf_result)
80                 return NULL;
81
82         return strdup("vconf result string");
83 }