Added HAL testcases for nfc-manager
[platform/core/api/nfc.git] / haltest / nfc_manager_hal_tc.cpp
1 /*
2  * Copyright (c) 2018 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 <iostream>
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include <nfc.h>
21 #include <system_info.h>
22 #include "unittest.h"
23
24 using ::testing::InitGoogleTest;
25 using ::testing::Test;
26 using ::testing::TestCase;
27
28 void __activated(bool activated, void *user_data) {
29         std::cout<< (activated ? "activated" : "deactivated") << std::endl;
30 }
31
32 static bool __check_feature_supported(char *key)
33 {
34         bool value = false;
35         int ret = system_info_get_platform_bool(key, &value);
36
37         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
38         EXPECT_EQ(true, value) << key << " feature is not supported";
39
40         return value;
41 }
42
43 /*
44 @testcase       Init_p
45 @since_tizen    5.0
46 @author         SRID(abhishek.s94)
47 @reviewer       HQ(jh8801.jung)
48 @type           auto
49 @description    Positive, Initialize NFC manager
50 @apicovered     nfc_manager_initialize
51 @passcase       when nfc_manager_initialize returns NFC_ERROR_NONE
52 @failcase       when nfc_manager_initialize does not return NFC_ERROR_NONE
53 @precondition   __check_feature_supported must return true for nfc feature
54 @postcondition  None
55 */
56 TEST(Hal_nfc, Init_p)
57 {
58         g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
59         ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
60
61         nfc_manager_set_activation_changed_cb(__activated, NULL);
62         int rv = nfc_manager_initialize();
63         EXPECT_EQ(NFC_ERROR_NONE, rv) << "Initialization failure";
64
65 }
66
67 /*
68 @testcase       Set_Activation_true_p
69 @since_tizen    5.0
70 @author         SRID(abhishek.s94)
71 @reviewer       HQ(jh8801.jung)
72 @type           auto
73 @description    Positive, Activate NFC manager
74 @apicovered     nfc_manager_set_activation
75 @passcase       when nfc_manager_set_activation returns NFC_ERROR_NONE or NFC_ERROR_ALREADY_ACTIVATED
76 @failcase       when nfc_manager_set_activation does not return NFC_ERROR_NONE or NFC_ERROR_ALREADY_ACTIVATED
77 @precondition   __check_feature_supported must return true for nfc feature
78 @postcondition  None
79 */
80 TEST(Hal_nfc, Set_Activation_true_p)
81 {
82         g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
83         ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
84
85         int rv = nfc_manager_set_activation(true, NULL, NULL);
86         sleep(5);
87         EXPECT_EQ(rv == NFC_ERROR_NONE || rv == NFC_ERROR_ALREADY_ACTIVATED, true)
88                 << "Activation failure";
89 }
90
91 /*
92 @testcase       Set_Activation_false_p
93 @since_tizen    5.0
94 @author         SRID(abhishek.s94)
95 @reviewer       HQ(jh8801.jung)
96 @type           auto
97 @description    Positive, Deactivate NFC manager
98 @apicovered     nfc_manager_set_activation
99 @passcase       when nfc_manager_set_activation returns NFC_ERROR_NONE
100 @failcase       when nfc_manager_set_activation does not return NFC_ERROR_NONE
101 @precondition   __check_feature_supported must return true for nfc feature
102 @postcondition  None
103 */
104 TEST(Hal_nfc, Set_Activation_false_p)
105 {
106         g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
107         ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
108
109         int rv = nfc_manager_set_activation(false, NULL, NULL);
110         EXPECT_EQ(NFC_ERROR_NONE, rv) << "Deactivation failure";
111 }
112
113 /*
114 @testcase       Deinit_p
115 @since_tizen    5.0
116 @author         SRID(abhishek.s94)
117 @reviewer       HQ(jh8801.jung)
118 @type           auto
119 @description    Positive, Deinitialize NFC manager
120 @apicovered     nfc_manager_deinitialize
121 @passcase       when nfc_manager_deinitialize returns NFC_ERROR_NONE
122 @failcase       when nfc_manager_deinitialize does not return NFC_ERROR_NONE
123 @precondition   __check_feature_supported must return true for nfc feature
124 @postcondition  None
125 */
126 TEST(Hal_nfc, Deinit_p)
127 {
128         g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
129         ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
130
131         int rv = nfc_manager_deinitialize();
132         EXPECT_EQ(NFC_ERROR_NONE, rv) << "De-initialization failure";
133 }
134
135 int main(int argc, char **argv)
136 {
137         InitGoogleTest(&argc, argv);
138         return RUN_ALL_TESTS();
139 }