Added Haltest for zigbee-manager
[platform/core/connectivity/zigbee-manager.git] / haltest / zigbee_manager_hal_tc.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 #define FEATURE_ZIGBEE       "http://tizen.org/feature/network.zigbee"
28 static bool g_bFeatureZb = false;
29
30 using ::testing::InitGoogleTest;
31 using ::testing::Test;
32 using ::testing::TestCase;
33
34 static bool __check_feature_supported(char *key)
35 {
36         bool value = false;
37         int ret = system_info_get_platform_bool(key, &value);
38
39         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
40         EXPECT_EQ(true, value) << key << " feature is not supported";
41
42         return value;
43 }
44
45 /*
46 @testcase       Enable_p
47 @since_tizen    5.0
48 @author         SRID(abhishek.s94)
49 @reviewer       HQ(saerome.kim)
50 @type           auto
51 @description    Positive, Enable zigbee manager
52 @apicovered     "enable" method on "org.tizen.zigbee.manager" interface
53 @passcase       when zbl_enable returns ZIGBEE_ERROR_NONE
54 @failcase       when zbl_enable does not return ZIGBEE_ERROR_NONE
55 @precondition   __check_feature_supported must return true for zigbee feature
56 @postcondition  None
57 */
58 TEST(ZigbeeManager, Enable_p)
59 {
60         g_bFeatureZb = __check_feature_supported((char*)FEATURE_ZIGBEE);
61         ASSERT_EQ(true, g_bFeatureZb) << FEATURE_ZIGBEE << " feature is not supported";
62
63         int ret = ZIGBEE_ERROR_NONE;
64         Zigbee zb_mgr;
65
66         ret = zb_mgr.zbl_enable();
67         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
68 }
69
70 /*
71 @testcase       Disable_p
72 @since_tizen    5.0
73 @author         SRID(abhishek.s94)
74 @reviewer       HQ(saerome.kim)
75 @type           auto
76 @description    Positive, Disable zigbee manager
77 @apicovered     "disable" method on "org.tizen.zigbee.manager" interface
78 @passcase       when zbl_disable returns ZIGBEE_ERROR_NONE
79 @failcase       when zbl_disable does not return ZIGBEE_ERROR_NONE
80 @precondition   __check_feature_supported must return true for zigbee feature
81 @postcondition  None
82 */
83 TEST(ZigbeeManager, Disable_p)
84 {
85         g_bFeatureZb = __check_feature_supported((char*)FEATURE_ZIGBEE);
86         ASSERT_EQ(true, g_bFeatureZb) << FEATURE_ZIGBEE << " feature is not supported";
87
88         int ret = ZIGBEE_ERROR_NONE;
89         Zigbee zb_mgr;
90
91         ret = zb_mgr.zbl_disable();
92         EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
93 }
94
95 int main(int argc, char **argv)
96 {
97         int ret = 0;
98         try {
99                 testing::InitGoogleTest(&argc, argv);
100         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
101                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
102         } catch (...) {
103                 std::cerr << "Caught: unknown exception" << std::endl;
104         }
105
106         try {
107                 ret = RUN_ALL_TESTS();
108         } catch (const ::testing::internal::GoogleTestFailureException& ex) {
109                 std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
110         } catch (...) {
111                 std::cerr << "Caught: unknown exception" << std::endl;
112         }
113         return ret;
114 }