2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
23 #include <system_info.h>
27 using ::testing::InitGoogleTest;
28 using ::testing::Test;
29 using ::testing::TestCase;
31 static softap_h sa = NULL;
32 static bool g_is_requested;
33 static softap_error_e g_error;
34 static softap_disabled_cause_e g_code;
36 static bool __check_feature_supported(char *key)
39 int ret = system_info_get_platform_bool(key, &value);
41 EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
42 EXPECT_EQ(true, value) << key << " feature is not supported";
47 static gboolean __timeout_callback(gpointer data)
49 EXPECT_TRUE(0) << "SoftAP callback timeout!";
54 static void __enabled_cb(softap_error_e error, bool is_requested, void *data)
57 g_is_requested = is_requested;
61 static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, void *data)
68 TEST(Hal_softap, Init_p)
70 g_bFeatureWifi = __check_feature_supported((char*)FEATURE_WIFI);
71 ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported";
73 int ret = SOFTAP_ERROR_NONE;
75 ret = softap_create(&sa);
76 ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Initialization failure";
78 ret = softap_set_enabled_cb(sa, __enabled_cb, NULL);
79 EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set enabled callback!!";
81 ret = softap_set_disabled_cb(sa, __disabled_cb, NULL);
82 EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set disabled callback!!";
85 TEST(Hal_softap, Activate_p)
87 ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported";
89 int ret = SOFTAP_ERROR_NONE;
92 ret = softap_is_enabled(sa, &enabled);
93 ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to get SoftAP state";
98 ret = softap_enable(sa);
99 ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to enable SoftAP";
101 RUN_GMAIN_LOOP(__timeout_callback);
103 EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to enable SoftAP";
104 EXPECT_EQ(true, g_is_requested) << "Failed to enable SoftAP";
107 ret = access(WIFI_ADDRESS_PATH, F_OK);
108 EXPECT_EQ(0, ret) << "Could not access " << WIFI_ADDRESS_PATH;
111 TEST(Hal_softap, Deactivate_p)
113 ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported";
115 int ret = SOFTAP_ERROR_NONE;
117 ret = softap_disable(sa);
118 ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to disable SoftAP";
120 RUN_GMAIN_LOOP(__timeout_callback);
122 EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to disable SoftAP" << g_code;
124 ret = access(WIFI_ADDRESS_PATH, F_OK);
125 EXPECT_EQ(-1, ret) << WIFI_ADDRESS_PATH << " is exist";
128 TEST(Hal_softap, Deinit_p)
130 ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported";
132 int ret = SOFTAP_ERROR_NONE;
134 ret = softap_unset_enabled_cb(sa);
135 EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset enabled callback!!";
137 ret = softap_unset_disabled_cb(sa);
138 EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset disabled callback!!";
140 ret = softap_destroy(sa);
141 EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Deinitialization failure";
144 int main(int argc, char **argv)
146 InitGoogleTest(&argc, argv);
147 return RUN_ALL_TESTS();