Add a test program for checking wifi state 60/71560/5
authorsung.goo.kim <sung.goo.kim@samsung.com>
Thu, 26 May 2016 02:02:06 +0000 (11:02 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 26 May 2016 04:54:20 +0000 (21:54 -0700)
Change-Id: Ieb37453ccb412c803929aa6dca804b95b3418477

packaging/iotcon.spec
test/CMakeLists.txt
test/iotcon-test-wifi.c [new file with mode: 0644]

index e270f45888e31d8067fbb1bd0515333a5098ac60..ece8b216103909cbc5ec41c4db00c64a6cac9f65 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(capi-system-system-settings)
+BuildRequires:  pkgconfig(capi-network-wifi)
 BuildRequires:  pkgconfig(iotivity)
 BuildRequires:  pkgconfig(uuid)
 BuildRequires:  pkgconfig(cynara-client)
index 3b526359b66f9f11b74218bc5da3e99934b94c21..9b3e65d64e314101c7691240f60896e58ee1ba2b 100644 (file)
@@ -19,7 +19,10 @@ SET(IOTCON_TEST_ENCAP_SERVER "iotcon-test-encap-server")
 SET(IOTCON_TEST_ENCAP_CLIENT_SRCS "iotcon-test-encap-client.c")
 SET(IOTCON_TEST_ENCAP_SERVER_SRCS "iotcon-test-encap-server.c")
 
-pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
+SET(IOTCON_TEST_WIFI "iotcon-test-wifi")
+SET(IOTCON_TEST_WIFI_SRCS "iotcon-test-wifi.c")
+
+pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0 capi-network-wifi)
 INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
 
@@ -51,3 +54,6 @@ ADD_EXECUTABLE(${IOTCON_TEST_ENCAP_SERVER} ${IOTCON_TEST_ENCAP_SERVER_SRCS})
 TARGET_LINK_LIBRARIES(${IOTCON_TEST_ENCAP_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
 INSTALL(TARGETS ${IOTCON_TEST_ENCAP_SERVER} DESTINATION ${BIN_INSTALL_DIR})
 
+ADD_EXECUTABLE(${IOTCON_TEST_WIFI} ${IOTCON_TEST_WIFI_SRCS})
+TARGET_LINK_LIBRARIES(${IOTCON_TEST_WIFI} ${test_pkgs_LIBRARIES} ${CLIENT})
+INSTALL(TARGETS ${IOTCON_TEST_WIFI} DESTINATION ${BIN_INSTALL_DIR})
diff --git a/test/iotcon-test-wifi.c b/test/iotcon-test-wifi.c
new file mode 100644 (file)
index 0000000..5020e9c
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <wifi.h>
+
+#include "test.h"
+
+static void _check_wifi_state()
+{
+       int ret;
+       wifi_ap_h ap;
+       wifi_connection_state_e connection_state;
+       bool activated;
+       char *essid;
+
+       ret = wifi_initialize();
+       if (WIFI_ERROR_NONE != ret) {
+               ERR("wifi_initialize() Fail(%d)", ret);
+               printf("wifi_initialize() Fail(%d)\n", ret);
+               return;
+       }
+
+       ret = wifi_is_activated(&activated);
+       if (WIFI_ERROR_NONE != ret) {
+               ERR("wifi_is_activated() Fail(%d)", ret);
+               printf("wifi_is_activated() Fail(%d)\n", ret);
+               wifi_deinitialize();
+               return;
+       } else if (false == activated) {
+               ERR("wifi is not activated");
+               printf("wifi is not activate\n");
+               wifi_deinitialize();
+               return;
+       }
+
+       ret = wifi_get_connection_state(&connection_state);
+       if (WIFI_ERROR_NONE != ret) {
+               ERR("wifi_get_connection_state() Fail(%d)", ret);
+               printf("wifi_get_connection_state() Fail(%d)\n", ret);
+               wifi_deinitialize();
+               return;
+       }
+
+       switch (connection_state) {
+       case WIFI_CONNECTION_STATE_CONNECTED:
+               INFO("WIFI_CONNECTION_STATE_CONNECTED");
+               printf("WIFI_CONNECTION_STATE_CONNECTED\n");
+               ret = wifi_get_connected_ap(&ap);
+               if (WIFI_ERROR_NONE != ret) {
+                       ERR("wifi_get_connected_ap() Fail(%d)", ret);
+                       printf("wifi_get_connected_ap() Fail(%d)\n", ret);
+                       break;
+               }
+               ret = wifi_ap_get_essid(ap, &essid);
+               if (WIFI_ERROR_NONE != ret) {
+                       ERR("wifi_ap_get_essid() Fail(%d)", ret);
+                       printf("wifi_ap_get_essid() Fail(%d)\n", ret);
+                       wifi_ap_destroy(ap);
+                       break;
+               }
+               INFO("ssid: %s", essid);
+               printf("ssid: %s\n", essid);
+               free(essid);
+               wifi_ap_destroy(ap);
+               break;
+       case WIFI_CONNECTION_STATE_FAILURE:
+               ERR("WIFI_CONNECTION_STATE_FAILURE");
+               printf("WIFI_CONNECTION_STATE_FAILURE\n");
+               break;
+       case WIFI_CONNECTION_STATE_DISCONNECTED:
+               ERR("WIFI_CONNECTION_STATE_DISCONNECTED");
+               printf("WIFI_CONNECTION_STATE_DISCONNECTED\n");
+               break;
+       case WIFI_CONNECTION_STATE_ASSOCIATION:
+               ERR("WIFI_CONNECTION_STATE_ASSOCIATION");
+               printf("WIFI_CONNECTION_STATE_ASSOCIATION\n");
+               break;
+       case WIFI_CONNECTION_STATE_CONFIGURATION:
+               ERR("WIFI_CONNECTION_STATE_CONFIGURATION");
+               printf("WIFI_CONNECTION_STATE_CONFIGURATION\n");
+               break;
+       default:
+               ERR("Invalid connection state(%d)", connection_state);
+               printf("Invalid connection state(%d)", connection_state);
+       }
+
+       wifi_deinitialize();
+}
+
+int main(int argc, char **argv)
+{
+       _check_wifi_state();
+       return 0;
+}