Added additional Haltest cases
[platform/core/connectivity/zigbee-manager.git] / haltest / zigbee-manager-haltests.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 #include <system_info.h>
24
25 #include "zbl.h"
26
27 using ::testing::InitGoogleTest;
28 using ::testing::Test;
29 using ::testing::TestCase;
30
31 const char *feature_name = (char *)"http://tizen.org/feature/network.zigbee";
32
33 static bool __check_feature_supported()
34 {
35         bool zigbee_supported = FALSE;
36         if (!system_info_get_platform_bool(feature_name, &zigbee_supported)) {
37                 if (FALSE == zigbee_supported) {
38                         GLOGD("zigbee feature is disabled");
39                         return ZIGBEE_ERROR_NOT_SUPPORTED;
40                 }
41                 return ZIGBEE_ERROR_NONE;
42         } else {
43                 GLOGD("Error - Feature getting from System Info");
44                 return ZIGBEE_ERROR_INVALID_PARAMETER;
45         }
46
47 }
48
49 /*
50 @testcase       Enable_p
51 @since_tizen    5.0
52 @author         SRID(abhishek.s94)
53 @reviewer       HQ(saerome.kim)
54 @type           auto
55 @description    Positive, Enable zigbee manager
56 @apicovered     "enable" method on "org.tizen.zigbee.manager" interface
57 @passcase       when zbl_enable returns ZIGBEE_ERROR_NONE
58 @failcase       when zbl_enable does not return ZIGBEE_ERROR_NONE
59 @precondition   __check_feature_supported must return true for zigbee feature
60 @postcondition  None
61 */
62 TEST(ZigbeeManager, Enable_p)
63 {
64         int ret = ZIGBEE_ERROR_NONE;
65         Zigbee zb_mgr;
66
67         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
68                 ret = zb_mgr.zbl_enable();
69         }
70         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
71 }
72
73 /*
74 @testcase       FormNetwork_p
75 @since_tizen    5.0
76 @author         SRID(abhishek.s94)
77 @reviewer       HQ(saerome.kim)
78 @type           auto
79 @description    Positive, Form network using zigbee-manager
80 @apicovered     "form_network" method on "org.tizen.zigbee.service" interface
81 @passcase       when zbl_form_network returns ZIGBEE_ERROR_NONE
82 @failcase       when zbl_form_network does not return ZIGBEE_ERROR_NONE
83 @precondition   __check_feature_supported must return true for zigbee feature
84 @postcondition  None
85 */
86 TEST(ZigbeeManager, FormNetwork_p)
87 {
88         int ret = ZIGBEE_ERROR_NONE;
89         Zigbee zb_mgr;
90
91         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
92                 ret = zb_mgr.zbl_form_network();
93         }
94         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
95 }
96
97 /*
98 @testcase       GetNetworkInfo_p
99 @since_tizen    5.0
100 @author         SRID(abhishek.s94)
101 @reviewer       HQ(saerome.kim)
102 @type           auto
103 @description    Positive, get network info using zigbee-manager
104 @apicovered     "get_network_info" method on "org.tizen.zigbee.service" interface
105 @passcase       when zbl_get_network_info returns ZIGBEE_ERROR_NONE
106 @failcase       when zbl_get_network_info does not return ZIGBEE_ERROR_NONE
107 @precondition   __check_feature_supported must return true for zigbee feature
108 @postcondition  None
109 */
110 TEST(ZigbeeManager, GetNetworkInfo_p)
111 {
112         int ret = ZIGBEE_ERROR_NONE;
113         Zigbee zb_mgr;
114
115         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
116                 ret = zb_mgr.zbl_get_network_info();
117         }
118         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
119 }
120
121 /*
122 @testcase       GetMac_p
123 @since_tizen    5.0
124 @author         SRID(abhishek.s94)
125 @reviewer       HQ(saerome.kim)
126 @type           auto
127 @description    Positive, get mac address using zigbee-manager
128 @apicovered     "get_mac" method on "org.tizen.zigbee.service" interface
129 @passcase       when zbl_get_mac returns ZIGBEE_ERROR_NONE
130 @failcase       when zbl_get_mac does not return ZIGBEE_ERROR_NONE
131 @precondition   __check_feature_supported must return true for zigbee feature
132 @postcondition  None
133 */
134 TEST(ZigbeeManager, GetMac_p)
135 {
136         int ret = ZIGBEE_ERROR_NONE;
137         Zigbee zb_mgr;
138
139         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
140                 ret = zb_mgr.zbl_get_mac();
141         }
142         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
143 }
144
145 /*
146 @testcase       PermitJoin_p
147 @since_tizen    5.0
148 @author         SRID(abhishek.s94)
149 @reviewer       HQ(saerome.kim)
150 @type           auto
151 @description    Positive, Allow permit join using zigbee-manager
152 @apicovered     "permit_join" method on "org.tizen.zigbee.service" interface
153 @passcase       when zbl_permit_join returns ZIGBEE_ERROR_NONE
154 @failcase       when zbl_permit_join does not return ZIGBEE_ERROR_NONE
155 @precondition   __check_feature_supported must return true for zigbee feature
156 @postcondition  None
157 */
158 TEST(ZigbeeManager, PermitJoin_p)
159 {
160         int ret = ZIGBEE_ERROR_NONE;
161         Zigbee zb_mgr;
162
163         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
164                 ret = zb_mgr.zbl_permit_join(1, true);
165         }
166         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
167 }
168
169 /*
170 @testcase       LeaveNetwork_p
171 @since_tizen    5.0
172 @author         SRID(abhishek.s94)
173 @reviewer       HQ(saerome.kim)
174 @type           auto
175 @description    Positive, Leave network using zigbee-manager
176 @apicovered     "leave_network" method on "org.tizen.zigbee.service" interface
177 @passcase       when zbl_leave_network returns ZIGBEE_ERROR_NONE
178 @failcase       when zbl_leave_network does not return ZIGBEE_ERROR_NONE
179 @precondition   __check_feature_supported must return true for zigbee feature
180 @postcondition  None
181 */
182 TEST(ZigbeeManager, LeaveNetwork_p)
183 {
184         int ret = ZIGBEE_ERROR_NONE;
185         Zigbee zb_mgr;
186
187         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
188                 ret = zb_mgr.zbl_leave_network();
189         }
190         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
191 }
192
193 /*
194 @testcase       Disable_p
195 @since_tizen    5.0
196 @author         SRID(abhishek.s94)
197 @reviewer       HQ(saerome.kim)
198 @type           auto
199 @description    Positive, Disable zigbee manager
200 @apicovered     "disable" method on "org.tizen.zigbee.manager" interface
201 @passcase       when zbl_disable returns ZIGBEE_ERROR_NONE
202 @failcase       when zbl_disable does not return ZIGBEE_ERROR_NONE
203 @precondition   __check_feature_supported must return true for zigbee feature
204 @postcondition  None
205 */
206 TEST(ZigbeeManager, Disable_p)
207 {
208         int ret = ZIGBEE_ERROR_NONE;
209         Zigbee zb_mgr;
210
211         if (ZIGBEE_ERROR_NONE == __check_feature_supported()) {
212                 ret = zb_mgr.zbl_disable();
213         }
214         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
215 }
216
217 int main(int argc, char **argv)
218 {
219         int ret = 0;
220         try {
221                 testing::InitGoogleTest(&argc, argv);
222         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
223                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
224         } catch (...) {
225                 std::cerr << "Caught: unknown exception" << std::endl;
226         }
227
228         try {
229                 ret = RUN_ALL_TESTS();
230         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
231                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
232         } catch (...) {
233                 std::cerr << "Caught: unknown exception" << std::endl;
234         }
235         return ret;
236 }