Check the feature in order to execute HAL accordance with the feature.
[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       Disable_p
75 @since_tizen    5.0
76 @author         SRID(abhishek.s94)
77 @reviewer       HQ(saerome.kim)
78 @type           auto
79 @description    Positive, Disable zigbee manager
80 @apicovered     "disable" method on "org.tizen.zigbee.manager" interface
81 @passcase       when zbl_disable returns ZIGBEE_ERROR_NONE
82 @failcase       when zbl_disable does not return ZIGBEE_ERROR_NONE
83 @precondition   __check_feature_supported must return true for zigbee feature
84 @postcondition  None
85 */
86 TEST(ZigbeeManager, Disable_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_disable();
93         }
94         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
95 }
96
97 int main(int argc, char **argv)
98 {
99         int ret = 0;
100         try {
101                 testing::InitGoogleTest(&argc, argv);
102         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
103                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
104         } catch (...) {
105                 std::cerr << "Caught: unknown exception" << std::endl;
106         }
107
108         try {
109                 ret = RUN_ALL_TESTS();
110         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
111                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
112         } catch (...) {
113                 std::cerr << "Caught: unknown exception" << std::endl;
114         }
115         return ret;
116 }